1621f50c3Smrg#! /usr/bin/env sh
21a9c160aSmrg## DO NOT EDIT - This file generated from ./build-aux/ltmain.in
3621f50c3Smrg##               by inline-source v2019-02-19.15
4dc407927Smrg
5621f50c3Smrg# libtool (GNU libtool) 2.4.7
61a9c160aSmrg# Provide generalized library-building support services.
7dc407927Smrg# Written by Gordon Matzigkeit <gord@gnu.ai.mit.edu>, 1996
8dc407927Smrg
9621f50c3Smrg# Copyright (C) 1996-2019, 2021-2022 Free Software Foundation, Inc.
10dc407927Smrg# This is free software; see the source for copying conditions.  There is NO
11dc407927Smrg# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12dc407927Smrg
13dc407927Smrg# GNU Libtool is free software; you can redistribute it and/or modify
143eed67faSmbalmer# it under the terms of the GNU General Public License as published by
153eed67faSmbalmer# the Free Software Foundation; either version 2 of the License, or
163eed67faSmbalmer# (at your option) any later version.
173eed67faSmbalmer#
18dc407927Smrg# As a special exception to the GNU General Public License,
19dc407927Smrg# if you distribute this file as part of a program or library that
20dc407927Smrg# is built using GNU Libtool, you may include this file under the
21dc407927Smrg# same distribution terms that you use for the rest of that program.
22dc407927Smrg#
23dc407927Smrg# GNU Libtool is distributed in the hope that it will be useful, but
243eed67faSmbalmer# WITHOUT ANY WARRANTY; without even the implied warranty of
253eed67faSmbalmer# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
263eed67faSmbalmer# General Public License for more details.
273eed67faSmbalmer#
283eed67faSmbalmer# You should have received a copy of the GNU General Public License
291a9c160aSmrg# along with this program.  If not, see <http://www.gnu.org/licenses/>.
303eed67faSmbalmer
313eed67faSmbalmer
32dd0822caSmrgPROGRAM=libtool
333eed67faSmbalmerPACKAGE=libtool
34621f50c3SmrgVERSION=2.4.7
35621f50c3Smrgpackage_revision=2.4.7
363eed67faSmbalmer
371a9c160aSmrg
381a9c160aSmrg## ------ ##
391a9c160aSmrg## Usage. ##
401a9c160aSmrg## ------ ##
411a9c160aSmrg
421a9c160aSmrg# Run './libtool --help' for help with using this script from the
431a9c160aSmrg# command line.
441a9c160aSmrg
451a9c160aSmrg
461a9c160aSmrg## ------------------------------- ##
471a9c160aSmrg## User overridable command paths. ##
481a9c160aSmrg## ------------------------------- ##
491a9c160aSmrg
501a9c160aSmrg# After configure completes, it has a better idea of some of the
511a9c160aSmrg# shell tools we need than the defaults used by the functions shared
521a9c160aSmrg# with bootstrap, so set those here where they can still be over-
531a9c160aSmrg# ridden by the user, but otherwise take precedence.
541a9c160aSmrg
551a9c160aSmrg: ${AUTOCONF="autoconf"}
561a9c160aSmrg: ${AUTOMAKE="automake"}
571a9c160aSmrg
581a9c160aSmrg
591a9c160aSmrg## -------------------------- ##
601a9c160aSmrg## Source external libraries. ##
611a9c160aSmrg## -------------------------- ##
621a9c160aSmrg
631a9c160aSmrg# Much of our low-level functionality needs to be sourced from external
641a9c160aSmrg# libraries, which are installed to $pkgauxdir.
651a9c160aSmrg
661a9c160aSmrg# Set a version string for this script.
67621f50c3Smrgscriptversion=2019-02-19.15; # UTC
681a9c160aSmrg
691a9c160aSmrg# General shell script boiler plate, and helper functions.
701a9c160aSmrg# Written by Gary V. Vaughan, 2004
711a9c160aSmrg
72621f50c3Smrg# This is free software.  There is NO warranty; not even for
73621f50c3Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
74621f50c3Smrg#
75621f50c3Smrg# Copyright (C) 2004-2019, 2021 Bootstrap Authors
76621f50c3Smrg#
77621f50c3Smrg# This file is dual licensed under the terms of the MIT license
78621f50c3Smrg# <https://opensource.org/license/MIT>, and GPL version 2 or later
79621f50c3Smrg# <http://www.gnu.org/licenses/gpl-2.0.html>.  You must apply one of
80621f50c3Smrg# these licenses when using or redistributing this software or any of
81621f50c3Smrg# the files within it.  See the URLs above, or the file `LICENSE`
82621f50c3Smrg# included in the Bootstrap distribution for the full license texts.
831a9c160aSmrg
84621f50c3Smrg# Please report bugs or propose patches to:
85621f50c3Smrg# <https://github.com/gnulib-modules/bootstrap/issues>
861a9c160aSmrg
871a9c160aSmrg
881a9c160aSmrg## ------ ##
891a9c160aSmrg## Usage. ##
901a9c160aSmrg## ------ ##
911a9c160aSmrg
921a9c160aSmrg# Evaluate this file near the top of your script to gain access to
931a9c160aSmrg# the functions and variables defined here:
941a9c160aSmrg#
951a9c160aSmrg#   . `echo "$0" | ${SED-sed} 's|[^/]*$||'`/build-aux/funclib.sh
961a9c160aSmrg#
971a9c160aSmrg# If you need to override any of the default environment variable
981a9c160aSmrg# settings, do that before evaluating this file.
991a9c160aSmrg
1001a9c160aSmrg
1011a9c160aSmrg## -------------------- ##
1021a9c160aSmrg## Shell normalisation. ##
1031a9c160aSmrg## -------------------- ##
1041a9c160aSmrg
1051a9c160aSmrg# Some shells need a little help to be as Bourne compatible as possible.
1061a9c160aSmrg# Before doing anything else, make sure all that help has been provided!
1071a9c160aSmrg
1081a9c160aSmrgDUALCASE=1; export DUALCASE # for MKS sh
1091a9c160aSmrgif test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then :
1103eed67faSmbalmer  emulate sh
1113eed67faSmbalmer  NULLCMD=:
1121a9c160aSmrg  # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which
1133eed67faSmbalmer  # is contrary to our usage.  Disable this feature.
1143eed67faSmbalmer  alias -g '${1+"$@"}'='"$@"'
1153eed67faSmbalmer  setopt NO_GLOB_SUBST
1163eed67faSmbalmerelse
1171a9c160aSmrg  case `(set -o) 2>/dev/null` in *posix*) set -o posix ;; esac
1183eed67faSmbalmerfi
119dd0822caSmrg
1201a9c160aSmrg# NLS nuisances: We save the old values in case they are required later.
1211a9c160aSmrg_G_user_locale=
1221a9c160aSmrg_G_safe_locale=
1231a9c160aSmrgfor _G_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES
1243eed67faSmbalmerdo
1251a9c160aSmrg  eval "if test set = \"\${$_G_var+set}\"; then
1261a9c160aSmrg          save_$_G_var=\$$_G_var
1271a9c160aSmrg          $_G_var=C
1281a9c160aSmrg	  export $_G_var
1291a9c160aSmrg	  _G_user_locale=\"$_G_var=\\\$save_\$_G_var; \$_G_user_locale\"
1301a9c160aSmrg	  _G_safe_locale=\"$_G_var=C; \$_G_safe_locale\"
1313eed67faSmbalmer	fi"
1323eed67faSmbalmerdone
133621f50c3Smrg# These NLS vars are set unconditionally (bootstrap issue #24).  Unset those
134621f50c3Smrg# in case the environment reset is needed later and the $save_* variant is not
135621f50c3Smrg# defined (see the code above).
136621f50c3SmrgLC_ALL=C
137621f50c3SmrgLANGUAGE=C
138621f50c3Smrgexport LANGUAGE LC_ALL
139dc407927Smrg
1401a9c160aSmrg# Make sure IFS has a sensible default
1411a9c160aSmrgsp=' '
1421a9c160aSmrgnl='
1431a9c160aSmrg'
1441a9c160aSmrgIFS="$sp	$nl"
1451a9c160aSmrg
1461a9c160aSmrg# There are apparently some retarded systems that use ';' as a PATH separator!
1471a9c160aSmrgif test "${PATH_SEPARATOR+set}" != set; then
1481a9c160aSmrg  PATH_SEPARATOR=:
1491a9c160aSmrg  (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && {
1501a9c160aSmrg    (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 ||
1511a9c160aSmrg      PATH_SEPARATOR=';'
1521a9c160aSmrg  }
1531a9c160aSmrgfi
154dc407927Smrg
155dc407927Smrg
156621f50c3Smrg# func_unset VAR
157621f50c3Smrg# --------------
158621f50c3Smrg# Portably unset VAR.
159621f50c3Smrg# In some shells, an 'unset VAR' statement leaves a non-zero return
160621f50c3Smrg# status if VAR is already unset, which might be problematic if the
161621f50c3Smrg# statement is used at the end of a function (thus poisoning its return
162621f50c3Smrg# value) or when 'set -e' is active (causing even a spurious abort of
163621f50c3Smrg# the script in this case).
164621f50c3Smrgfunc_unset ()
165621f50c3Smrg{
166621f50c3Smrg    { eval $1=; (eval unset $1) >/dev/null 2>&1 && eval unset $1 || : ; }
167621f50c3Smrg}
168621f50c3Smrg
169621f50c3Smrg
170621f50c3Smrg# Make sure CDPATH doesn't cause `cd` commands to output the target dir.
171621f50c3Smrgfunc_unset CDPATH
172621f50c3Smrg
173621f50c3Smrg# Make sure ${,E,F}GREP behave sanely.
174621f50c3Smrgfunc_unset GREP_OPTIONS
175621f50c3Smrg
176dc407927Smrg
1771a9c160aSmrg## ------------------------- ##
1781a9c160aSmrg## Locate command utilities. ##
1791a9c160aSmrg## ------------------------- ##
1801a9c160aSmrg
1811a9c160aSmrg
1821a9c160aSmrg# func_executable_p FILE
1831a9c160aSmrg# ----------------------
1841a9c160aSmrg# Check that FILE is an executable regular file.
1851a9c160aSmrgfunc_executable_p ()
1861a9c160aSmrg{
1871a9c160aSmrg    test -f "$1" && test -x "$1"
1881a9c160aSmrg}
1891a9c160aSmrg
1901a9c160aSmrg
1911a9c160aSmrg# func_path_progs PROGS_LIST CHECK_FUNC [PATH]
1921a9c160aSmrg# --------------------------------------------
1931a9c160aSmrg# Search for either a program that responds to --version with output
1941a9c160aSmrg# containing "GNU", or else returned by CHECK_FUNC otherwise, by
1951a9c160aSmrg# trying all the directories in PATH with each of the elements of
1961a9c160aSmrg# PROGS_LIST.
1971a9c160aSmrg#
1981a9c160aSmrg# CHECK_FUNC should accept the path to a candidate program, and
1991a9c160aSmrg# set $func_check_prog_result if it truncates its output less than
2001a9c160aSmrg# $_G_path_prog_max characters.
2011a9c160aSmrgfunc_path_progs ()
2021a9c160aSmrg{
2031a9c160aSmrg    _G_progs_list=$1
2041a9c160aSmrg    _G_check_func=$2
2051a9c160aSmrg    _G_PATH=${3-"$PATH"}
2061a9c160aSmrg
2071a9c160aSmrg    _G_path_prog_max=0
2081a9c160aSmrg    _G_path_prog_found=false
2091a9c160aSmrg    _G_save_IFS=$IFS; IFS=${PATH_SEPARATOR-:}
2101a9c160aSmrg    for _G_dir in $_G_PATH; do
2111a9c160aSmrg      IFS=$_G_save_IFS
2121a9c160aSmrg      test -z "$_G_dir" && _G_dir=.
2131a9c160aSmrg      for _G_prog_name in $_G_progs_list; do
2141a9c160aSmrg        for _exeext in '' .EXE; do
2151a9c160aSmrg          _G_path_prog=$_G_dir/$_G_prog_name$_exeext
2161a9c160aSmrg          func_executable_p "$_G_path_prog" || continue
2171a9c160aSmrg          case `"$_G_path_prog" --version 2>&1` in
2181a9c160aSmrg            *GNU*) func_path_progs_result=$_G_path_prog _G_path_prog_found=: ;;
2191a9c160aSmrg            *)     $_G_check_func $_G_path_prog
2201a9c160aSmrg		   func_path_progs_result=$func_check_prog_result
2211a9c160aSmrg		   ;;
2221a9c160aSmrg          esac
2231a9c160aSmrg          $_G_path_prog_found && break 3
2241a9c160aSmrg        done
2251a9c160aSmrg      done
2261a9c160aSmrg    done
2271a9c160aSmrg    IFS=$_G_save_IFS
2281a9c160aSmrg    test -z "$func_path_progs_result" && {
2291a9c160aSmrg      echo "no acceptable sed could be found in \$PATH" >&2
2301a9c160aSmrg      exit 1
2311a9c160aSmrg    }
2321a9c160aSmrg}
2331a9c160aSmrg
2341a9c160aSmrg
2351a9c160aSmrg# We want to be able to use the functions in this file before configure
2361a9c160aSmrg# has figured out where the best binaries are kept, which means we have
2371a9c160aSmrg# to search for them ourselves - except when the results are already set
2381a9c160aSmrg# where we skip the searches.
2391a9c160aSmrg
2401a9c160aSmrg# Unless the user overrides by setting SED, search the path for either GNU
2411a9c160aSmrg# sed, or the sed that truncates its output the least.
2421a9c160aSmrgtest -z "$SED" && {
2431a9c160aSmrg  _G_sed_script=s/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb/
2441a9c160aSmrg  for _G_i in 1 2 3 4 5 6 7; do
2451a9c160aSmrg    _G_sed_script=$_G_sed_script$nl$_G_sed_script
2461a9c160aSmrg  done
2471a9c160aSmrg  echo "$_G_sed_script" 2>/dev/null | sed 99q >conftest.sed
2481a9c160aSmrg  _G_sed_script=
2491a9c160aSmrg
2501a9c160aSmrg  func_check_prog_sed ()
2511a9c160aSmrg  {
2521a9c160aSmrg    _G_path_prog=$1
2531a9c160aSmrg
2541a9c160aSmrg    _G_count=0
2551a9c160aSmrg    printf 0123456789 >conftest.in
2561a9c160aSmrg    while :
2571a9c160aSmrg    do
2581a9c160aSmrg      cat conftest.in conftest.in >conftest.tmp
2591a9c160aSmrg      mv conftest.tmp conftest.in
2601a9c160aSmrg      cp conftest.in conftest.nl
2611a9c160aSmrg      echo '' >> conftest.nl
2621a9c160aSmrg      "$_G_path_prog" -f conftest.sed <conftest.nl >conftest.out 2>/dev/null || break
2631a9c160aSmrg      diff conftest.out conftest.nl >/dev/null 2>&1 || break
2641a9c160aSmrg      _G_count=`expr $_G_count + 1`
2651a9c160aSmrg      if test "$_G_count" -gt "$_G_path_prog_max"; then
2661a9c160aSmrg        # Best one so far, save it but keep looking for a better one
2671a9c160aSmrg        func_check_prog_result=$_G_path_prog
2681a9c160aSmrg        _G_path_prog_max=$_G_count
2691a9c160aSmrg      fi
2701a9c160aSmrg      # 10*(2^10) chars as input seems more than enough
2711a9c160aSmrg      test 10 -lt "$_G_count" && break
2721a9c160aSmrg    done
2731a9c160aSmrg    rm -f conftest.in conftest.tmp conftest.nl conftest.out
2741a9c160aSmrg  }
2751a9c160aSmrg
276621f50c3Smrg  func_path_progs "sed gsed" func_check_prog_sed "$PATH:/usr/xpg4/bin"
2771a9c160aSmrg  rm -f conftest.sed
2781a9c160aSmrg  SED=$func_path_progs_result
2791a9c160aSmrg}
2801a9c160aSmrg
2811a9c160aSmrg
2821a9c160aSmrg# Unless the user overrides by setting GREP, search the path for either GNU
2831a9c160aSmrg# grep, or the grep that truncates its output the least.
2841a9c160aSmrgtest -z "$GREP" && {
2851a9c160aSmrg  func_check_prog_grep ()
2861a9c160aSmrg  {
2871a9c160aSmrg    _G_path_prog=$1
2881a9c160aSmrg
2891a9c160aSmrg    _G_count=0
2901a9c160aSmrg    _G_path_prog_max=0
2911a9c160aSmrg    printf 0123456789 >conftest.in
2921a9c160aSmrg    while :
2931a9c160aSmrg    do
2941a9c160aSmrg      cat conftest.in conftest.in >conftest.tmp
2951a9c160aSmrg      mv conftest.tmp conftest.in
2961a9c160aSmrg      cp conftest.in conftest.nl
2971a9c160aSmrg      echo 'GREP' >> conftest.nl
2981a9c160aSmrg      "$_G_path_prog" -e 'GREP$' -e '-(cannot match)-' <conftest.nl >conftest.out 2>/dev/null || break
2991a9c160aSmrg      diff conftest.out conftest.nl >/dev/null 2>&1 || break
3001a9c160aSmrg      _G_count=`expr $_G_count + 1`
3011a9c160aSmrg      if test "$_G_count" -gt "$_G_path_prog_max"; then
3021a9c160aSmrg        # Best one so far, save it but keep looking for a better one
3031a9c160aSmrg        func_check_prog_result=$_G_path_prog
3041a9c160aSmrg        _G_path_prog_max=$_G_count
3051a9c160aSmrg      fi
3061a9c160aSmrg      # 10*(2^10) chars as input seems more than enough
3071a9c160aSmrg      test 10 -lt "$_G_count" && break
3081a9c160aSmrg    done
3091a9c160aSmrg    rm -f conftest.in conftest.tmp conftest.nl conftest.out
3101a9c160aSmrg  }
3111a9c160aSmrg
312621f50c3Smrg  func_path_progs "grep ggrep" func_check_prog_grep "$PATH:/usr/xpg4/bin"
3131a9c160aSmrg  GREP=$func_path_progs_result
3141a9c160aSmrg}
3151a9c160aSmrg
3161a9c160aSmrg
3171a9c160aSmrg## ------------------------------- ##
3181a9c160aSmrg## User overridable command paths. ##
3191a9c160aSmrg## ------------------------------- ##
3201a9c160aSmrg
3211a9c160aSmrg# All uppercase variable names are used for environment variables.  These
3221a9c160aSmrg# variables can be overridden by the user before calling a script that
3231a9c160aSmrg# uses them if a suitable command of that name is not already available
3241a9c160aSmrg# in the command search PATH.
325dc407927Smrg
326dc407927Smrg: ${CP="cp -f"}
3271a9c160aSmrg: ${ECHO="printf %s\n"}
3281a9c160aSmrg: ${EGREP="$GREP -E"}
3291a9c160aSmrg: ${FGREP="$GREP -F"}
3301a9c160aSmrg: ${LN_S="ln -s"}
331dc407927Smrg: ${MAKE="make"}
332dc407927Smrg: ${MKDIR="mkdir"}
333dc407927Smrg: ${MV="mv -f"}
334dc407927Smrg: ${RM="rm -f"}
335dc407927Smrg: ${SHELL="${CONFIG_SHELL-/bin/sh}"}
3363eed67faSmbalmer
337dc407927Smrg
3381a9c160aSmrg## -------------------- ##
3391a9c160aSmrg## Useful sed snippets. ##
3401a9c160aSmrg## -------------------- ##
341dd0822caSmrg
3421a9c160aSmrgsed_dirname='s|/[^/]*$||'
3431a9c160aSmrgsed_basename='s|^.*/||'
344dd0822caSmrg
3451a9c160aSmrg# Sed substitution that helps us do robust quoting.  It backslashifies
3461a9c160aSmrg# metacharacters that are still active within double-quoted strings.
3471a9c160aSmrgsed_quote_subst='s|\([`"$\\]\)|\\\1|g'
348dd0822caSmrg
3491a9c160aSmrg# Same as above, but do not quote variable references.
3501a9c160aSmrgsed_double_quote_subst='s/\(["`\\]\)/\\\1/g'
351dd0822caSmrg
3521a9c160aSmrg# Sed substitution that turns a string into a regex matching for the
3531a9c160aSmrg# string literally.
3541a9c160aSmrgsed_make_literal_regex='s|[].[^$\\*\/]|\\&|g'
355dd0822caSmrg
3561a9c160aSmrg# Sed substitution that converts a w32 file name or path
3571a9c160aSmrg# that contains forward slashes, into one that contains
3581a9c160aSmrg# (escaped) backslashes.  A very naive implementation.
3591a9c160aSmrgsed_naive_backslashify='s|\\\\*|\\|g;s|/|\\|g;s|\\|\\\\|g'
3601a9c160aSmrg
3611a9c160aSmrg# Re-'\' parameter expansions in output of sed_double_quote_subst that
3621a9c160aSmrg# were '\'-ed in input to the same.  If an odd number of '\' preceded a
3631a9c160aSmrg# '$' in input to sed_double_quote_subst, that '$' was protected from
3641a9c160aSmrg# expansion.  Since each input '\' is now two '\'s, look for any number
3651a9c160aSmrg# of runs of four '\'s followed by two '\'s and then a '$'.  '\' that '$'.
3661a9c160aSmrg_G_bs='\\'
3671a9c160aSmrg_G_bs2='\\\\'
3681a9c160aSmrg_G_bs4='\\\\\\\\'
3691a9c160aSmrg_G_dollar='\$'
3701a9c160aSmrgsed_double_backslash="\
3711a9c160aSmrg  s/$_G_bs4/&\\
3721a9c160aSmrg/g
3731a9c160aSmrg  s/^$_G_bs2$_G_dollar/$_G_bs&/
3741a9c160aSmrg  s/\\([^$_G_bs]\\)$_G_bs2$_G_dollar/\\1$_G_bs2$_G_bs$_G_dollar/g
3751a9c160aSmrg  s/\n//g"
376dd0822caSmrg
377621f50c3Smrg# require_check_ifs_backslash
378621f50c3Smrg# ---------------------------
379621f50c3Smrg# Check if we can use backslash as IFS='\' separator, and set
380621f50c3Smrg# $check_ifs_backshlash_broken to ':' or 'false'.
381621f50c3Smrgrequire_check_ifs_backslash=func_require_check_ifs_backslash
382621f50c3Smrgfunc_require_check_ifs_backslash ()
383621f50c3Smrg{
384621f50c3Smrg  _G_save_IFS=$IFS
385621f50c3Smrg  IFS='\'
386621f50c3Smrg  _G_check_ifs_backshlash='a\\b'
387621f50c3Smrg  for _G_i in $_G_check_ifs_backshlash
388621f50c3Smrg  do
389621f50c3Smrg  case $_G_i in
390621f50c3Smrg  a)
391621f50c3Smrg    check_ifs_backshlash_broken=false
392621f50c3Smrg    ;;
393621f50c3Smrg  '')
394621f50c3Smrg    break
395621f50c3Smrg    ;;
396621f50c3Smrg  *)
397621f50c3Smrg    check_ifs_backshlash_broken=:
398621f50c3Smrg    break
399621f50c3Smrg    ;;
400621f50c3Smrg  esac
401621f50c3Smrg  done
402621f50c3Smrg  IFS=$_G_save_IFS
403621f50c3Smrg  require_check_ifs_backslash=:
404621f50c3Smrg}
405621f50c3Smrg
406dd0822caSmrg
4071a9c160aSmrg## ----------------- ##
4081a9c160aSmrg## Global variables. ##
4091a9c160aSmrg## ----------------- ##
410dd0822caSmrg
4111a9c160aSmrg# Except for the global variables explicitly listed below, the following
4121a9c160aSmrg# functions in the '^func_' namespace, and the '^require_' namespace
4131a9c160aSmrg# variables initialised in the 'Resource management' section, sourcing
4141a9c160aSmrg# this file will not pollute your global namespace with anything
4151a9c160aSmrg# else. There's no portable way to scope variables in Bourne shell
4161a9c160aSmrg# though, so actually running these functions will sometimes place
4171a9c160aSmrg# results into a variable named after the function, and often use
4181a9c160aSmrg# temporary variables in the '^_G_' namespace. If you are careful to
4191a9c160aSmrg# avoid using those namespaces casually in your sourcing script, things
4201a9c160aSmrg# should continue to work as you expect. And, of course, you can freely
4211a9c160aSmrg# overwrite any of the functions or variables defined here before
4221a9c160aSmrg# calling anything to customize them.
423dd0822caSmrg
4241a9c160aSmrgEXIT_SUCCESS=0
4251a9c160aSmrgEXIT_FAILURE=1
4261a9c160aSmrgEXIT_MISMATCH=63  # $? = 63 is used to indicate version mismatch to missing.
4271a9c160aSmrgEXIT_SKIP=77	  # $? = 77 is used to indicate a skipped test to automake.
4283eed67faSmbalmer
4291a9c160aSmrg# Allow overriding, eg assuming that you follow the convention of
4301a9c160aSmrg# putting '$debug_cmd' at the start of all your functions, you can get
4311a9c160aSmrg# bash to show function call trace with:
4321a9c160aSmrg#
4331a9c160aSmrg#    debug_cmd='eval echo "${FUNCNAME[0]} $*" >&2' bash your-script-name
4341a9c160aSmrgdebug_cmd=${debug_cmd-":"}
4351a9c160aSmrgexit_cmd=:
436dc407927Smrg
4371a9c160aSmrg# By convention, finish your script with:
4381a9c160aSmrg#
4391a9c160aSmrg#    exit $exit_status
4401a9c160aSmrg#
4411a9c160aSmrg# so that you can set exit_status to non-zero if you want to indicate
4421a9c160aSmrg# something went wrong during execution without actually bailing out at
4431a9c160aSmrg# the point of failure.
4441a9c160aSmrgexit_status=$EXIT_SUCCESS
445dd0822caSmrg
4461a9c160aSmrg# Work around backward compatibility issue on IRIX 6.5. On IRIX 6.4+, sh
4471a9c160aSmrg# is ksh but when the shell is invoked as "sh" and the current value of
4481a9c160aSmrg# the _XPG environment variable is not equal to 1 (one), the special
4491a9c160aSmrg# positional parameter $0, within a function call, is the name of the
4501a9c160aSmrg# function.
4511a9c160aSmrgprogpath=$0
452dc407927Smrg
4531a9c160aSmrg# The name of this program.
4541a9c160aSmrgprogname=`$ECHO "$progpath" |$SED "$sed_basename"`
455dc407927Smrg
4561a9c160aSmrg# Make sure we have an absolute progpath for reexecution:
457dc407927Smrgcase $progpath in
458dc407927Smrg  [\\/]*|[A-Za-z]:\\*) ;;
459dc407927Smrg  *[\\/]*)
4601a9c160aSmrg     progdir=`$ECHO "$progpath" |$SED "$sed_dirname"`
461dc407927Smrg     progdir=`cd "$progdir" && pwd`
4621a9c160aSmrg     progpath=$progdir/$progname
463dc407927Smrg     ;;
464dc407927Smrg  *)
4651a9c160aSmrg     _G_IFS=$IFS
46675cbef56Smrg     IFS=${PATH_SEPARATOR-:}
467dc407927Smrg     for progdir in $PATH; do
4681a9c160aSmrg       IFS=$_G_IFS
469dc407927Smrg       test -x "$progdir/$progname" && break
470dc407927Smrg     done
4711a9c160aSmrg     IFS=$_G_IFS
472dc407927Smrg     test -n "$progdir" || progdir=`pwd`
4731a9c160aSmrg     progpath=$progdir/$progname
474dc407927Smrg     ;;
475dc407927Smrgesac
476dc407927Smrg
477dc407927Smrg
4781a9c160aSmrg## ----------------- ##
4791a9c160aSmrg## Standard options. ##
4801a9c160aSmrg## ----------------- ##
481dd0822caSmrg
4821a9c160aSmrg# The following options affect the operation of the functions defined
4831a9c160aSmrg# below, and should be set appropriately depending on run-time para-
4841a9c160aSmrg# meters passed on the command line.
485dc407927Smrg
486dc407927Smrgopt_dry_run=false
487dc407927Smrgopt_quiet=false
488dc407927Smrgopt_verbose=false
489dc407927Smrg
4901a9c160aSmrg# Categories 'all' and 'none' are always available.  Append any others
4911a9c160aSmrg# you will pass as the first argument to func_warning from your own
4921a9c160aSmrg# code.
4931a9c160aSmrgwarning_categories=
494dc407927Smrg
4951a9c160aSmrg# By default, display warnings according to 'opt_warning_types'.  Set
4961a9c160aSmrg# 'warning_func'  to ':' to elide all warnings, or func_fatal_error to
4971a9c160aSmrg# treat the next displayed warning as a fatal error.
4981a9c160aSmrgwarning_func=func_warn_and_continue
499dc407927Smrg
5001a9c160aSmrg# Set to 'all' to display all warnings, 'none' to suppress all
5011a9c160aSmrg# warnings, or a space delimited list of some subset of
5021a9c160aSmrg# 'warning_categories' to display only the listed warnings.
5031a9c160aSmrgopt_warning_types=all
504dc407927Smrg
505dd0822caSmrg
5061a9c160aSmrg## -------------------- ##
5071a9c160aSmrg## Resource management. ##
5081a9c160aSmrg## -------------------- ##
509dc407927Smrg
5101a9c160aSmrg# This section contains definitions for functions that each ensure a
5111a9c160aSmrg# particular resource (a file, or a non-empty configuration variable for
5121a9c160aSmrg# example) is available, and if appropriate to extract default values
5131a9c160aSmrg# from pertinent package files. Call them using their associated
5141a9c160aSmrg# 'require_*' variable to ensure that they are executed, at most, once.
5151a9c160aSmrg#
5161a9c160aSmrg# It's entirely deliberate that calling these functions can set
5171a9c160aSmrg# variables that don't obey the namespace limitations obeyed by the rest
5181a9c160aSmrg# of this file, in order that that they be as useful as possible to
5191a9c160aSmrg# callers.
520dc407927Smrg
521dc407927Smrg
5221a9c160aSmrg# require_term_colors
5231a9c160aSmrg# -------------------
5241a9c160aSmrg# Allow display of bold text on terminals that support it.
5251a9c160aSmrgrequire_term_colors=func_require_term_colors
5261a9c160aSmrgfunc_require_term_colors ()
527dc407927Smrg{
5281a9c160aSmrg    $debug_cmd
5291a9c160aSmrg
5301a9c160aSmrg    test -t 1 && {
5311a9c160aSmrg      # COLORTERM and USE_ANSI_COLORS environment variables take
5321a9c160aSmrg      # precedence, because most terminfo databases neglect to describe
5331a9c160aSmrg      # whether color sequences are supported.
5341a9c160aSmrg      test -n "${COLORTERM+set}" && : ${USE_ANSI_COLORS="1"}
5351a9c160aSmrg
5361a9c160aSmrg      if test 1 = "$USE_ANSI_COLORS"; then
5371a9c160aSmrg        # Standard ANSI escape sequences
5381a9c160aSmrg        tc_reset='[0m'
5391a9c160aSmrg        tc_bold='[1m';   tc_standout='[7m'
5401a9c160aSmrg        tc_red='[31m';   tc_green='[32m'
5411a9c160aSmrg        tc_blue='[34m';  tc_cyan='[36m'
5421a9c160aSmrg      else
5431a9c160aSmrg        # Otherwise trust the terminfo database after all.
5441a9c160aSmrg        test -n "`tput sgr0 2>/dev/null`" && {
5451a9c160aSmrg          tc_reset=`tput sgr0`
5461a9c160aSmrg          test -n "`tput bold 2>/dev/null`" && tc_bold=`tput bold`
5471a9c160aSmrg          tc_standout=$tc_bold
5481a9c160aSmrg          test -n "`tput smso 2>/dev/null`" && tc_standout=`tput smso`
5491a9c160aSmrg          test -n "`tput setaf 1 2>/dev/null`" && tc_red=`tput setaf 1`
5501a9c160aSmrg          test -n "`tput setaf 2 2>/dev/null`" && tc_green=`tput setaf 2`
5511a9c160aSmrg          test -n "`tput setaf 4 2>/dev/null`" && tc_blue=`tput setaf 4`
5521a9c160aSmrg          test -n "`tput setaf 5 2>/dev/null`" && tc_cyan=`tput setaf 5`
5531a9c160aSmrg        }
5541a9c160aSmrg      fi
5551a9c160aSmrg    }
556dc407927Smrg
5571a9c160aSmrg    require_term_colors=:
558dc407927Smrg}
559dc407927Smrg
560dc407927Smrg
5611a9c160aSmrg## ----------------- ##
5621a9c160aSmrg## Function library. ##
5631a9c160aSmrg## ----------------- ##
5641a9c160aSmrg
5651a9c160aSmrg# This section contains a variety of useful functions to call in your
5661a9c160aSmrg# scripts. Take note of the portable wrappers for features provided by
5671a9c160aSmrg# some modern shells, which will fall back to slower equivalents on
5681a9c160aSmrg# less featureful shells.
5691a9c160aSmrg
5701a9c160aSmrg
5711a9c160aSmrg# func_append VAR VALUE
5721a9c160aSmrg# ---------------------
5731a9c160aSmrg# Append VALUE onto the existing contents of VAR.
5741a9c160aSmrg
5751a9c160aSmrg  # We should try to minimise forks, especially on Windows where they are
5761a9c160aSmrg  # unreasonably slow, so skip the feature probes when bash or zsh are
5771a9c160aSmrg  # being used:
5781a9c160aSmrg  if test set = "${BASH_VERSION+set}${ZSH_VERSION+set}"; then
5791a9c160aSmrg    : ${_G_HAVE_ARITH_OP="yes"}
5801a9c160aSmrg    : ${_G_HAVE_XSI_OPS="yes"}
5811a9c160aSmrg    # The += operator was introduced in bash 3.1
5821a9c160aSmrg    case $BASH_VERSION in
5831a9c160aSmrg      [12].* | 3.0 | 3.0*) ;;
5841a9c160aSmrg      *)
5851a9c160aSmrg        : ${_G_HAVE_PLUSEQ_OP="yes"}
5861a9c160aSmrg        ;;
5871a9c160aSmrg    esac
5881a9c160aSmrg  fi
5891a9c160aSmrg
5901a9c160aSmrg  # _G_HAVE_PLUSEQ_OP
5911a9c160aSmrg  # Can be empty, in which case the shell is probed, "yes" if += is
5921a9c160aSmrg  # useable or anything else if it does not work.
5931a9c160aSmrg  test -z "$_G_HAVE_PLUSEQ_OP" \
5941a9c160aSmrg    && (eval 'x=a; x+=" b"; test "a b" = "$x"') 2>/dev/null \
5951a9c160aSmrg    && _G_HAVE_PLUSEQ_OP=yes
5961a9c160aSmrg
5971a9c160aSmrgif test yes = "$_G_HAVE_PLUSEQ_OP"
5981a9c160aSmrgthen
5991a9c160aSmrg  # This is an XSI compatible shell, allowing a faster implementation...
6001a9c160aSmrg  eval 'func_append ()
6011a9c160aSmrg  {
6021a9c160aSmrg    $debug_cmd
6031a9c160aSmrg
6041a9c160aSmrg    eval "$1+=\$2"
6051a9c160aSmrg  }'
6061a9c160aSmrgelse
6071a9c160aSmrg  # ...otherwise fall back to using expr, which is often a shell builtin.
6081a9c160aSmrg  func_append ()
6091a9c160aSmrg  {
6101a9c160aSmrg    $debug_cmd
6111a9c160aSmrg
6121a9c160aSmrg    eval "$1=\$$1\$2"
6131a9c160aSmrg  }
6141a9c160aSmrgfi
6151a9c160aSmrg
6161a9c160aSmrg
6171a9c160aSmrg# func_append_quoted VAR VALUE
6181a9c160aSmrg# ----------------------------
6191a9c160aSmrg# Quote VALUE and append to the end of shell variable VAR, separated
6201a9c160aSmrg# by a space.
6211a9c160aSmrgif test yes = "$_G_HAVE_PLUSEQ_OP"; then
6221a9c160aSmrg  eval 'func_append_quoted ()
6231a9c160aSmrg  {
6241a9c160aSmrg    $debug_cmd
6251a9c160aSmrg
626621f50c3Smrg    func_quote_arg pretty "$2"
627621f50c3Smrg    eval "$1+=\\ \$func_quote_arg_result"
6281a9c160aSmrg  }'
6291a9c160aSmrgelse
6301a9c160aSmrg  func_append_quoted ()
6311a9c160aSmrg  {
6321a9c160aSmrg    $debug_cmd
6331a9c160aSmrg
634621f50c3Smrg    func_quote_arg pretty "$2"
635621f50c3Smrg    eval "$1=\$$1\\ \$func_quote_arg_result"
6361a9c160aSmrg  }
6371a9c160aSmrgfi
6381a9c160aSmrg
6391a9c160aSmrg
6401a9c160aSmrg# func_append_uniq VAR VALUE
6411a9c160aSmrg# --------------------------
6421a9c160aSmrg# Append unique VALUE onto the existing contents of VAR, assuming
6431a9c160aSmrg# entries are delimited by the first character of VALUE.  For example:
6441a9c160aSmrg#
6451a9c160aSmrg#   func_append_uniq options " --another-option option-argument"
6461a9c160aSmrg#
6471a9c160aSmrg# will only append to $options if " --another-option option-argument "
6481a9c160aSmrg# is not already present somewhere in $options already (note spaces at
6491a9c160aSmrg# each end implied by leading space in second argument).
6501a9c160aSmrgfunc_append_uniq ()
6511a9c160aSmrg{
6521a9c160aSmrg    $debug_cmd
6531a9c160aSmrg
6541a9c160aSmrg    eval _G_current_value='`$ECHO $'$1'`'
6551a9c160aSmrg    _G_delim=`expr "$2" : '\(.\)'`
6561a9c160aSmrg
6571a9c160aSmrg    case $_G_delim$_G_current_value$_G_delim in
6581a9c160aSmrg      *"$2$_G_delim"*) ;;
6591a9c160aSmrg      *) func_append "$@" ;;
6601a9c160aSmrg    esac
6611a9c160aSmrg}
6621a9c160aSmrg
6631a9c160aSmrg
6641a9c160aSmrg# func_arith TERM...
6651a9c160aSmrg# ------------------
6661a9c160aSmrg# Set func_arith_result to the result of evaluating TERMs.
6671a9c160aSmrg  test -z "$_G_HAVE_ARITH_OP" \
6681a9c160aSmrg    && (eval 'test 2 = $(( 1 + 1 ))') 2>/dev/null \
6691a9c160aSmrg    && _G_HAVE_ARITH_OP=yes
6701a9c160aSmrg
6711a9c160aSmrgif test yes = "$_G_HAVE_ARITH_OP"; then
6721a9c160aSmrg  eval 'func_arith ()
6731a9c160aSmrg  {
6741a9c160aSmrg    $debug_cmd
6751a9c160aSmrg
6761a9c160aSmrg    func_arith_result=$(( $* ))
6771a9c160aSmrg  }'
6781a9c160aSmrgelse
6791a9c160aSmrg  func_arith ()
6801a9c160aSmrg  {
6811a9c160aSmrg    $debug_cmd
6821a9c160aSmrg
6831a9c160aSmrg    func_arith_result=`expr "$@"`
6841a9c160aSmrg  }
6851a9c160aSmrgfi
6861a9c160aSmrg
6871a9c160aSmrg
6881a9c160aSmrg# func_basename FILE
6891a9c160aSmrg# ------------------
6901a9c160aSmrg# Set func_basename_result to FILE with everything up to and including
6911a9c160aSmrg# the last / stripped.
6921a9c160aSmrgif test yes = "$_G_HAVE_XSI_OPS"; then
6931a9c160aSmrg  # If this shell supports suffix pattern removal, then use it to avoid
6941a9c160aSmrg  # forking. Hide the definitions single quotes in case the shell chokes
6951a9c160aSmrg  # on unsupported syntax...
6961a9c160aSmrg  _b='func_basename_result=${1##*/}'
6971a9c160aSmrg  _d='case $1 in
6981a9c160aSmrg        */*) func_dirname_result=${1%/*}$2 ;;
6991a9c160aSmrg        *  ) func_dirname_result=$3        ;;
7001a9c160aSmrg      esac'
7011a9c160aSmrg
7021a9c160aSmrgelse
7031a9c160aSmrg  # ...otherwise fall back to using sed.
7041a9c160aSmrg  _b='func_basename_result=`$ECHO "$1" |$SED "$sed_basename"`'
7051a9c160aSmrg  _d='func_dirname_result=`$ECHO "$1"  |$SED "$sed_dirname"`
7061a9c160aSmrg      if test "X$func_dirname_result" = "X$1"; then
7071a9c160aSmrg        func_dirname_result=$3
7081a9c160aSmrg      else
7091a9c160aSmrg        func_append func_dirname_result "$2"
7101a9c160aSmrg      fi'
7111a9c160aSmrgfi
7121a9c160aSmrg
7131a9c160aSmrgeval 'func_basename ()
7141a9c160aSmrg{
7151a9c160aSmrg    $debug_cmd
7161a9c160aSmrg
7171a9c160aSmrg    '"$_b"'
7181a9c160aSmrg}'
7191a9c160aSmrg
7201a9c160aSmrg
7211a9c160aSmrg# func_dirname FILE APPEND NONDIR_REPLACEMENT
7221a9c160aSmrg# -------------------------------------------
7231a9c160aSmrg# Compute the dirname of FILE.  If nonempty, add APPEND to the result,
7241a9c160aSmrg# otherwise set result to NONDIR_REPLACEMENT.
7251a9c160aSmrgeval 'func_dirname ()
7261a9c160aSmrg{
7271a9c160aSmrg    $debug_cmd
7281a9c160aSmrg
7291a9c160aSmrg    '"$_d"'
7301a9c160aSmrg}'
7311a9c160aSmrg
7321a9c160aSmrg
7331a9c160aSmrg# func_dirname_and_basename FILE APPEND NONDIR_REPLACEMENT
7341a9c160aSmrg# --------------------------------------------------------
7351a9c160aSmrg# Perform func_basename and func_dirname in a single function
7361a9c160aSmrg# call:
7371a9c160aSmrg#   dirname:  Compute the dirname of FILE.  If nonempty,
7381a9c160aSmrg#             add APPEND to the result, otherwise set result
7391a9c160aSmrg#             to NONDIR_REPLACEMENT.
7401a9c160aSmrg#             value returned in "$func_dirname_result"
7411a9c160aSmrg#   basename: Compute filename of FILE.
7421a9c160aSmrg#             value retuned in "$func_basename_result"
7431a9c160aSmrg# For efficiency, we do not delegate to the functions above but instead
7441a9c160aSmrg# duplicate the functionality here.
7451a9c160aSmrgeval 'func_dirname_and_basename ()
7461a9c160aSmrg{
7471a9c160aSmrg    $debug_cmd
7481a9c160aSmrg
7491a9c160aSmrg    '"$_b"'
7501a9c160aSmrg    '"$_d"'
7511a9c160aSmrg}'
7521a9c160aSmrg
7531a9c160aSmrg
7541a9c160aSmrg# func_echo ARG...
7551a9c160aSmrg# ----------------
7561a9c160aSmrg# Echo program name prefixed message.
7571a9c160aSmrgfunc_echo ()
7581a9c160aSmrg{
7591a9c160aSmrg    $debug_cmd
7601a9c160aSmrg
7611a9c160aSmrg    _G_message=$*
7621a9c160aSmrg
7631a9c160aSmrg    func_echo_IFS=$IFS
7641a9c160aSmrg    IFS=$nl
7651a9c160aSmrg    for _G_line in $_G_message; do
7661a9c160aSmrg      IFS=$func_echo_IFS
7671a9c160aSmrg      $ECHO "$progname: $_G_line"
7681a9c160aSmrg    done
7691a9c160aSmrg    IFS=$func_echo_IFS
7701a9c160aSmrg}
7711a9c160aSmrg
7721a9c160aSmrg
7731a9c160aSmrg# func_echo_all ARG...
7741a9c160aSmrg# --------------------
7751a9c160aSmrg# Invoke $ECHO with all args, space-separated.
7761a9c160aSmrgfunc_echo_all ()
7771a9c160aSmrg{
7781a9c160aSmrg    $ECHO "$*"
7791a9c160aSmrg}
7801a9c160aSmrg
7811a9c160aSmrg
7821a9c160aSmrg# func_echo_infix_1 INFIX ARG...
7831a9c160aSmrg# ------------------------------
7841a9c160aSmrg# Echo program name, followed by INFIX on the first line, with any
7851a9c160aSmrg# additional lines not showing INFIX.
7861a9c160aSmrgfunc_echo_infix_1 ()
7871a9c160aSmrg{
7881a9c160aSmrg    $debug_cmd
7891a9c160aSmrg
7901a9c160aSmrg    $require_term_colors
7911a9c160aSmrg
7921a9c160aSmrg    _G_infix=$1; shift
7931a9c160aSmrg    _G_indent=$_G_infix
7941a9c160aSmrg    _G_prefix="$progname: $_G_infix: "
7951a9c160aSmrg    _G_message=$*
7961a9c160aSmrg
7971a9c160aSmrg    # Strip color escape sequences before counting printable length
7981a9c160aSmrg    for _G_tc in "$tc_reset" "$tc_bold" "$tc_standout" "$tc_red" "$tc_green" "$tc_blue" "$tc_cyan"
7991a9c160aSmrg    do
8001a9c160aSmrg      test -n "$_G_tc" && {
8011a9c160aSmrg        _G_esc_tc=`$ECHO "$_G_tc" | $SED "$sed_make_literal_regex"`
8021a9c160aSmrg        _G_indent=`$ECHO "$_G_indent" | $SED "s|$_G_esc_tc||g"`
8031a9c160aSmrg      }
8041a9c160aSmrg    done
8051a9c160aSmrg    _G_indent="$progname: "`echo "$_G_indent" | $SED 's|.| |g'`"  " ## exclude from sc_prohibit_nested_quotes
8061a9c160aSmrg
8071a9c160aSmrg    func_echo_infix_1_IFS=$IFS
8081a9c160aSmrg    IFS=$nl
8091a9c160aSmrg    for _G_line in $_G_message; do
8101a9c160aSmrg      IFS=$func_echo_infix_1_IFS
8111a9c160aSmrg      $ECHO "$_G_prefix$tc_bold$_G_line$tc_reset" >&2
8121a9c160aSmrg      _G_prefix=$_G_indent
8131a9c160aSmrg    done
8141a9c160aSmrg    IFS=$func_echo_infix_1_IFS
8151a9c160aSmrg}
8161a9c160aSmrg
8171a9c160aSmrg
8181a9c160aSmrg# func_error ARG...
8191a9c160aSmrg# -----------------
8201a9c160aSmrg# Echo program name prefixed message to standard error.
8211a9c160aSmrgfunc_error ()
8221a9c160aSmrg{
8231a9c160aSmrg    $debug_cmd
8241a9c160aSmrg
8251a9c160aSmrg    $require_term_colors
8261a9c160aSmrg
8271a9c160aSmrg    func_echo_infix_1 "  $tc_standout${tc_red}error$tc_reset" "$*" >&2
8281a9c160aSmrg}
8291a9c160aSmrg
8301a9c160aSmrg
8311a9c160aSmrg# func_fatal_error ARG...
8321a9c160aSmrg# -----------------------
8331a9c160aSmrg# Echo program name prefixed message to standard error, and exit.
8341a9c160aSmrgfunc_fatal_error ()
8351a9c160aSmrg{
8361a9c160aSmrg    $debug_cmd
8371a9c160aSmrg
8381a9c160aSmrg    func_error "$*"
8391a9c160aSmrg    exit $EXIT_FAILURE
8401a9c160aSmrg}
8411a9c160aSmrg
8421a9c160aSmrg
8431a9c160aSmrg# func_grep EXPRESSION FILENAME
8441a9c160aSmrg# -----------------------------
845dc407927Smrg# Check whether EXPRESSION matches any line of FILENAME, without output.
846dc407927Smrgfunc_grep ()
847dc407927Smrg{
8481a9c160aSmrg    $debug_cmd
8491a9c160aSmrg
850dc407927Smrg    $GREP "$1" "$2" >/dev/null 2>&1
851dc407927Smrg}
852dc407927Smrg
853dc407927Smrg
8541a9c160aSmrg# func_len STRING
8551a9c160aSmrg# ---------------
8561a9c160aSmrg# Set func_len_result to the length of STRING. STRING may not
8571a9c160aSmrg# start with a hyphen.
8581a9c160aSmrg  test -z "$_G_HAVE_XSI_OPS" \
8591a9c160aSmrg    && (eval 'x=a/b/c;
8601a9c160aSmrg      test 5aa/bb/cc = "${#x}${x%%/*}${x%/*}${x#*/}${x##*/}"') 2>/dev/null \
8611a9c160aSmrg    && _G_HAVE_XSI_OPS=yes
8621a9c160aSmrg
8631a9c160aSmrgif test yes = "$_G_HAVE_XSI_OPS"; then
8641a9c160aSmrg  eval 'func_len ()
8651a9c160aSmrg  {
8661a9c160aSmrg    $debug_cmd
8671a9c160aSmrg
8681a9c160aSmrg    func_len_result=${#1}
8691a9c160aSmrg  }'
8701a9c160aSmrgelse
8711a9c160aSmrg  func_len ()
8721a9c160aSmrg  {
8731a9c160aSmrg    $debug_cmd
8741a9c160aSmrg
8751a9c160aSmrg    func_len_result=`expr "$1" : ".*" 2>/dev/null || echo $max_cmd_len`
8761a9c160aSmrg  }
8771a9c160aSmrgfi
8781a9c160aSmrg
8791a9c160aSmrg
8801a9c160aSmrg# func_mkdir_p DIRECTORY-PATH
8811a9c160aSmrg# ---------------------------
882dc407927Smrg# Make sure the entire path to DIRECTORY-PATH is available.
883dc407927Smrgfunc_mkdir_p ()
884dc407927Smrg{
8851a9c160aSmrg    $debug_cmd
8861a9c160aSmrg
8871a9c160aSmrg    _G_directory_path=$1
8881a9c160aSmrg    _G_dir_list=
889dc407927Smrg
8901a9c160aSmrg    if test -n "$_G_directory_path" && test : != "$opt_dry_run"; then
891dc407927Smrg
8921a9c160aSmrg      # Protect directory names starting with '-'
8931a9c160aSmrg      case $_G_directory_path in
8941a9c160aSmrg        -*) _G_directory_path=./$_G_directory_path ;;
895dc407927Smrg      esac
896dc407927Smrg
897dc407927Smrg      # While some portion of DIR does not yet exist...
8981a9c160aSmrg      while test ! -d "$_G_directory_path"; do
899dc407927Smrg        # ...make a list in topmost first order.  Use a colon delimited
900dc407927Smrg	# list incase some portion of path contains whitespace.
9011a9c160aSmrg        _G_dir_list=$_G_directory_path:$_G_dir_list
902dc407927Smrg
903dc407927Smrg        # If the last portion added has no slash in it, the list is done
9041a9c160aSmrg        case $_G_directory_path in */*) ;; *) break ;; esac
905dc407927Smrg
906dc407927Smrg        # ...otherwise throw away the child directory and loop
9071a9c160aSmrg        _G_directory_path=`$ECHO "$_G_directory_path" | $SED -e "$sed_dirname"`
908dc407927Smrg      done
9091a9c160aSmrg      _G_dir_list=`$ECHO "$_G_dir_list" | $SED 's|:*$||'`
910dc407927Smrg
9111a9c160aSmrg      func_mkdir_p_IFS=$IFS; IFS=:
9121a9c160aSmrg      for _G_dir in $_G_dir_list; do
9131a9c160aSmrg	IFS=$func_mkdir_p_IFS
9141a9c160aSmrg        # mkdir can fail with a 'File exist' error if two processes
915dc407927Smrg        # try to create one of the directories concurrently.  Don't
916dc407927Smrg        # stop in that case!
9171a9c160aSmrg        $MKDIR "$_G_dir" 2>/dev/null || :
918dc407927Smrg      done
9191a9c160aSmrg      IFS=$func_mkdir_p_IFS
920dc407927Smrg
921dc407927Smrg      # Bail out if we (or some other process) failed to create a directory.
9221a9c160aSmrg      test -d "$_G_directory_path" || \
9231a9c160aSmrg        func_fatal_error "Failed to create '$1'"
924dc407927Smrg    fi
925dc407927Smrg}
9263eed67faSmbalmer
9273eed67faSmbalmer
9281a9c160aSmrg# func_mktempdir [BASENAME]
9291a9c160aSmrg# -------------------------
9303eed67faSmbalmer# Make a temporary directory that won't clash with other running
9313eed67faSmbalmer# libtool processes, and avoids race conditions if possible.  If
9321a9c160aSmrg# given, BASENAME is the basename for that directory.
9333eed67faSmbalmerfunc_mktempdir ()
9343eed67faSmbalmer{
9351a9c160aSmrg    $debug_cmd
9363eed67faSmbalmer
9371a9c160aSmrg    _G_template=${TMPDIR-/tmp}/${1-$progname}
9381a9c160aSmrg
9391a9c160aSmrg    if test : = "$opt_dry_run"; then
9403eed67faSmbalmer      # Return a directory name, but don't create it in dry-run mode
9411a9c160aSmrg      _G_tmpdir=$_G_template-$$
9423eed67faSmbalmer    else
9433eed67faSmbalmer
9443eed67faSmbalmer      # If mktemp works, use that first and foremost
9451a9c160aSmrg      _G_tmpdir=`mktemp -d "$_G_template-XXXXXXXX" 2>/dev/null`
9463eed67faSmbalmer
9471a9c160aSmrg      if test ! -d "$_G_tmpdir"; then
948dc407927Smrg        # Failing that, at least try and use $RANDOM to avoid a race
9491a9c160aSmrg        _G_tmpdir=$_G_template-${RANDOM-0}$$
9503eed67faSmbalmer
9511a9c160aSmrg        func_mktempdir_umask=`umask`
952dc407927Smrg        umask 0077
9531a9c160aSmrg        $MKDIR "$_G_tmpdir"
9541a9c160aSmrg        umask $func_mktempdir_umask
9553eed67faSmbalmer      fi
9563eed67faSmbalmer
9573eed67faSmbalmer      # If we're not in dry-run mode, bomb out on failure
9581a9c160aSmrg      test -d "$_G_tmpdir" || \
9591a9c160aSmrg        func_fatal_error "cannot create temporary directory '$_G_tmpdir'"
9603eed67faSmbalmer    fi
9613eed67faSmbalmer
9621a9c160aSmrg    $ECHO "$_G_tmpdir"
9631a9c160aSmrg}
9641a9c160aSmrg
9651a9c160aSmrg
9661a9c160aSmrg# func_normal_abspath PATH
9671a9c160aSmrg# ------------------------
9681a9c160aSmrg# Remove doubled-up and trailing slashes, "." path components,
9691a9c160aSmrg# and cancel out any ".." path components in PATH after making
9701a9c160aSmrg# it an absolute path.
9711a9c160aSmrgfunc_normal_abspath ()
9721a9c160aSmrg{
9731a9c160aSmrg    $debug_cmd
9741a9c160aSmrg
9751a9c160aSmrg    # These SED scripts presuppose an absolute path with a trailing slash.
9761a9c160aSmrg    _G_pathcar='s|^/\([^/]*\).*$|\1|'
9771a9c160aSmrg    _G_pathcdr='s|^/[^/]*||'
9781a9c160aSmrg    _G_removedotparts=':dotsl
9791a9c160aSmrg		s|/\./|/|g
9801a9c160aSmrg		t dotsl
9811a9c160aSmrg		s|/\.$|/|'
9821a9c160aSmrg    _G_collapseslashes='s|/\{1,\}|/|g'
9831a9c160aSmrg    _G_finalslash='s|/*$|/|'
9841a9c160aSmrg
9851a9c160aSmrg    # Start from root dir and reassemble the path.
9861a9c160aSmrg    func_normal_abspath_result=
9871a9c160aSmrg    func_normal_abspath_tpath=$1
9881a9c160aSmrg    func_normal_abspath_altnamespace=
9891a9c160aSmrg    case $func_normal_abspath_tpath in
9901a9c160aSmrg      "")
9911a9c160aSmrg        # Empty path, that just means $cwd.
9921a9c160aSmrg        func_stripname '' '/' "`pwd`"
9931a9c160aSmrg        func_normal_abspath_result=$func_stripname_result
9941a9c160aSmrg        return
9951a9c160aSmrg        ;;
9961a9c160aSmrg      # The next three entries are used to spot a run of precisely
9971a9c160aSmrg      # two leading slashes without using negated character classes;
9981a9c160aSmrg      # we take advantage of case's first-match behaviour.
9991a9c160aSmrg      ///*)
10001a9c160aSmrg        # Unusual form of absolute path, do nothing.
10011a9c160aSmrg        ;;
10021a9c160aSmrg      //*)
10031a9c160aSmrg        # Not necessarily an ordinary path; POSIX reserves leading '//'
10041a9c160aSmrg        # and for example Cygwin uses it to access remote file shares
10051a9c160aSmrg        # over CIFS/SMB, so we conserve a leading double slash if found.
10061a9c160aSmrg        func_normal_abspath_altnamespace=/
10071a9c160aSmrg        ;;
10081a9c160aSmrg      /*)
10091a9c160aSmrg        # Absolute path, do nothing.
10101a9c160aSmrg        ;;
10111a9c160aSmrg      *)
10121a9c160aSmrg        # Relative path, prepend $cwd.
10131a9c160aSmrg        func_normal_abspath_tpath=`pwd`/$func_normal_abspath_tpath
10141a9c160aSmrg        ;;
10151a9c160aSmrg    esac
10161a9c160aSmrg
10171a9c160aSmrg    # Cancel out all the simple stuff to save iterations.  We also want
10181a9c160aSmrg    # the path to end with a slash for ease of parsing, so make sure
10191a9c160aSmrg    # there is one (and only one) here.
10201a9c160aSmrg    func_normal_abspath_tpath=`$ECHO "$func_normal_abspath_tpath" | $SED \
10211a9c160aSmrg          -e "$_G_removedotparts" -e "$_G_collapseslashes" -e "$_G_finalslash"`
10221a9c160aSmrg    while :; do
10231a9c160aSmrg      # Processed it all yet?
10241a9c160aSmrg      if test / = "$func_normal_abspath_tpath"; then
10251a9c160aSmrg        # If we ascended to the root using ".." the result may be empty now.
10261a9c160aSmrg        if test -z "$func_normal_abspath_result"; then
10271a9c160aSmrg          func_normal_abspath_result=/
10281a9c160aSmrg        fi
10291a9c160aSmrg        break
10301a9c160aSmrg      fi
10311a9c160aSmrg      func_normal_abspath_tcomponent=`$ECHO "$func_normal_abspath_tpath" | $SED \
10321a9c160aSmrg          -e "$_G_pathcar"`
10331a9c160aSmrg      func_normal_abspath_tpath=`$ECHO "$func_normal_abspath_tpath" | $SED \
10341a9c160aSmrg          -e "$_G_pathcdr"`
10351a9c160aSmrg      # Figure out what to do with it
10361a9c160aSmrg      case $func_normal_abspath_tcomponent in
10371a9c160aSmrg        "")
10381a9c160aSmrg          # Trailing empty path component, ignore it.
10391a9c160aSmrg          ;;
10401a9c160aSmrg        ..)
10411a9c160aSmrg          # Parent dir; strip last assembled component from result.
10421a9c160aSmrg          func_dirname "$func_normal_abspath_result"
10431a9c160aSmrg          func_normal_abspath_result=$func_dirname_result
10441a9c160aSmrg          ;;
10451a9c160aSmrg        *)
10461a9c160aSmrg          # Actual path component, append it.
10471a9c160aSmrg          func_append func_normal_abspath_result "/$func_normal_abspath_tcomponent"
10481a9c160aSmrg          ;;
10491a9c160aSmrg      esac
10501a9c160aSmrg    done
10511a9c160aSmrg    # Restore leading double-slash if one was found on entry.
10521a9c160aSmrg    func_normal_abspath_result=$func_normal_abspath_altnamespace$func_normal_abspath_result
10531a9c160aSmrg}
10541a9c160aSmrg
10551a9c160aSmrg
10561a9c160aSmrg# func_notquiet ARG...
10571a9c160aSmrg# --------------------
10581a9c160aSmrg# Echo program name prefixed message only when not in quiet mode.
10591a9c160aSmrgfunc_notquiet ()
10601a9c160aSmrg{
10611a9c160aSmrg    $debug_cmd
10621a9c160aSmrg
10631a9c160aSmrg    $opt_quiet || func_echo ${1+"$@"}
10641a9c160aSmrg
10651a9c160aSmrg    # A bug in bash halts the script if the last line of a function
10661a9c160aSmrg    # fails when set -e is in force, so we need another command to
10671a9c160aSmrg    # work around that:
10681a9c160aSmrg    :
10691a9c160aSmrg}
10701a9c160aSmrg
10711a9c160aSmrg
10721a9c160aSmrg# func_relative_path SRCDIR DSTDIR
10731a9c160aSmrg# --------------------------------
10741a9c160aSmrg# Set func_relative_path_result to the relative path from SRCDIR to DSTDIR.
10751a9c160aSmrgfunc_relative_path ()
10761a9c160aSmrg{
10771a9c160aSmrg    $debug_cmd
10781a9c160aSmrg
10791a9c160aSmrg    func_relative_path_result=
10801a9c160aSmrg    func_normal_abspath "$1"
10811a9c160aSmrg    func_relative_path_tlibdir=$func_normal_abspath_result
10821a9c160aSmrg    func_normal_abspath "$2"
10831a9c160aSmrg    func_relative_path_tbindir=$func_normal_abspath_result
10841a9c160aSmrg
10851a9c160aSmrg    # Ascend the tree starting from libdir
10861a9c160aSmrg    while :; do
10871a9c160aSmrg      # check if we have found a prefix of bindir
10881a9c160aSmrg      case $func_relative_path_tbindir in
10891a9c160aSmrg        $func_relative_path_tlibdir)
10901a9c160aSmrg          # found an exact match
10911a9c160aSmrg          func_relative_path_tcancelled=
10921a9c160aSmrg          break
10931a9c160aSmrg          ;;
10941a9c160aSmrg        $func_relative_path_tlibdir*)
10951a9c160aSmrg          # found a matching prefix
10961a9c160aSmrg          func_stripname "$func_relative_path_tlibdir" '' "$func_relative_path_tbindir"
10971a9c160aSmrg          func_relative_path_tcancelled=$func_stripname_result
10981a9c160aSmrg          if test -z "$func_relative_path_result"; then
10991a9c160aSmrg            func_relative_path_result=.
11001a9c160aSmrg          fi
11011a9c160aSmrg          break
11021a9c160aSmrg          ;;
11031a9c160aSmrg        *)
11041a9c160aSmrg          func_dirname $func_relative_path_tlibdir
11051a9c160aSmrg          func_relative_path_tlibdir=$func_dirname_result
11061a9c160aSmrg          if test -z "$func_relative_path_tlibdir"; then
11071a9c160aSmrg            # Have to descend all the way to the root!
11081a9c160aSmrg            func_relative_path_result=../$func_relative_path_result
11091a9c160aSmrg            func_relative_path_tcancelled=$func_relative_path_tbindir
11101a9c160aSmrg            break
11111a9c160aSmrg          fi
11121a9c160aSmrg          func_relative_path_result=../$func_relative_path_result
11131a9c160aSmrg          ;;
11141a9c160aSmrg      esac
11151a9c160aSmrg    done
11161a9c160aSmrg
11171a9c160aSmrg    # Now calculate path; take care to avoid doubling-up slashes.
11181a9c160aSmrg    func_stripname '' '/' "$func_relative_path_result"
11191a9c160aSmrg    func_relative_path_result=$func_stripname_result
11201a9c160aSmrg    func_stripname '/' '/' "$func_relative_path_tcancelled"
11211a9c160aSmrg    if test -n "$func_stripname_result"; then
11221a9c160aSmrg      func_append func_relative_path_result "/$func_stripname_result"
11231a9c160aSmrg    fi
11241a9c160aSmrg
11251a9c160aSmrg    # Normalisation. If bindir is libdir, return '.' else relative path.
11261a9c160aSmrg    if test -n "$func_relative_path_result"; then
11271a9c160aSmrg      func_stripname './' '' "$func_relative_path_result"
11281a9c160aSmrg      func_relative_path_result=$func_stripname_result
11291a9c160aSmrg    fi
11301a9c160aSmrg
11311a9c160aSmrg    test -n "$func_relative_path_result" || func_relative_path_result=.
11321a9c160aSmrg
11331a9c160aSmrg    :
11341a9c160aSmrg}
11351a9c160aSmrg
11361a9c160aSmrg
1137621f50c3Smrg# func_quote_portable EVAL ARG
1138621f50c3Smrg# ----------------------------
1139621f50c3Smrg# Internal function to portably implement func_quote_arg.  Note that we still
1140621f50c3Smrg# keep attention to performance here so we as much as possible try to avoid
1141621f50c3Smrg# calling sed binary (so far O(N) complexity as long as func_append is O(1)).
1142621f50c3Smrgfunc_quote_portable ()
11431a9c160aSmrg{
11441a9c160aSmrg    $debug_cmd
11451a9c160aSmrg
1146621f50c3Smrg    $require_check_ifs_backslash
11471a9c160aSmrg
1148621f50c3Smrg    func_quote_portable_result=$2
11491a9c160aSmrg
1150621f50c3Smrg    # one-time-loop (easy break)
1151621f50c3Smrg    while true
1152621f50c3Smrg    do
1153621f50c3Smrg      if $1; then
1154621f50c3Smrg        func_quote_portable_result=`$ECHO "$2" | $SED \
1155621f50c3Smrg          -e "$sed_double_quote_subst" -e "$sed_double_backslash"`
1156621f50c3Smrg        break
1157621f50c3Smrg      fi
1158621f50c3Smrg
1159621f50c3Smrg      # Quote for eval.
1160621f50c3Smrg      case $func_quote_portable_result in
1161621f50c3Smrg        *[\\\`\"\$]*)
1162621f50c3Smrg          # Fallback to sed for $func_check_bs_ifs_broken=:, or when the string
1163621f50c3Smrg          # contains the shell wildcard characters.
1164621f50c3Smrg          case $check_ifs_backshlash_broken$func_quote_portable_result in
1165621f50c3Smrg            :*|*[\[\*\?]*)
1166621f50c3Smrg              func_quote_portable_result=`$ECHO "$func_quote_portable_result" \
1167621f50c3Smrg                  | $SED "$sed_quote_subst"`
1168621f50c3Smrg              break
11691a9c160aSmrg              ;;
1170621f50c3Smrg          esac
1171621f50c3Smrg
1172621f50c3Smrg          func_quote_portable_old_IFS=$IFS
1173621f50c3Smrg          for _G_char in '\' '`' '"' '$'
1174621f50c3Smrg          do
1175621f50c3Smrg            # STATE($1) PREV($2) SEPARATOR($3)
1176621f50c3Smrg            set start "" ""
1177621f50c3Smrg            func_quote_portable_result=dummy"$_G_char$func_quote_portable_result$_G_char"dummy
1178621f50c3Smrg            IFS=$_G_char
1179621f50c3Smrg            for _G_part in $func_quote_portable_result
1180621f50c3Smrg            do
1181621f50c3Smrg              case $1 in
1182621f50c3Smrg              quote)
1183621f50c3Smrg                func_append func_quote_portable_result "$3$2"
1184621f50c3Smrg                set quote "$_G_part" "\\$_G_char"
1185621f50c3Smrg                ;;
1186621f50c3Smrg              start)
1187621f50c3Smrg                set first "" ""
1188621f50c3Smrg                func_quote_portable_result=
1189621f50c3Smrg                ;;
1190621f50c3Smrg              first)
1191621f50c3Smrg                set quote "$_G_part" ""
1192621f50c3Smrg                ;;
1193621f50c3Smrg              esac
1194621f50c3Smrg            done
11951a9c160aSmrg          done
1196621f50c3Smrg          IFS=$func_quote_portable_old_IFS
1197621f50c3Smrg          ;;
1198621f50c3Smrg        *) ;;
1199621f50c3Smrg      esac
1200621f50c3Smrg      break
1201621f50c3Smrg    done
1202621f50c3Smrg
1203621f50c3Smrg    func_quote_portable_unquoted_result=$func_quote_portable_result
1204621f50c3Smrg    case $func_quote_portable_result in
1205621f50c3Smrg      # double-quote args containing shell metacharacters to delay
1206621f50c3Smrg      # word splitting, command substitution and variable expansion
1207621f50c3Smrg      # for a subsequent eval.
1208621f50c3Smrg      # many bourne shells cannot handle close brackets correctly
1209621f50c3Smrg      # in scan sets, so we specify it separately.
1210621f50c3Smrg      *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \	]*|*]*|"")
1211621f50c3Smrg        func_quote_portable_result=\"$func_quote_portable_result\"
12121a9c160aSmrg        ;;
12131a9c160aSmrg    esac
12141a9c160aSmrg}
12151a9c160aSmrg
12161a9c160aSmrg
1217621f50c3Smrg# func_quotefast_eval ARG
1218621f50c3Smrg# -----------------------
1219621f50c3Smrg# Quote one ARG (internal).  This is equivalent to 'func_quote_arg eval ARG',
1220621f50c3Smrg# but optimized for speed.  Result is stored in $func_quotefast_eval.
1221621f50c3Smrgif test xyes = `(x=; printf -v x %q yes; echo x"$x") 2>/dev/null`; then
1222621f50c3Smrg  printf -v _GL_test_printf_tilde %q '~'
1223621f50c3Smrg  if test '\~' = "$_GL_test_printf_tilde"; then
1224621f50c3Smrg    func_quotefast_eval ()
1225621f50c3Smrg    {
1226621f50c3Smrg      printf -v func_quotefast_eval_result %q "$1"
1227621f50c3Smrg    }
1228621f50c3Smrg  else
1229621f50c3Smrg    # Broken older Bash implementations.  Make those faster too if possible.
1230621f50c3Smrg    func_quotefast_eval ()
1231621f50c3Smrg    {
1232621f50c3Smrg      case $1 in
1233621f50c3Smrg        '~'*)
1234621f50c3Smrg          func_quote_portable false "$1"
1235621f50c3Smrg          func_quotefast_eval_result=$func_quote_portable_result
12361a9c160aSmrg          ;;
12371a9c160aSmrg        *)
1238621f50c3Smrg          printf -v func_quotefast_eval_result %q "$1"
1239621f50c3Smrg          ;;
12401a9c160aSmrg      esac
1241621f50c3Smrg    }
1242621f50c3Smrg  fi
1243621f50c3Smrgelse
1244621f50c3Smrg  func_quotefast_eval ()
1245621f50c3Smrg  {
1246621f50c3Smrg    func_quote_portable false "$1"
1247621f50c3Smrg    func_quotefast_eval_result=$func_quote_portable_result
1248621f50c3Smrg  }
1249621f50c3Smrgfi
12501a9c160aSmrg
12511a9c160aSmrg
1252621f50c3Smrg# func_quote_arg MODEs ARG
1253621f50c3Smrg# ------------------------
1254621f50c3Smrg# Quote one ARG to be evaled later.  MODEs argument may contain zero or more
1255621f50c3Smrg# specifiers listed below separated by ',' character.  This function returns two
1256621f50c3Smrg# values:
1257621f50c3Smrg#   i) func_quote_arg_result
1258621f50c3Smrg#      double-quoted (when needed), suitable for a subsequent eval
1259621f50c3Smrg#  ii) func_quote_arg_unquoted_result
1260621f50c3Smrg#      has all characters that are still active within double
1261621f50c3Smrg#      quotes backslashified.  Available only if 'unquoted' is specified.
1262621f50c3Smrg#
1263621f50c3Smrg# Available modes:
1264621f50c3Smrg# ----------------
1265621f50c3Smrg# 'eval' (default)
1266621f50c3Smrg#       - escape shell special characters
1267621f50c3Smrg# 'expand'
1268621f50c3Smrg#       - the same as 'eval';  but do not quote variable references
1269621f50c3Smrg# 'pretty'
1270621f50c3Smrg#       - request aesthetic output, i.e. '"a b"' instead of 'a\ b'.  This might
1271621f50c3Smrg#         be used later in func_quote to get output like: 'echo "a b"' instead
1272621f50c3Smrg#         of 'echo a\ b'.  This is slower than default on some shells.
1273621f50c3Smrg# 'unquoted'
1274621f50c3Smrg#       - produce also $func_quote_arg_unquoted_result which does not contain
1275621f50c3Smrg#         wrapping double-quotes.
1276621f50c3Smrg#
1277621f50c3Smrg# Examples for 'func_quote_arg pretty,unquoted string':
1278621f50c3Smrg#
1279621f50c3Smrg#   string      | *_result              | *_unquoted_result
1280621f50c3Smrg#   ------------+-----------------------+-------------------
1281621f50c3Smrg#   "           | \"                    | \"
1282621f50c3Smrg#   a b         | "a b"                 | a b
1283621f50c3Smrg#   "a b"       | "\"a b\""             | \"a b\"
1284621f50c3Smrg#   *           | "*"                   | *
1285621f50c3Smrg#   z="${x-$y}" | "z=\"\${x-\$y}\""     | z=\"\${x-\$y}\"
1286621f50c3Smrg#
1287621f50c3Smrg# Examples for 'func_quote_arg pretty,unquoted,expand string':
1288621f50c3Smrg#
1289621f50c3Smrg#   string        |   *_result          |  *_unquoted_result
1290621f50c3Smrg#   --------------+---------------------+--------------------
1291621f50c3Smrg#   z="${x-$y}"   | "z=\"${x-$y}\""     | z=\"${x-$y}\"
1292621f50c3Smrgfunc_quote_arg ()
1293621f50c3Smrg{
1294621f50c3Smrg    _G_quote_expand=false
1295621f50c3Smrg    case ,$1, in
1296621f50c3Smrg      *,expand,*)
1297621f50c3Smrg        _G_quote_expand=:
1298621f50c3Smrg        ;;
12991a9c160aSmrg    esac
13001a9c160aSmrg
1301621f50c3Smrg    case ,$1, in
1302621f50c3Smrg      *,pretty,*|*,expand,*|*,unquoted,*)
1303621f50c3Smrg        func_quote_portable $_G_quote_expand "$2"
1304621f50c3Smrg        func_quote_arg_result=$func_quote_portable_result
1305621f50c3Smrg        func_quote_arg_unquoted_result=$func_quote_portable_unquoted_result
1306621f50c3Smrg        ;;
1307621f50c3Smrg      *)
1308621f50c3Smrg        # Faster quote-for-eval for some shells.
1309621f50c3Smrg        func_quotefast_eval "$2"
1310621f50c3Smrg        func_quote_arg_result=$func_quotefast_eval_result
13111a9c160aSmrg        ;;
13121a9c160aSmrg    esac
1313621f50c3Smrg}
13141a9c160aSmrg
1315621f50c3Smrg
1316621f50c3Smrg# func_quote MODEs ARGs...
1317621f50c3Smrg# ------------------------
1318621f50c3Smrg# Quote all ARGs to be evaled later and join them into single command.  See
1319621f50c3Smrg# func_quote_arg's description for more info.
1320621f50c3Smrgfunc_quote ()
1321621f50c3Smrg{
1322621f50c3Smrg    $debug_cmd
1323621f50c3Smrg    _G_func_quote_mode=$1 ; shift
1324621f50c3Smrg    func_quote_result=
1325621f50c3Smrg    while test 0 -lt $#; do
1326621f50c3Smrg      func_quote_arg "$_G_func_quote_mode" "$1"
1327621f50c3Smrg      if test -n "$func_quote_result"; then
1328621f50c3Smrg        func_append func_quote_result " $func_quote_arg_result"
1329621f50c3Smrg      else
1330621f50c3Smrg        func_append func_quote_result "$func_quote_arg_result"
1331621f50c3Smrg      fi
1332621f50c3Smrg      shift
1333621f50c3Smrg    done
13341a9c160aSmrg}
13351a9c160aSmrg
13361a9c160aSmrg
13371a9c160aSmrg# func_stripname PREFIX SUFFIX NAME
13381a9c160aSmrg# ---------------------------------
13391a9c160aSmrg# strip PREFIX and SUFFIX from NAME, and store in func_stripname_result.
13401a9c160aSmrg# PREFIX and SUFFIX must not contain globbing or regex special
13411a9c160aSmrg# characters, hashes, percent signs, but SUFFIX may contain a leading
13421a9c160aSmrg# dot (in which case that matches only a dot).
13431a9c160aSmrgif test yes = "$_G_HAVE_XSI_OPS"; then
13441a9c160aSmrg  eval 'func_stripname ()
13451a9c160aSmrg  {
13461a9c160aSmrg    $debug_cmd
13471a9c160aSmrg
13481a9c160aSmrg    # pdksh 5.2.14 does not do ${X%$Y} correctly if both X and Y are
13491a9c160aSmrg    # positional parameters, so assign one to ordinary variable first.
13501a9c160aSmrg    func_stripname_result=$3
13511a9c160aSmrg    func_stripname_result=${func_stripname_result#"$1"}
13521a9c160aSmrg    func_stripname_result=${func_stripname_result%"$2"}
13531a9c160aSmrg  }'
13541a9c160aSmrgelse
13551a9c160aSmrg  func_stripname ()
13561a9c160aSmrg  {
13571a9c160aSmrg    $debug_cmd
13581a9c160aSmrg
13591a9c160aSmrg    case $2 in
13601a9c160aSmrg      .*) func_stripname_result=`$ECHO "$3" | $SED -e "s%^$1%%" -e "s%\\\\$2\$%%"`;;
13611a9c160aSmrg      *)  func_stripname_result=`$ECHO "$3" | $SED -e "s%^$1%%" -e "s%$2\$%%"`;;
13621a9c160aSmrg    esac
13631a9c160aSmrg  }
13641a9c160aSmrgfi
13651a9c160aSmrg
13661a9c160aSmrg
13671a9c160aSmrg# func_show_eval CMD [FAIL_EXP]
13681a9c160aSmrg# -----------------------------
13691a9c160aSmrg# Unless opt_quiet is true, then output CMD.  Then, if opt_dryrun is
13701a9c160aSmrg# not true, evaluate CMD.  If the evaluation of CMD fails, and FAIL_EXP
13711a9c160aSmrg# is given, then evaluate it.
13721a9c160aSmrgfunc_show_eval ()
13731a9c160aSmrg{
13741a9c160aSmrg    $debug_cmd
13751a9c160aSmrg
13761a9c160aSmrg    _G_cmd=$1
13771a9c160aSmrg    _G_fail_exp=${2-':'}
13781a9c160aSmrg
1379621f50c3Smrg    func_quote_arg pretty,expand "$_G_cmd"
1380621f50c3Smrg    eval "func_notquiet $func_quote_arg_result"
13811a9c160aSmrg
13821a9c160aSmrg    $opt_dry_run || {
13831a9c160aSmrg      eval "$_G_cmd"
13841a9c160aSmrg      _G_status=$?
13851a9c160aSmrg      if test 0 -ne "$_G_status"; then
13861a9c160aSmrg	eval "(exit $_G_status); $_G_fail_exp"
13871a9c160aSmrg      fi
13881a9c160aSmrg    }
13891a9c160aSmrg}
13901a9c160aSmrg
13911a9c160aSmrg
13921a9c160aSmrg# func_show_eval_locale CMD [FAIL_EXP]
13931a9c160aSmrg# ------------------------------------
13941a9c160aSmrg# Unless opt_quiet is true, then output CMD.  Then, if opt_dryrun is
13951a9c160aSmrg# not true, evaluate CMD.  If the evaluation of CMD fails, and FAIL_EXP
13961a9c160aSmrg# is given, then evaluate it.  Use the saved locale for evaluation.
13971a9c160aSmrgfunc_show_eval_locale ()
13981a9c160aSmrg{
13991a9c160aSmrg    $debug_cmd
14001a9c160aSmrg
14011a9c160aSmrg    _G_cmd=$1
14021a9c160aSmrg    _G_fail_exp=${2-':'}
14031a9c160aSmrg
14041a9c160aSmrg    $opt_quiet || {
1405621f50c3Smrg      func_quote_arg expand,pretty "$_G_cmd"
1406621f50c3Smrg      eval "func_echo $func_quote_arg_result"
14071a9c160aSmrg    }
14081a9c160aSmrg
14091a9c160aSmrg    $opt_dry_run || {
14101a9c160aSmrg      eval "$_G_user_locale
14111a9c160aSmrg	    $_G_cmd"
14121a9c160aSmrg      _G_status=$?
14131a9c160aSmrg      eval "$_G_safe_locale"
14141a9c160aSmrg      if test 0 -ne "$_G_status"; then
14151a9c160aSmrg	eval "(exit $_G_status); $_G_fail_exp"
14161a9c160aSmrg      fi
14171a9c160aSmrg    }
14181a9c160aSmrg}
14191a9c160aSmrg
14201a9c160aSmrg
14211a9c160aSmrg# func_tr_sh
14221a9c160aSmrg# ----------
14231a9c160aSmrg# Turn $1 into a string suitable for a shell variable name.
14241a9c160aSmrg# Result is stored in $func_tr_sh_result.  All characters
14251a9c160aSmrg# not in the set a-zA-Z0-9_ are replaced with '_'. Further,
14261a9c160aSmrg# if $1 begins with a digit, a '_' is prepended as well.
14271a9c160aSmrgfunc_tr_sh ()
14281a9c160aSmrg{
14291a9c160aSmrg    $debug_cmd
14301a9c160aSmrg
14311a9c160aSmrg    case $1 in
14321a9c160aSmrg    [0-9]* | *[!a-zA-Z0-9_]*)
14331a9c160aSmrg      func_tr_sh_result=`$ECHO "$1" | $SED -e 's/^\([0-9]\)/_\1/' -e 's/[^a-zA-Z0-9_]/_/g'`
14341a9c160aSmrg      ;;
14351a9c160aSmrg    * )
14361a9c160aSmrg      func_tr_sh_result=$1
14371a9c160aSmrg      ;;
14381a9c160aSmrg    esac
14391a9c160aSmrg}
14401a9c160aSmrg
14411a9c160aSmrg
14421a9c160aSmrg# func_verbose ARG...
14431a9c160aSmrg# -------------------
14441a9c160aSmrg# Echo program name prefixed message in verbose mode only.
14451a9c160aSmrgfunc_verbose ()
14461a9c160aSmrg{
14471a9c160aSmrg    $debug_cmd
14481a9c160aSmrg
14491a9c160aSmrg    $opt_verbose && func_echo "$*"
14501a9c160aSmrg
14511a9c160aSmrg    :
14521a9c160aSmrg}
14531a9c160aSmrg
14541a9c160aSmrg
14551a9c160aSmrg# func_warn_and_continue ARG...
14561a9c160aSmrg# -----------------------------
14571a9c160aSmrg# Echo program name prefixed warning message to standard error.
14581a9c160aSmrgfunc_warn_and_continue ()
14591a9c160aSmrg{
14601a9c160aSmrg    $debug_cmd
14611a9c160aSmrg
14621a9c160aSmrg    $require_term_colors
14631a9c160aSmrg
14641a9c160aSmrg    func_echo_infix_1 "${tc_red}warning$tc_reset" "$*" >&2
14651a9c160aSmrg}
14661a9c160aSmrg
14671a9c160aSmrg
14681a9c160aSmrg# func_warning CATEGORY ARG...
14691a9c160aSmrg# ----------------------------
14701a9c160aSmrg# Echo program name prefixed warning message to standard error. Warning
14711a9c160aSmrg# messages can be filtered according to CATEGORY, where this function
14721a9c160aSmrg# elides messages where CATEGORY is not listed in the global variable
14731a9c160aSmrg# 'opt_warning_types'.
14741a9c160aSmrgfunc_warning ()
14751a9c160aSmrg{
14761a9c160aSmrg    $debug_cmd
14771a9c160aSmrg
14781a9c160aSmrg    # CATEGORY must be in the warning_categories list!
14791a9c160aSmrg    case " $warning_categories " in
14801a9c160aSmrg      *" $1 "*) ;;
14811a9c160aSmrg      *) func_internal_error "invalid warning category '$1'" ;;
14821a9c160aSmrg    esac
14831a9c160aSmrg
14841a9c160aSmrg    _G_category=$1
14851a9c160aSmrg    shift
14861a9c160aSmrg
14871a9c160aSmrg    case " $opt_warning_types " in
14881a9c160aSmrg      *" $_G_category "*) $warning_func ${1+"$@"} ;;
14891a9c160aSmrg    esac
14901a9c160aSmrg}
14911a9c160aSmrg
14921a9c160aSmrg
14931a9c160aSmrg# func_sort_ver VER1 VER2
14941a9c160aSmrg# -----------------------
14951a9c160aSmrg# 'sort -V' is not generally available.
14961a9c160aSmrg# Note this deviates from the version comparison in automake
14971a9c160aSmrg# in that it treats 1.5 < 1.5.0, and treats 1.4.4a < 1.4-p3a
14981a9c160aSmrg# but this should suffice as we won't be specifying old
14991a9c160aSmrg# version formats or redundant trailing .0 in bootstrap.conf.
15001a9c160aSmrg# If we did want full compatibility then we should probably
15011a9c160aSmrg# use m4_version_compare from autoconf.
15021a9c160aSmrgfunc_sort_ver ()
15031a9c160aSmrg{
15041a9c160aSmrg    $debug_cmd
15051a9c160aSmrg
15061a9c160aSmrg    printf '%s\n%s\n' "$1" "$2" \
15071a9c160aSmrg      | 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
15081a9c160aSmrg}
15091a9c160aSmrg
15101a9c160aSmrg# func_lt_ver PREV CURR
15111a9c160aSmrg# ---------------------
15121a9c160aSmrg# Return true if PREV and CURR are in the correct order according to
15131a9c160aSmrg# func_sort_ver, otherwise false.  Use it like this:
15141a9c160aSmrg#
15151a9c160aSmrg#  func_lt_ver "$prev_ver" "$proposed_ver" || func_fatal_error "..."
15161a9c160aSmrgfunc_lt_ver ()
15171a9c160aSmrg{
15181a9c160aSmrg    $debug_cmd
15191a9c160aSmrg
15201a9c160aSmrg    test "x$1" = x`func_sort_ver "$1" "$2" | $SED 1q`
15211a9c160aSmrg}
15221a9c160aSmrg
15231a9c160aSmrg
15241a9c160aSmrg# Local variables:
15251a9c160aSmrg# mode: shell-script
15261a9c160aSmrg# sh-indentation: 2
15271a9c160aSmrg# eval: (add-hook 'before-save-hook 'time-stamp)
15281a9c160aSmrg# time-stamp-pattern: "10/scriptversion=%:y-%02m-%02d.%02H; # UTC"
15291a9c160aSmrg# time-stamp-time-zone: "UTC"
15301a9c160aSmrg# End:
15311a9c160aSmrg#! /bin/sh
15321a9c160aSmrg
15331a9c160aSmrg# A portable, pluggable option parser for Bourne shell.
15341a9c160aSmrg# Written by Gary V. Vaughan, 2010
15351a9c160aSmrg
1536621f50c3Smrg# This is free software.  There is NO warranty; not even for
1537621f50c3Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
1538621f50c3Smrg#
1539621f50c3Smrg# Copyright (C) 2010-2019, 2021 Bootstrap Authors
1540621f50c3Smrg#
1541621f50c3Smrg# This file is dual licensed under the terms of the MIT license
1542621f50c3Smrg# <https://opensource.org/license/MIT>, and GPL version 2 or later
1543621f50c3Smrg# <http://www.gnu.org/licenses/gpl-2.0.html>.  You must apply one of
1544621f50c3Smrg# these licenses when using or redistributing this software or any of
1545621f50c3Smrg# the files within it.  See the URLs above, or the file `LICENSE`
1546621f50c3Smrg# included in the Bootstrap distribution for the full license texts.
15471a9c160aSmrg
1548621f50c3Smrg# Please report bugs or propose patches to:
1549621f50c3Smrg# <https://github.com/gnulib-modules/bootstrap/issues>
15501a9c160aSmrg
1551621f50c3Smrg# Set a version string for this script.
1552621f50c3Smrgscriptversion=2019-02-19.15; # UTC
15531a9c160aSmrg
15541a9c160aSmrg
15551a9c160aSmrg## ------ ##
15561a9c160aSmrg## Usage. ##
15571a9c160aSmrg## ------ ##
15581a9c160aSmrg
15591a9c160aSmrg# This file is a library for parsing options in your shell scripts along
15601a9c160aSmrg# with assorted other useful supporting features that you can make use
15611a9c160aSmrg# of too.
15621a9c160aSmrg#
15631a9c160aSmrg# For the simplest scripts you might need only:
15641a9c160aSmrg#
15651a9c160aSmrg#   #!/bin/sh
15661a9c160aSmrg#   . relative/path/to/funclib.sh
15671a9c160aSmrg#   . relative/path/to/options-parser
15681a9c160aSmrg#   scriptversion=1.0
15691a9c160aSmrg#   func_options ${1+"$@"}
15701a9c160aSmrg#   eval set dummy "$func_options_result"; shift
15711a9c160aSmrg#   ...rest of your script...
15721a9c160aSmrg#
15731a9c160aSmrg# In order for the '--version' option to work, you will need to have a
15741a9c160aSmrg# suitably formatted comment like the one at the top of this file
1575621f50c3Smrg# starting with '# Written by ' and ending with '# Copyright'.
15761a9c160aSmrg#
15771a9c160aSmrg# For '-h' and '--help' to work, you will also need a one line
15781a9c160aSmrg# description of your script's purpose in a comment directly above the
15791a9c160aSmrg# '# Written by ' line, like the one at the top of this file.
15801a9c160aSmrg#
15811a9c160aSmrg# The default options also support '--debug', which will turn on shell
15821a9c160aSmrg# execution tracing (see the comment above debug_cmd below for another
15831a9c160aSmrg# use), and '--verbose' and the func_verbose function to allow your script
15841a9c160aSmrg# to display verbose messages only when your user has specified
15851a9c160aSmrg# '--verbose'.
15861a9c160aSmrg#
1587621f50c3Smrg# After sourcing this file, you can plug in processing for additional
15881a9c160aSmrg# options by amending the variables from the 'Configuration' section
15891a9c160aSmrg# below, and following the instructions in the 'Option parsing'
15901a9c160aSmrg# section further down.
15911a9c160aSmrg
15921a9c160aSmrg## -------------- ##
15931a9c160aSmrg## Configuration. ##
15941a9c160aSmrg## -------------- ##
15951a9c160aSmrg
15961a9c160aSmrg# You should override these variables in your script after sourcing this
15971a9c160aSmrg# file so that they reflect the customisations you have added to the
15981a9c160aSmrg# option parser.
15991a9c160aSmrg
16001a9c160aSmrg# The usage line for option parsing errors and the start of '-h' and
16011a9c160aSmrg# '--help' output messages. You can embed shell variables for delayed
16021a9c160aSmrg# expansion at the time the message is displayed, but you will need to
16031a9c160aSmrg# quote other shell meta-characters carefully to prevent them being
16041a9c160aSmrg# expanded when the contents are evaled.
16051a9c160aSmrgusage='$progpath [OPTION]...'
16061a9c160aSmrg
16071a9c160aSmrg# Short help message in response to '-h' and '--help'.  Add to this or
16081a9c160aSmrg# override it after sourcing this library to reflect the full set of
16091a9c160aSmrg# options your script accepts.
16101a9c160aSmrgusage_message="\
16111a9c160aSmrg       --debug        enable verbose shell tracing
16121a9c160aSmrg   -W, --warnings=CATEGORY
16131a9c160aSmrg                      report the warnings falling in CATEGORY [all]
16141a9c160aSmrg   -v, --verbose      verbosely report processing
16151a9c160aSmrg       --version      print version information and exit
16161a9c160aSmrg   -h, --help         print short or long help message and exit
16171a9c160aSmrg"
16181a9c160aSmrg
16191a9c160aSmrg# Additional text appended to 'usage_message' in response to '--help'.
16201a9c160aSmrglong_help_message="
16211a9c160aSmrgWarning categories include:
16221a9c160aSmrg       'all'          show all warnings
16231a9c160aSmrg       'none'         turn off all the warnings
16241a9c160aSmrg       'error'        warnings are treated as fatal errors"
16251a9c160aSmrg
16261a9c160aSmrg# Help message printed before fatal option parsing errors.
16271a9c160aSmrgfatal_help="Try '\$progname --help' for more information."
16281a9c160aSmrg
16291a9c160aSmrg
16301a9c160aSmrg
16311a9c160aSmrg## ------------------------- ##
16321a9c160aSmrg## Hook function management. ##
16331a9c160aSmrg## ------------------------- ##
16341a9c160aSmrg
16351a9c160aSmrg# This section contains functions for adding, removing, and running hooks
1636621f50c3Smrg# in the main code.  A hook is just a list of function names that can be
1637621f50c3Smrg# run in order later on.
16381a9c160aSmrg
16391a9c160aSmrg# func_hookable FUNC_NAME
16401a9c160aSmrg# -----------------------
16411a9c160aSmrg# Declare that FUNC_NAME will run hooks added with
16421a9c160aSmrg# 'func_add_hook FUNC_NAME ...'.
16431a9c160aSmrgfunc_hookable ()
16441a9c160aSmrg{
16451a9c160aSmrg    $debug_cmd
16461a9c160aSmrg
16471a9c160aSmrg    func_append hookable_fns " $1"
16481a9c160aSmrg}
16491a9c160aSmrg
16501a9c160aSmrg
16511a9c160aSmrg# func_add_hook FUNC_NAME HOOK_FUNC
16521a9c160aSmrg# ---------------------------------
16531a9c160aSmrg# Request that FUNC_NAME call HOOK_FUNC before it returns.  FUNC_NAME must
16541a9c160aSmrg# first have been declared "hookable" by a call to 'func_hookable'.
16551a9c160aSmrgfunc_add_hook ()
16561a9c160aSmrg{
16571a9c160aSmrg    $debug_cmd
16581a9c160aSmrg
16591a9c160aSmrg    case " $hookable_fns " in
16601a9c160aSmrg      *" $1 "*) ;;
16611a9c160aSmrg      *) func_fatal_error "'$1' does not accept hook functions." ;;
16621a9c160aSmrg    esac
16631a9c160aSmrg
16641a9c160aSmrg    eval func_append ${1}_hooks '" $2"'
16651a9c160aSmrg}
16661a9c160aSmrg
16671a9c160aSmrg
16681a9c160aSmrg# func_remove_hook FUNC_NAME HOOK_FUNC
16691a9c160aSmrg# ------------------------------------
1670621f50c3Smrg# Remove HOOK_FUNC from the list of hook functions to be called by
1671621f50c3Smrg# FUNC_NAME.
16721a9c160aSmrgfunc_remove_hook ()
16731a9c160aSmrg{
16741a9c160aSmrg    $debug_cmd
16751a9c160aSmrg
16761a9c160aSmrg    eval ${1}_hooks='`$ECHO "\$'$1'_hooks" |$SED "s| '$2'||"`'
16771a9c160aSmrg}
16781a9c160aSmrg
16791a9c160aSmrg
1680621f50c3Smrg# func_propagate_result FUNC_NAME_A FUNC_NAME_B
1681621f50c3Smrg# ---------------------------------------------
1682621f50c3Smrg# If the *_result variable of FUNC_NAME_A _is set_, assign its value to
1683621f50c3Smrg# *_result variable of FUNC_NAME_B.
1684621f50c3Smrgfunc_propagate_result ()
1685621f50c3Smrg{
1686621f50c3Smrg    $debug_cmd
1687621f50c3Smrg
1688621f50c3Smrg    func_propagate_result_result=:
1689621f50c3Smrg    if eval "test \"\${${1}_result+set}\" = set"
1690621f50c3Smrg    then
1691621f50c3Smrg      eval "${2}_result=\$${1}_result"
1692621f50c3Smrg    else
1693621f50c3Smrg      func_propagate_result_result=false
1694621f50c3Smrg    fi
1695621f50c3Smrg}
1696621f50c3Smrg
1697621f50c3Smrg
16981a9c160aSmrg# func_run_hooks FUNC_NAME [ARG]...
16991a9c160aSmrg# ---------------------------------
17001a9c160aSmrg# Run all hook functions registered to FUNC_NAME.
1701621f50c3Smrg# It's assumed that the list of hook functions contains nothing more
17021a9c160aSmrg# than a whitespace-delimited list of legal shell function names, and
17031a9c160aSmrg# no effort is wasted trying to catch shell meta-characters or preserve
17041a9c160aSmrg# whitespace.
17051a9c160aSmrgfunc_run_hooks ()
17061a9c160aSmrg{
17071a9c160aSmrg    $debug_cmd
17081a9c160aSmrg
17091a9c160aSmrg    case " $hookable_fns " in
17101a9c160aSmrg      *" $1 "*) ;;
1711621f50c3Smrg      *) func_fatal_error "'$1' does not support hook functions." ;;
17121a9c160aSmrg    esac
17131a9c160aSmrg
17141a9c160aSmrg    eval _G_hook_fns=\$$1_hooks; shift
17151a9c160aSmrg
17161a9c160aSmrg    for _G_hook in $_G_hook_fns; do
1717621f50c3Smrg      func_unset "${_G_hook}_result"
1718621f50c3Smrg      eval $_G_hook '${1+"$@"}'
1719621f50c3Smrg      func_propagate_result $_G_hook func_run_hooks
1720621f50c3Smrg      if $func_propagate_result_result; then
1721621f50c3Smrg        eval set dummy "$func_run_hooks_result"; shift
1722621f50c3Smrg      fi
17231a9c160aSmrg    done
17241a9c160aSmrg}
17251a9c160aSmrg
17261a9c160aSmrg
17271a9c160aSmrg
17281a9c160aSmrg## --------------- ##
17291a9c160aSmrg## Option parsing. ##
17301a9c160aSmrg## --------------- ##
17311a9c160aSmrg
17321a9c160aSmrg# In order to add your own option parsing hooks, you must accept the
1733621f50c3Smrg# full positional parameter list from your hook function.  You may remove
1734621f50c3Smrg# or edit any options that you action, and then pass back the remaining
1735621f50c3Smrg# unprocessed options in '<hooked_function_name>_result', escaped
1736621f50c3Smrg# suitably for 'eval'.
1737621f50c3Smrg#
1738621f50c3Smrg# The '<hooked_function_name>_result' variable is automatically unset
1739621f50c3Smrg# before your hook gets called; for best performance, only set the
1740621f50c3Smrg# *_result variable when necessary (i.e. don't call the 'func_quote'
1741621f50c3Smrg# function unnecessarily because it can be an expensive operation on some
1742621f50c3Smrg# machines).
1743621f50c3Smrg#
1744621f50c3Smrg# Like this:
17451a9c160aSmrg#
17461a9c160aSmrg#    my_options_prep ()
17471a9c160aSmrg#    {
17481a9c160aSmrg#        $debug_cmd
17491a9c160aSmrg#
17501a9c160aSmrg#        # Extend the existing usage message.
17511a9c160aSmrg#        usage_message=$usage_message'
17521a9c160aSmrg#      -s, --silent       don'\''t print informational messages
17531a9c160aSmrg#    '
1754621f50c3Smrg#        # No change in '$@' (ignored completely by this hook).  Leave
1755621f50c3Smrg#        # my_options_prep_result variable intact.
17561a9c160aSmrg#    }
17571a9c160aSmrg#    func_add_hook func_options_prep my_options_prep
17581a9c160aSmrg#
17591a9c160aSmrg#
17601a9c160aSmrg#    my_silent_option ()
17611a9c160aSmrg#    {
17621a9c160aSmrg#        $debug_cmd
17631a9c160aSmrg#
1764621f50c3Smrg#        args_changed=false
1765621f50c3Smrg#
1766621f50c3Smrg#        # Note that, for efficiency, we parse as many options as we can
17671a9c160aSmrg#        # recognise in a loop before passing the remainder back to the
17681a9c160aSmrg#        # caller on the first unrecognised argument we encounter.
17691a9c160aSmrg#        while test $# -gt 0; do
17701a9c160aSmrg#          opt=$1; shift
17711a9c160aSmrg#          case $opt in
1772621f50c3Smrg#            --silent|-s) opt_silent=:
1773621f50c3Smrg#                         args_changed=:
1774621f50c3Smrg#                         ;;
17751a9c160aSmrg#            # Separate non-argument short options:
17761a9c160aSmrg#            -s*)         func_split_short_opt "$_G_opt"
17771a9c160aSmrg#                         set dummy "$func_split_short_opt_name" \
17781a9c160aSmrg#                             "-$func_split_short_opt_arg" ${1+"$@"}
17791a9c160aSmrg#                         shift
1780621f50c3Smrg#                         args_changed=:
17811a9c160aSmrg#                         ;;
1782621f50c3Smrg#            *)           # Make sure the first unrecognised option "$_G_opt"
1783621f50c3Smrg#                         # is added back to "$@" in case we need it later,
1784621f50c3Smrg#                         # if $args_changed was set to 'true'.
1785621f50c3Smrg#                         set dummy "$_G_opt" ${1+"$@"}; shift; break ;;
17861a9c160aSmrg#          esac
17871a9c160aSmrg#        done
17881a9c160aSmrg#
1789621f50c3Smrg#        # Only call 'func_quote' here if we processed at least one argument.
1790621f50c3Smrg#        if $args_changed; then
1791621f50c3Smrg#          func_quote eval ${1+"$@"}
1792621f50c3Smrg#          my_silent_option_result=$func_quote_result
1793621f50c3Smrg#        fi
17941a9c160aSmrg#    }
17951a9c160aSmrg#    func_add_hook func_parse_options my_silent_option
17961a9c160aSmrg#
17971a9c160aSmrg#
17981a9c160aSmrg#    my_option_validation ()
17991a9c160aSmrg#    {
18001a9c160aSmrg#        $debug_cmd
18011a9c160aSmrg#
18021a9c160aSmrg#        $opt_silent && $opt_verbose && func_fatal_help "\
18031a9c160aSmrg#    '--silent' and '--verbose' options are mutually exclusive."
18041a9c160aSmrg#    }
18051a9c160aSmrg#    func_add_hook func_validate_options my_option_validation
18061a9c160aSmrg#
1807621f50c3Smrg# You'll also need to manually amend $usage_message to reflect the extra
18081a9c160aSmrg# options you parse.  It's preferable to append if you can, so that
18091a9c160aSmrg# multiple option parsing hooks can be added safely.
18101a9c160aSmrg
18111a9c160aSmrg
1812621f50c3Smrg# func_options_finish [ARG]...
1813621f50c3Smrg# ----------------------------
1814621f50c3Smrg# Finishing the option parse loop (call 'func_options' hooks ATM).
1815621f50c3Smrgfunc_options_finish ()
1816621f50c3Smrg{
1817621f50c3Smrg    $debug_cmd
1818621f50c3Smrg
1819621f50c3Smrg    func_run_hooks func_options ${1+"$@"}
1820621f50c3Smrg    func_propagate_result func_run_hooks func_options_finish
1821621f50c3Smrg}
1822621f50c3Smrg
1823621f50c3Smrg
18241a9c160aSmrg# func_options [ARG]...
18251a9c160aSmrg# ---------------------
18261a9c160aSmrg# All the functions called inside func_options are hookable. See the
18271a9c160aSmrg# individual implementations for details.
18281a9c160aSmrgfunc_hookable func_options
18291a9c160aSmrgfunc_options ()
18301a9c160aSmrg{
18311a9c160aSmrg    $debug_cmd
18321a9c160aSmrg
1833621f50c3Smrg    _G_options_quoted=false
18341a9c160aSmrg
1835621f50c3Smrg    for my_func in options_prep parse_options validate_options options_finish
1836621f50c3Smrg    do
1837621f50c3Smrg      func_unset func_${my_func}_result
1838621f50c3Smrg      func_unset func_run_hooks_result
1839621f50c3Smrg      eval func_$my_func '${1+"$@"}'
1840621f50c3Smrg      func_propagate_result func_$my_func func_options
1841621f50c3Smrg      if $func_propagate_result_result; then
1842621f50c3Smrg        eval set dummy "$func_options_result"; shift
1843621f50c3Smrg        _G_options_quoted=:
1844621f50c3Smrg      fi
1845621f50c3Smrg    done
18461a9c160aSmrg
1847621f50c3Smrg    $_G_options_quoted || {
1848621f50c3Smrg      # As we (func_options) are top-level options-parser function and
1849621f50c3Smrg      # nobody quoted "$@" for us yet, we need to do it explicitly for
1850621f50c3Smrg      # caller.
1851621f50c3Smrg      func_quote eval ${1+"$@"}
1852621f50c3Smrg      func_options_result=$func_quote_result
1853621f50c3Smrg    }
18543eed67faSmbalmer}
18553eed67faSmbalmer
18563eed67faSmbalmer
18571a9c160aSmrg# func_options_prep [ARG]...
18581a9c160aSmrg# --------------------------
18591a9c160aSmrg# All initialisations required before starting the option parse loop.
18601a9c160aSmrg# Note that when calling hook functions, we pass through the list of
18611a9c160aSmrg# positional parameters.  If a hook function modifies that list, and
1862621f50c3Smrg# needs to propagate that back to rest of this script, then the complete
1863621f50c3Smrg# modified list must be put in 'func_run_hooks_result' before returning.
18641a9c160aSmrgfunc_hookable func_options_prep
18651a9c160aSmrgfunc_options_prep ()
18663eed67faSmbalmer{
18671a9c160aSmrg    $debug_cmd
1868dc407927Smrg
18691a9c160aSmrg    # Option defaults:
18701a9c160aSmrg    opt_verbose=false
18711a9c160aSmrg    opt_warning_types=
18721a9c160aSmrg
18731a9c160aSmrg    func_run_hooks func_options_prep ${1+"$@"}
1874621f50c3Smrg    func_propagate_result func_run_hooks func_options_prep
18753eed67faSmbalmer}
18763eed67faSmbalmer
18773eed67faSmbalmer
18781a9c160aSmrg# func_parse_options [ARG]...
18791a9c160aSmrg# ---------------------------
18801a9c160aSmrg# The main option parsing loop.
18811a9c160aSmrgfunc_hookable func_parse_options
18821a9c160aSmrgfunc_parse_options ()
18833eed67faSmbalmer{
18841a9c160aSmrg    $debug_cmd
1885dc407927Smrg
1886621f50c3Smrg    _G_parse_options_requote=false
18871a9c160aSmrg    # this just eases exit handling
18881a9c160aSmrg    while test $# -gt 0; do
18891a9c160aSmrg      # Defer to hook functions for initial option parsing, so they
18901a9c160aSmrg      # get priority in the event of reusing an option name.
18911a9c160aSmrg      func_run_hooks func_parse_options ${1+"$@"}
1892621f50c3Smrg      func_propagate_result func_run_hooks func_parse_options
1893621f50c3Smrg      if $func_propagate_result_result; then
1894621f50c3Smrg        eval set dummy "$func_parse_options_result"; shift
1895621f50c3Smrg        # Even though we may have changed "$@", we passed the "$@" array
1896621f50c3Smrg        # down into the hook and it quoted it for us (because we are in
1897621f50c3Smrg        # this if-branch).  No need to quote it again.
1898621f50c3Smrg        _G_parse_options_requote=false
1899621f50c3Smrg      fi
19003eed67faSmbalmer
19011a9c160aSmrg      # Break out of the loop if we already parsed every option.
19021a9c160aSmrg      test $# -gt 0 || break
19033eed67faSmbalmer
1904621f50c3Smrg      # We expect that one of the options parsed in this function matches
1905621f50c3Smrg      # and thus we remove _G_opt from "$@" and need to re-quote.
1906621f50c3Smrg      _G_match_parse_options=:
19071a9c160aSmrg      _G_opt=$1
19081a9c160aSmrg      shift
19091a9c160aSmrg      case $_G_opt in
19101a9c160aSmrg        --debug|-x)   debug_cmd='set -x'
1911621f50c3Smrg                      func_echo "enabling shell trace mode" >&2
19121a9c160aSmrg                      $debug_cmd
19131a9c160aSmrg                      ;;
19141a9c160aSmrg
19151a9c160aSmrg        --no-warnings|--no-warning|--no-warn)
19161a9c160aSmrg                      set dummy --warnings none ${1+"$@"}
19171a9c160aSmrg                      shift
19181a9c160aSmrg		      ;;
1919dc407927Smrg
19201a9c160aSmrg        --warnings|--warning|-W)
1921621f50c3Smrg                      if test $# = 0 && func_missing_arg $_G_opt; then
1922621f50c3Smrg                        _G_parse_options_requote=:
1923621f50c3Smrg                        break
1924621f50c3Smrg                      fi
19251a9c160aSmrg                      case " $warning_categories $1" in
19261a9c160aSmrg                        *" $1 "*)
19271a9c160aSmrg                          # trailing space prevents matching last $1 above
19281a9c160aSmrg                          func_append_uniq opt_warning_types " $1"
19291a9c160aSmrg                          ;;
19301a9c160aSmrg                        *all)
19311a9c160aSmrg                          opt_warning_types=$warning_categories
19321a9c160aSmrg                          ;;
19331a9c160aSmrg                        *none)
19341a9c160aSmrg                          opt_warning_types=none
19351a9c160aSmrg                          warning_func=:
19361a9c160aSmrg                          ;;
19371a9c160aSmrg                        *error)
19381a9c160aSmrg                          opt_warning_types=$warning_categories
19391a9c160aSmrg                          warning_func=func_fatal_error
19401a9c160aSmrg                          ;;
19411a9c160aSmrg                        *)
19421a9c160aSmrg                          func_fatal_error \
19431a9c160aSmrg                             "unsupported warning category: '$1'"
19441a9c160aSmrg                          ;;
19451a9c160aSmrg                      esac
19461a9c160aSmrg                      shift
19471a9c160aSmrg                      ;;
19481a9c160aSmrg
19491a9c160aSmrg        --verbose|-v) opt_verbose=: ;;
19501a9c160aSmrg        --version)    func_version ;;
19511a9c160aSmrg        -\?|-h)       func_usage ;;
19521a9c160aSmrg        --help)       func_help ;;
19531a9c160aSmrg
19541a9c160aSmrg	# Separate optargs to long options (plugins may need this):
19551a9c160aSmrg	--*=*)        func_split_equals "$_G_opt"
19561a9c160aSmrg	              set dummy "$func_split_equals_lhs" \
19571a9c160aSmrg                          "$func_split_equals_rhs" ${1+"$@"}
19581a9c160aSmrg                      shift
19591a9c160aSmrg                      ;;
19601a9c160aSmrg
19611a9c160aSmrg       # Separate optargs to short options:
19621a9c160aSmrg        -W*)
19631a9c160aSmrg                      func_split_short_opt "$_G_opt"
19641a9c160aSmrg                      set dummy "$func_split_short_opt_name" \
19651a9c160aSmrg                          "$func_split_short_opt_arg" ${1+"$@"}
19661a9c160aSmrg                      shift
19671a9c160aSmrg                      ;;
19681a9c160aSmrg
19691a9c160aSmrg        # Separate non-argument short options:
19701a9c160aSmrg        -\?*|-h*|-v*|-x*)
19711a9c160aSmrg                      func_split_short_opt "$_G_opt"
19721a9c160aSmrg                      set dummy "$func_split_short_opt_name" \
19731a9c160aSmrg                          "-$func_split_short_opt_arg" ${1+"$@"}
19741a9c160aSmrg                      shift
19751a9c160aSmrg                      ;;
19761a9c160aSmrg
1977621f50c3Smrg        --)           _G_parse_options_requote=: ; break ;;
19781a9c160aSmrg        -*)           func_fatal_help "unrecognised option: '$_G_opt'" ;;
1979621f50c3Smrg        *)            set dummy "$_G_opt" ${1+"$@"}; shift
1980621f50c3Smrg                      _G_match_parse_options=false
1981621f50c3Smrg                      break
1982621f50c3Smrg                      ;;
19831a9c160aSmrg      esac
1984621f50c3Smrg
1985621f50c3Smrg      if $_G_match_parse_options; then
1986621f50c3Smrg        _G_parse_options_requote=:
1987621f50c3Smrg      fi
19881a9c160aSmrg    done
19891a9c160aSmrg
1990621f50c3Smrg    if $_G_parse_options_requote; then
1991621f50c3Smrg      # save modified positional parameters for caller
1992621f50c3Smrg      func_quote eval ${1+"$@"}
1993621f50c3Smrg      func_parse_options_result=$func_quote_result
1994621f50c3Smrg    fi
19953eed67faSmbalmer}
19963eed67faSmbalmer
1997dc407927Smrg
19981a9c160aSmrg# func_validate_options [ARG]...
19991a9c160aSmrg# ------------------------------
20001a9c160aSmrg# Perform any sanity checks on option settings and/or unconsumed
20011a9c160aSmrg# arguments.
20021a9c160aSmrgfunc_hookable func_validate_options
20031a9c160aSmrgfunc_validate_options ()
20043eed67faSmbalmer{
20051a9c160aSmrg    $debug_cmd
2006dc407927Smrg
20071a9c160aSmrg    # Display all warnings if -W was not given.
20081a9c160aSmrg    test -n "$opt_warning_types" || opt_warning_types=" $warning_categories"
2009dc407927Smrg
20101a9c160aSmrg    func_run_hooks func_validate_options ${1+"$@"}
2011621f50c3Smrg    func_propagate_result func_run_hooks func_validate_options
20123eed67faSmbalmer
20131a9c160aSmrg    # Bail if the options were screwed!
20141a9c160aSmrg    $exit_cmd $EXIT_FAILURE
2015dd0822caSmrg}
2016dc407927Smrg
2017dc407927Smrg
2018dd0822caSmrg
20191a9c160aSmrg## ----------------- ##
20201a9c160aSmrg## Helper functions. ##
20211a9c160aSmrg## ----------------- ##
2022dc407927Smrg
20231a9c160aSmrg# This section contains the helper functions used by the rest of the
20241a9c160aSmrg# hookable option parser framework in ascii-betical order.
20251a9c160aSmrg
20261a9c160aSmrg
20271a9c160aSmrg# func_fatal_help ARG...
20281a9c160aSmrg# ----------------------
20291a9c160aSmrg# Echo program name prefixed message to standard error, followed by
20301a9c160aSmrg# a help hint, and exit.
20311a9c160aSmrgfunc_fatal_help ()
2032dc407927Smrg{
20331a9c160aSmrg    $debug_cmd
2034dd0822caSmrg
20351a9c160aSmrg    eval \$ECHO \""Usage: $usage"\"
20361a9c160aSmrg    eval \$ECHO \""$fatal_help"\"
20371a9c160aSmrg    func_error ${1+"$@"}
20381a9c160aSmrg    exit $EXIT_FAILURE
2039dc407927Smrg}
2040dc407927Smrg
20411a9c160aSmrg
20421a9c160aSmrg# func_help
20431a9c160aSmrg# ---------
20441a9c160aSmrg# Echo long help message to standard output and exit.
2045dc407927Smrgfunc_help ()
2046dc407927Smrg{
20471a9c160aSmrg    $debug_cmd
20481a9c160aSmrg
20491a9c160aSmrg    func_usage_message
20501a9c160aSmrg    $ECHO "$long_help_message"
20511a9c160aSmrg    exit 0
2052dc407927Smrg}
2053dc407927Smrg
20541a9c160aSmrg
20551a9c160aSmrg# func_missing_arg ARGNAME
20561a9c160aSmrg# ------------------------
2057dc407927Smrg# Echo program name prefixed message to standard error and set global
2058dc407927Smrg# exit_cmd.
2059dc407927Smrgfunc_missing_arg ()
2060dc407927Smrg{
20611a9c160aSmrg    $debug_cmd
2062dd0822caSmrg
20631a9c160aSmrg    func_error "Missing argument for '$1'."
2064dc407927Smrg    exit_cmd=exit
20653eed67faSmbalmer}
20663eed67faSmbalmer
20673eed67faSmbalmer
20681a9c160aSmrg# func_split_equals STRING
20691a9c160aSmrg# ------------------------
2070621f50c3Smrg# Set func_split_equals_lhs and func_split_equals_rhs shell variables
2071621f50c3Smrg# after splitting STRING at the '=' sign.
20721a9c160aSmrgtest -z "$_G_HAVE_XSI_OPS" \
20731a9c160aSmrg    && (eval 'x=a/b/c;
20741a9c160aSmrg      test 5aa/bb/cc = "${#x}${x%%/*}${x%/*}${x#*/}${x##*/}"') 2>/dev/null \
20751a9c160aSmrg    && _G_HAVE_XSI_OPS=yes
20761a9c160aSmrg
20771a9c160aSmrgif test yes = "$_G_HAVE_XSI_OPS"
20781a9c160aSmrgthen
20791a9c160aSmrg  # This is an XSI compatible shell, allowing a faster implementation...
20801a9c160aSmrg  eval 'func_split_equals ()
20811a9c160aSmrg  {
20821a9c160aSmrg      $debug_cmd
20831a9c160aSmrg
20841a9c160aSmrg      func_split_equals_lhs=${1%%=*}
20851a9c160aSmrg      func_split_equals_rhs=${1#*=}
2086621f50c3Smrg      if test "x$func_split_equals_lhs" = "x$1"; then
2087621f50c3Smrg        func_split_equals_rhs=
2088621f50c3Smrg      fi
20891a9c160aSmrg  }'
20901a9c160aSmrgelse
20911a9c160aSmrg  # ...otherwise fall back to using expr, which is often a shell builtin.
20921a9c160aSmrg  func_split_equals ()
20931a9c160aSmrg  {
20941a9c160aSmrg      $debug_cmd
20951a9c160aSmrg
20961a9c160aSmrg      func_split_equals_lhs=`expr "x$1" : 'x\([^=]*\)'`
20971a9c160aSmrg      func_split_equals_rhs=
2098621f50c3Smrg      test "x$func_split_equals_lhs=" = "x$1" \
20991a9c160aSmrg        || func_split_equals_rhs=`expr "x$1" : 'x[^=]*=\(.*\)$'`
21001a9c160aSmrg  }
21011a9c160aSmrgfi #func_split_equals
21021a9c160aSmrg
21031a9c160aSmrg
21041a9c160aSmrg# func_split_short_opt SHORTOPT
21051a9c160aSmrg# -----------------------------
2106dd0822caSmrg# Set func_split_short_opt_name and func_split_short_opt_arg shell
2107dd0822caSmrg# variables after splitting SHORTOPT after the 2nd character.
21081a9c160aSmrgif test yes = "$_G_HAVE_XSI_OPS"
21091a9c160aSmrgthen
21101a9c160aSmrg  # This is an XSI compatible shell, allowing a faster implementation...
21111a9c160aSmrg  eval 'func_split_short_opt ()
21121a9c160aSmrg  {
21131a9c160aSmrg      $debug_cmd
21141a9c160aSmrg
21151a9c160aSmrg      func_split_short_opt_arg=${1#??}
21161a9c160aSmrg      func_split_short_opt_name=${1%"$func_split_short_opt_arg"}
21171a9c160aSmrg  }'
21181a9c160aSmrgelse
21191a9c160aSmrg  # ...otherwise fall back to using expr, which is often a shell builtin.
21201a9c160aSmrg  func_split_short_opt ()
21211a9c160aSmrg  {
21221a9c160aSmrg      $debug_cmd
21231a9c160aSmrg
2124621f50c3Smrg      func_split_short_opt_name=`expr "x$1" : 'x\(-.\)'`
21251a9c160aSmrg      func_split_short_opt_arg=`expr "x$1" : 'x-.\(.*\)$'`
21261a9c160aSmrg  }
21271a9c160aSmrgfi #func_split_short_opt
21281a9c160aSmrg
21291a9c160aSmrg
21301a9c160aSmrg# func_usage
21311a9c160aSmrg# ----------
21321a9c160aSmrg# Echo short help message to standard output and exit.
21331a9c160aSmrgfunc_usage ()
2134dd0822caSmrg{
21351a9c160aSmrg    $debug_cmd
21363eed67faSmbalmer
21371a9c160aSmrg    func_usage_message
21381a9c160aSmrg    $ECHO "Run '$progname --help |${PAGER-more}' for full usage"
21391a9c160aSmrg    exit 0
21401a9c160aSmrg}
2141dd0822caSmrg
2142dd0822caSmrg
21431a9c160aSmrg# func_usage_message
21441a9c160aSmrg# ------------------
21451a9c160aSmrg# Echo short help message to standard output.
21461a9c160aSmrgfunc_usage_message ()
2147dd0822caSmrg{
21481a9c160aSmrg    $debug_cmd
2149dd0822caSmrg
21501a9c160aSmrg    eval \$ECHO \""Usage: $usage"\"
21511a9c160aSmrg    echo
21521a9c160aSmrg    $SED -n 's|^# ||
21531a9c160aSmrg        /^Written by/{
21541a9c160aSmrg          x;p;x
21551a9c160aSmrg        }
21561a9c160aSmrg	h
21571a9c160aSmrg	/^Written by/q' < "$progpath"
21581a9c160aSmrg    echo
21591a9c160aSmrg    eval \$ECHO \""$usage_message"\"
21601a9c160aSmrg}
2161dd0822caSmrg
2162dc407927Smrg
21631a9c160aSmrg# func_version
21641a9c160aSmrg# ------------
21651a9c160aSmrg# Echo version message to standard output and exit.
2166621f50c3Smrg# The version message is extracted from the calling file's header
2167621f50c3Smrg# comments, with leading '# ' stripped:
2168621f50c3Smrg#   1. First display the progname and version
2169621f50c3Smrg#   2. Followed by the header comment line matching  /^# Written by /
2170621f50c3Smrg#   3. Then a blank line followed by the first following line matching
2171621f50c3Smrg#      /^# Copyright /
2172621f50c3Smrg#   4. Immediately followed by any lines between the previous matches,
2173621f50c3Smrg#      except lines preceding the intervening completely blank line.
2174621f50c3Smrg# For example, see the header comments of this file.
21751a9c160aSmrgfunc_version ()
21761a9c160aSmrg{
21771a9c160aSmrg    $debug_cmd
2178dc407927Smrg
21791a9c160aSmrg    printf '%s\n' "$progname $scriptversion"
21801a9c160aSmrg    $SED -n '
2181621f50c3Smrg        /^# Written by /!b
2182621f50c3Smrg        s|^# ||; p; n
2183621f50c3Smrg
2184621f50c3Smrg        :fwd2blnk
2185621f50c3Smrg        /./ {
2186621f50c3Smrg          n
2187621f50c3Smrg          b fwd2blnk
21881a9c160aSmrg        }
2189621f50c3Smrg        p; n
2190621f50c3Smrg
2191621f50c3Smrg        :holdwrnt
2192621f50c3Smrg        s|^# ||
2193621f50c3Smrg        s|^# *$||
2194621f50c3Smrg        /^Copyright /!{
2195621f50c3Smrg          /./H
2196621f50c3Smrg          n
2197621f50c3Smrg          b holdwrnt
21981a9c160aSmrg        }
2199621f50c3Smrg
2200621f50c3Smrg        s|\((C)\)[ 0-9,-]*[ ,-]\([1-9][0-9]* \)|\1 \2|
2201621f50c3Smrg        G
2202621f50c3Smrg        s|\(\n\)\n*|\1|g
2203621f50c3Smrg        p; q' < "$progpath"
2204dc407927Smrg
22051a9c160aSmrg    exit $?
22061a9c160aSmrg}
22073eed67faSmbalmer
22083eed67faSmbalmer
22091a9c160aSmrg# Local variables:
22101a9c160aSmrg# mode: shell-script
22111a9c160aSmrg# sh-indentation: 2
22121a9c160aSmrg# eval: (add-hook 'before-save-hook 'time-stamp)
2213621f50c3Smrg# time-stamp-pattern: "30/scriptversion=%:y-%02m-%02d.%02H; # UTC"
22141a9c160aSmrg# time-stamp-time-zone: "UTC"
22151a9c160aSmrg# End:
22163eed67faSmbalmer
22171a9c160aSmrg# Set a version string.
2218621f50c3Smrgscriptversion='(GNU libtool) 2.4.7'
22193eed67faSmbalmer
2220dc407927Smrg
22211a9c160aSmrg# func_echo ARG...
22221a9c160aSmrg# ----------------
22231a9c160aSmrg# Libtool also displays the current mode in messages, so override
22241a9c160aSmrg# funclib.sh func_echo with this custom definition.
22251a9c160aSmrgfunc_echo ()
2226dd0822caSmrg{
22271a9c160aSmrg    $debug_cmd
2228dd0822caSmrg
22291a9c160aSmrg    _G_message=$*
2230dd0822caSmrg
22311a9c160aSmrg    func_echo_IFS=$IFS
22321a9c160aSmrg    IFS=$nl
22331a9c160aSmrg    for _G_line in $_G_message; do
22341a9c160aSmrg      IFS=$func_echo_IFS
22351a9c160aSmrg      $ECHO "$progname${opt_mode+: $opt_mode}: $_G_line"
22361a9c160aSmrg    done
22371a9c160aSmrg    IFS=$func_echo_IFS
22381a9c160aSmrg}
2239dd0822caSmrg
22401a9c160aSmrg
22411a9c160aSmrg# func_warning ARG...
22421a9c160aSmrg# -------------------
22431a9c160aSmrg# Libtool warnings are not categorized, so override funclib.sh
22441a9c160aSmrg# func_warning with this simpler definition.
22451a9c160aSmrgfunc_warning ()
2246dd0822caSmrg{
22471a9c160aSmrg    $debug_cmd
2248dd0822caSmrg
22491a9c160aSmrg    $warning_func ${1+"$@"}
22501a9c160aSmrg}
2251dd0822caSmrg
2252dd0822caSmrg
22531a9c160aSmrg## ---------------- ##
22541a9c160aSmrg## Options parsing. ##
22551a9c160aSmrg## ---------------- ##
22561a9c160aSmrg
22571a9c160aSmrg# Hook in the functions to make sure our own options are parsed during
22581a9c160aSmrg# the option parsing loop.
22591a9c160aSmrg
22601a9c160aSmrgusage='$progpath [OPTION]... [MODE-ARG]...'
22611a9c160aSmrg
22621a9c160aSmrg# Short help message in response to '-h'.
22631a9c160aSmrgusage_message="Options:
22641a9c160aSmrg       --config             show all configuration variables
22651a9c160aSmrg       --debug              enable verbose shell tracing
22661a9c160aSmrg   -n, --dry-run            display commands without modifying any files
22671a9c160aSmrg       --features           display basic configuration information and exit
22681a9c160aSmrg       --mode=MODE          use operation mode MODE
22691a9c160aSmrg       --no-warnings        equivalent to '-Wnone'
22701a9c160aSmrg       --preserve-dup-deps  don't remove duplicate dependency libraries
22711a9c160aSmrg       --quiet, --silent    don't print informational messages
22721a9c160aSmrg       --tag=TAG            use configuration variables from tag TAG
22731a9c160aSmrg   -v, --verbose            print more informational messages than default
22741a9c160aSmrg       --version            print version information
22751a9c160aSmrg   -W, --warnings=CATEGORY  report the warnings falling in CATEGORY [all]
22761a9c160aSmrg   -h, --help, --help-all   print short, long, or detailed help message
22771a9c160aSmrg"
2278dd0822caSmrg
22791a9c160aSmrg# Additional text appended to 'usage_message' in response to '--help'.
22801a9c160aSmrgfunc_help ()
2281dd0822caSmrg{
22821a9c160aSmrg    $debug_cmd
22831a9c160aSmrg
22841a9c160aSmrg    func_usage_message
22851a9c160aSmrg    $ECHO "$long_help_message
22861a9c160aSmrg
22871a9c160aSmrgMODE must be one of the following:
22881a9c160aSmrg
22891a9c160aSmrg       clean           remove files from the build directory
22901a9c160aSmrg       compile         compile a source file into a libtool object
22911a9c160aSmrg       execute         automatically set library path, then run a program
22921a9c160aSmrg       finish          complete the installation of libtool libraries
22931a9c160aSmrg       install         install libraries or executables
22941a9c160aSmrg       link            create a library or an executable
22951a9c160aSmrg       uninstall       remove libraries from an installed directory
22961a9c160aSmrg
22971a9c160aSmrgMODE-ARGS vary depending on the MODE.  When passed as first option,
22981a9c160aSmrg'--mode=MODE' may be abbreviated as 'MODE' or a unique abbreviation of that.
22991a9c160aSmrgTry '$progname --help --mode=MODE' for a more detailed description of MODE.
23001a9c160aSmrg
23011a9c160aSmrgWhen reporting a bug, please describe a test case to reproduce it and
23021a9c160aSmrginclude the following information:
23031a9c160aSmrg
23041a9c160aSmrg       host-triplet:   $host
23051a9c160aSmrg       shell:          $SHELL
23061a9c160aSmrg       compiler:       $LTCC
23071a9c160aSmrg       compiler flags: $LTCFLAGS
23081a9c160aSmrg       linker:         $LD (gnu? $with_gnu_ld)
2309621f50c3Smrg       version:        $progname (GNU libtool) 2.4.7
23101a9c160aSmrg       automake:       `($AUTOMAKE --version) 2>/dev/null |$SED 1q`
23111a9c160aSmrg       autoconf:       `($AUTOCONF --version) 2>/dev/null |$SED 1q`
23121a9c160aSmrg
23131a9c160aSmrgReport bugs to <bug-libtool@gnu.org>.
23141a9c160aSmrgGNU libtool home page: <http://www.gnu.org/software/libtool/>.
23151a9c160aSmrgGeneral help using GNU software: <http://www.gnu.org/gethelp/>."
23161a9c160aSmrg    exit 0
23171a9c160aSmrg}
2318dd0822caSmrg
2319dd0822caSmrg
23201a9c160aSmrg# func_lo2o OBJECT-NAME
23211a9c160aSmrg# ---------------------
23221a9c160aSmrg# Transform OBJECT-NAME from a '.lo' suffix to the platform specific
23231a9c160aSmrg# object suffix.
23241a9c160aSmrg
23251a9c160aSmrglo2o=s/\\.lo\$/.$objext/
23261a9c160aSmrgo2lo=s/\\.$objext\$/.lo/
23271a9c160aSmrg
23281a9c160aSmrgif test yes = "$_G_HAVE_XSI_OPS"; then
23291a9c160aSmrg  eval 'func_lo2o ()
23301a9c160aSmrg  {
23311a9c160aSmrg    case $1 in
23321a9c160aSmrg      *.lo) func_lo2o_result=${1%.lo}.$objext ;;
23331a9c160aSmrg      *   ) func_lo2o_result=$1               ;;
23341a9c160aSmrg    esac
23351a9c160aSmrg  }'
23361a9c160aSmrg
23371a9c160aSmrg  # func_xform LIBOBJ-OR-SOURCE
23381a9c160aSmrg  # ---------------------------
23391a9c160aSmrg  # Transform LIBOBJ-OR-SOURCE from a '.o' or '.c' (or otherwise)
23401a9c160aSmrg  # suffix to a '.lo' libtool-object suffix.
23411a9c160aSmrg  eval 'func_xform ()
23421a9c160aSmrg  {
23431a9c160aSmrg    func_xform_result=${1%.*}.lo
23441a9c160aSmrg  }'
23451a9c160aSmrgelse
23461a9c160aSmrg  # ...otherwise fall back to using sed.
23471a9c160aSmrg  func_lo2o ()
23481a9c160aSmrg  {
23491a9c160aSmrg    func_lo2o_result=`$ECHO "$1" | $SED "$lo2o"`
23501a9c160aSmrg  }
23511a9c160aSmrg
23521a9c160aSmrg  func_xform ()
23531a9c160aSmrg  {
23541a9c160aSmrg    func_xform_result=`$ECHO "$1" | $SED 's|\.[^.]*$|.lo|'`
23551a9c160aSmrg  }
23561a9c160aSmrgfi
2357dd0822caSmrg
2358dd0822caSmrg
23591a9c160aSmrg# func_fatal_configuration ARG...
23601a9c160aSmrg# -------------------------------
2361dc407927Smrg# Echo program name prefixed message to standard error, followed by
2362dc407927Smrg# a configuration failure hint, and exit.
2363dc407927Smrgfunc_fatal_configuration ()
2364dc407927Smrg{
2365621f50c3Smrg    func_fatal_error ${1+"$@"} \
23661a9c160aSmrg      "See the $PACKAGE documentation for more information." \
23671a9c160aSmrg      "Fatal configuration error."
2368dc407927Smrg}
23693eed67faSmbalmer
23703eed67faSmbalmer
2371dc407927Smrg# func_config
23721a9c160aSmrg# -----------
2373dc407927Smrg# Display the configuration for all the tags in this script.
2374dc407927Smrgfunc_config ()
2375dc407927Smrg{
2376dc407927Smrg    re_begincf='^# ### BEGIN LIBTOOL'
2377dc407927Smrg    re_endcf='^# ### END LIBTOOL'
2378dc407927Smrg
2379dc407927Smrg    # Default configuration.
2380dc407927Smrg    $SED "1,/$re_begincf CONFIG/d;/$re_endcf CONFIG/,\$d" < "$progpath"
23813eed67faSmbalmer
23823eed67faSmbalmer    # Now print the configurations for the tags.
23833eed67faSmbalmer    for tagname in $taglist; do
2384dc407927Smrg      $SED -n "/$re_begincf TAG CONFIG: $tagname\$/,/$re_endcf TAG CONFIG: $tagname\$/p" < "$progpath"
23853eed67faSmbalmer    done
23863eed67faSmbalmer
2387dc407927Smrg    exit $?
2388dc407927Smrg}
23893eed67faSmbalmer
23901a9c160aSmrg
2391dc407927Smrg# func_features
23921a9c160aSmrg# -------------
2393dc407927Smrg# Display the features supported by this script.
2394dc407927Smrgfunc_features ()
2395dc407927Smrg{
2396dd0822caSmrg    echo "host: $host"
23971a9c160aSmrg    if test yes = "$build_libtool_libs"; then
2398dd0822caSmrg      echo "enable shared libraries"
23993eed67faSmbalmer    else
2400dd0822caSmrg      echo "disable shared libraries"
24013eed67faSmbalmer    fi
24021a9c160aSmrg    if test yes = "$build_old_libs"; then
2403dd0822caSmrg      echo "enable static libraries"
24043eed67faSmbalmer    else
2405dd0822caSmrg      echo "disable static libraries"
24063eed67faSmbalmer    fi
2407dc407927Smrg
24083eed67faSmbalmer    exit $?
2409dc407927Smrg}
24103eed67faSmbalmer
24111a9c160aSmrg
24121a9c160aSmrg# func_enable_tag TAGNAME
24131a9c160aSmrg# -----------------------
2414dc407927Smrg# Verify that TAGNAME is valid, and either flag an error and exit, or
2415dc407927Smrg# enable the TAGNAME tag.  We also add TAGNAME to the global $taglist
2416dc407927Smrg# variable here.
2417dc407927Smrgfunc_enable_tag ()
2418dc407927Smrg{
24191a9c160aSmrg    # Global variable:
24201a9c160aSmrg    tagname=$1
24213eed67faSmbalmer
24221a9c160aSmrg    re_begincf="^# ### BEGIN LIBTOOL TAG CONFIG: $tagname\$"
24231a9c160aSmrg    re_endcf="^# ### END LIBTOOL TAG CONFIG: $tagname\$"
24241a9c160aSmrg    sed_extractcf=/$re_begincf/,/$re_endcf/p
24253eed67faSmbalmer
24261a9c160aSmrg    # Validate tagname.
24271a9c160aSmrg    case $tagname in
24281a9c160aSmrg      *[!-_A-Za-z0-9,/]*)
24291a9c160aSmrg        func_fatal_error "invalid tag name: $tagname"
24301a9c160aSmrg        ;;
24311a9c160aSmrg    esac
24323eed67faSmbalmer
24331a9c160aSmrg    # Don't test for the "default" C tag, as we know it's
24341a9c160aSmrg    # there but not specially marked.
24351a9c160aSmrg    case $tagname in
24361a9c160aSmrg        CC) ;;
2437dc407927Smrg    *)
24381a9c160aSmrg        if $GREP "$re_begincf" "$progpath" >/dev/null 2>&1; then
24391a9c160aSmrg	  taglist="$taglist $tagname"
24401a9c160aSmrg
24411a9c160aSmrg	  # Evaluate the configuration.  Be careful to quote the path
24421a9c160aSmrg	  # and the sed script, to avoid splitting on whitespace, but
24431a9c160aSmrg	  # also don't use non-portable quotes within backquotes within
24441a9c160aSmrg	  # quotes we have to do it in 2 steps:
24451a9c160aSmrg	  extractedcf=`$SED -n -e "$sed_extractcf" < "$progpath"`
24461a9c160aSmrg	  eval "$extractedcf"
24471a9c160aSmrg        else
24481a9c160aSmrg	  func_error "ignoring unknown tag $tagname"
24491a9c160aSmrg        fi
24501a9c160aSmrg        ;;
24511a9c160aSmrg    esac
2452dc407927Smrg}
2453dc407927Smrg
24541a9c160aSmrg
2455dd0822caSmrg# func_check_version_match
24561a9c160aSmrg# ------------------------
2457dd0822caSmrg# Ensure that we are using m4 macros, and libtool script from the same
2458dd0822caSmrg# release of libtool.
2459dd0822caSmrgfunc_check_version_match ()
2460dc407927Smrg{
24611a9c160aSmrg    if test "$package_revision" != "$macro_revision"; then
24621a9c160aSmrg      if test "$VERSION" != "$macro_version"; then
24631a9c160aSmrg        if test -z "$macro_version"; then
24641a9c160aSmrg          cat >&2 <<_LT_EOF
2465dd0822caSmrg$progname: Version mismatch error.  This is $PACKAGE $VERSION, but the
2466dd0822caSmrg$progname: definition of this LT_INIT comes from an older release.
2467dd0822caSmrg$progname: You should recreate aclocal.m4 with macros from $PACKAGE $VERSION
2468dd0822caSmrg$progname: and run autoconf again.
2469dd0822caSmrg_LT_EOF
24701a9c160aSmrg        else
24711a9c160aSmrg          cat >&2 <<_LT_EOF
2472dd0822caSmrg$progname: Version mismatch error.  This is $PACKAGE $VERSION, but the
2473dd0822caSmrg$progname: definition of this LT_INIT comes from $PACKAGE $macro_version.
2474dd0822caSmrg$progname: You should recreate aclocal.m4 with macros from $PACKAGE $VERSION
2475dd0822caSmrg$progname: and run autoconf again.
2476dd0822caSmrg_LT_EOF
24771a9c160aSmrg        fi
24781a9c160aSmrg      else
24791a9c160aSmrg        cat >&2 <<_LT_EOF
2480dd0822caSmrg$progname: Version mismatch error.  This is $PACKAGE $VERSION, revision $package_revision,
2481dd0822caSmrg$progname: but the definition of this LT_INIT comes from revision $macro_revision.
2482dd0822caSmrg$progname: You should recreate aclocal.m4 with macros from revision $package_revision
2483dd0822caSmrg$progname: of $PACKAGE $VERSION and run autoconf again.
2484dd0822caSmrg_LT_EOF
24851a9c160aSmrg      fi
24863eed67faSmbalmer
24871a9c160aSmrg      exit $EXIT_MISMATCH
24881a9c160aSmrg    fi
2489dd0822caSmrg}
2490dd0822caSmrg
2491dd0822caSmrg
24921a9c160aSmrg# libtool_options_prep [ARG]...
24931a9c160aSmrg# -----------------------------
24941a9c160aSmrg# Preparation for options parsed by libtool.
24951a9c160aSmrglibtool_options_prep ()
24961a9c160aSmrg{
24971a9c160aSmrg    $debug_mode
2498dd0822caSmrg
24991a9c160aSmrg    # Option defaults:
25001a9c160aSmrg    opt_config=false
25011a9c160aSmrg    opt_dlopen=
25021a9c160aSmrg    opt_dry_run=false
25031a9c160aSmrg    opt_help=false
25041a9c160aSmrg    opt_mode=
25051a9c160aSmrg    opt_preserve_dup_deps=false
25061a9c160aSmrg    opt_quiet=false
2507dd0822caSmrg
25081a9c160aSmrg    nonopt=
25091a9c160aSmrg    preserve_args=
2510dd0822caSmrg
2511621f50c3Smrg    _G_rc_lt_options_prep=:
2512621f50c3Smrg
25131a9c160aSmrg    # Shorthand for --mode=foo, only valid as the first argument
25141a9c160aSmrg    case $1 in
25151a9c160aSmrg    clean|clea|cle|cl)
25161a9c160aSmrg      shift; set dummy --mode clean ${1+"$@"}; shift
25171a9c160aSmrg      ;;
25181a9c160aSmrg    compile|compil|compi|comp|com|co|c)
25191a9c160aSmrg      shift; set dummy --mode compile ${1+"$@"}; shift
25201a9c160aSmrg      ;;
25211a9c160aSmrg    execute|execut|execu|exec|exe|ex|e)
25221a9c160aSmrg      shift; set dummy --mode execute ${1+"$@"}; shift
25231a9c160aSmrg      ;;
25241a9c160aSmrg    finish|finis|fini|fin|fi|f)
25251a9c160aSmrg      shift; set dummy --mode finish ${1+"$@"}; shift
25261a9c160aSmrg      ;;
25271a9c160aSmrg    install|instal|insta|inst|ins|in|i)
25281a9c160aSmrg      shift; set dummy --mode install ${1+"$@"}; shift
25291a9c160aSmrg      ;;
25301a9c160aSmrg    link|lin|li|l)
25311a9c160aSmrg      shift; set dummy --mode link ${1+"$@"}; shift
25321a9c160aSmrg      ;;
25331a9c160aSmrg    uninstall|uninstal|uninsta|uninst|unins|unin|uni|un|u)
25341a9c160aSmrg      shift; set dummy --mode uninstall ${1+"$@"}; shift
25351a9c160aSmrg      ;;
2536621f50c3Smrg    *)
2537621f50c3Smrg      _G_rc_lt_options_prep=false
2538621f50c3Smrg      ;;
25391a9c160aSmrg    esac
25401a9c160aSmrg
2541621f50c3Smrg    if $_G_rc_lt_options_prep; then
2542621f50c3Smrg      # Pass back the list of options.
2543621f50c3Smrg      func_quote eval ${1+"$@"}
2544621f50c3Smrg      libtool_options_prep_result=$func_quote_result
2545621f50c3Smrg    fi
25461a9c160aSmrg}
25471a9c160aSmrgfunc_add_hook func_options_prep libtool_options_prep
25483eed67faSmbalmer
2549dd0822caSmrg
25501a9c160aSmrg# libtool_parse_options [ARG]...
25511a9c160aSmrg# ---------------------------------
25521a9c160aSmrg# Provide handling for libtool specific options.
25531a9c160aSmrglibtool_parse_options ()
2554dd0822caSmrg{
25551a9c160aSmrg    $debug_cmd
2556dc407927Smrg
2557621f50c3Smrg    _G_rc_lt_parse_options=false
2558621f50c3Smrg
25591a9c160aSmrg    # Perform our own loop to consume as many options as possible in
25601a9c160aSmrg    # each iteration.
25611a9c160aSmrg    while test $# -gt 0; do
2562621f50c3Smrg      _G_match_lt_parse_options=:
25631a9c160aSmrg      _G_opt=$1
25641a9c160aSmrg      shift
25651a9c160aSmrg      case $_G_opt in
25661a9c160aSmrg        --dry-run|--dryrun|-n)
25671a9c160aSmrg                        opt_dry_run=:
25681a9c160aSmrg                        ;;
25691a9c160aSmrg
25701a9c160aSmrg        --config)       func_config ;;
25711a9c160aSmrg
25721a9c160aSmrg        --dlopen|-dlopen)
25731a9c160aSmrg                        opt_dlopen="${opt_dlopen+$opt_dlopen
25741a9c160aSmrg}$1"
25751a9c160aSmrg                        shift
25761a9c160aSmrg                        ;;
25771a9c160aSmrg
25781a9c160aSmrg        --preserve-dup-deps)
25791a9c160aSmrg                        opt_preserve_dup_deps=: ;;
25801a9c160aSmrg
25811a9c160aSmrg        --features)     func_features ;;
25821a9c160aSmrg
25831a9c160aSmrg        --finish)       set dummy --mode finish ${1+"$@"}; shift ;;
25841a9c160aSmrg
25851a9c160aSmrg        --help)         opt_help=: ;;
25861a9c160aSmrg
25871a9c160aSmrg        --help-all)     opt_help=': help-all' ;;
25881a9c160aSmrg
25891a9c160aSmrg        --mode)         test $# = 0 && func_missing_arg $_G_opt && break
25901a9c160aSmrg                        opt_mode=$1
25911a9c160aSmrg                        case $1 in
25921a9c160aSmrg                          # Valid mode arguments:
25931a9c160aSmrg                          clean|compile|execute|finish|install|link|relink|uninstall) ;;
25941a9c160aSmrg
25951a9c160aSmrg                          # Catch anything else as an error
25961a9c160aSmrg                          *) func_error "invalid argument for $_G_opt"
25971a9c160aSmrg                             exit_cmd=exit
25981a9c160aSmrg                             break
25991a9c160aSmrg                             ;;
26001a9c160aSmrg                        esac
26011a9c160aSmrg                        shift
26021a9c160aSmrg                        ;;
26031a9c160aSmrg
26041a9c160aSmrg        --no-silent|--no-quiet)
26051a9c160aSmrg                        opt_quiet=false
26061a9c160aSmrg                        func_append preserve_args " $_G_opt"
26071a9c160aSmrg                        ;;
26081a9c160aSmrg
26091a9c160aSmrg        --no-warnings|--no-warning|--no-warn)
26101a9c160aSmrg                        opt_warning=false
26111a9c160aSmrg                        func_append preserve_args " $_G_opt"
26121a9c160aSmrg                        ;;
26131a9c160aSmrg
26141a9c160aSmrg        --no-verbose)
26151a9c160aSmrg                        opt_verbose=false
26161a9c160aSmrg                        func_append preserve_args " $_G_opt"
26171a9c160aSmrg                        ;;
26181a9c160aSmrg
26191a9c160aSmrg        --silent|--quiet)
26201a9c160aSmrg                        opt_quiet=:
26211a9c160aSmrg                        opt_verbose=false
26221a9c160aSmrg                        func_append preserve_args " $_G_opt"
26231a9c160aSmrg                        ;;
26241a9c160aSmrg
26251a9c160aSmrg        --tag)          test $# = 0 && func_missing_arg $_G_opt && break
26261a9c160aSmrg                        opt_tag=$1
26271a9c160aSmrg                        func_append preserve_args " $_G_opt $1"
26281a9c160aSmrg                        func_enable_tag "$1"
26291a9c160aSmrg                        shift
26301a9c160aSmrg                        ;;
26311a9c160aSmrg
26321a9c160aSmrg        --verbose|-v)   opt_quiet=false
26331a9c160aSmrg                        opt_verbose=:
26341a9c160aSmrg                        func_append preserve_args " $_G_opt"
26351a9c160aSmrg                        ;;
26361a9c160aSmrg
2637621f50c3Smrg        # An option not handled by this hook function:
2638621f50c3Smrg        *)              set dummy "$_G_opt" ${1+"$@"} ; shift
2639621f50c3Smrg                        _G_match_lt_parse_options=false
2640621f50c3Smrg                        break
2641621f50c3Smrg                        ;;
26421a9c160aSmrg      esac
2643621f50c3Smrg      $_G_match_lt_parse_options && _G_rc_lt_parse_options=:
26441a9c160aSmrg    done
2645dd0822caSmrg
2646621f50c3Smrg    if $_G_rc_lt_parse_options; then
2647621f50c3Smrg      # save modified positional parameters for caller
2648621f50c3Smrg      func_quote eval ${1+"$@"}
2649621f50c3Smrg      libtool_parse_options_result=$func_quote_result
2650621f50c3Smrg    fi
26511a9c160aSmrg}
26521a9c160aSmrgfunc_add_hook func_parse_options libtool_parse_options
2653dc407927Smrg
26543eed67faSmbalmer
2655dc407927Smrg
26561a9c160aSmrg# libtool_validate_options [ARG]...
26571a9c160aSmrg# ---------------------------------
26581a9c160aSmrg# Perform any sanity checks on option settings and/or unconsumed
26591a9c160aSmrg# arguments.
26601a9c160aSmrglibtool_validate_options ()
26611a9c160aSmrg{
26621a9c160aSmrg    # save first non-option argument
26631a9c160aSmrg    if test 0 -lt $#; then
26641a9c160aSmrg      nonopt=$1
26651a9c160aSmrg      shift
2666dc407927Smrg    fi
2667dc407927Smrg
26681a9c160aSmrg    # preserve --debug
26691a9c160aSmrg    test : = "$debug_cmd" || func_append preserve_args " --debug"
2670dc407927Smrg
26711a9c160aSmrg    case $host in
26721a9c160aSmrg      # Solaris2 added to fix http://debbugs.gnu.org/cgi/bugreport.cgi?bug=16452
26731a9c160aSmrg      # see also: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59788
26741a9c160aSmrg      *cygwin* | *mingw* | *pw32* | *cegcc* | *solaris2* | *os2*)
26751a9c160aSmrg        # don't eliminate duplications in $postdeps and $predeps
26761a9c160aSmrg        opt_duplicate_compiler_generated_deps=:
26771a9c160aSmrg        ;;
26781a9c160aSmrg      *)
26791a9c160aSmrg        opt_duplicate_compiler_generated_deps=$opt_preserve_dup_deps
26801a9c160aSmrg        ;;
26811a9c160aSmrg    esac
26823eed67faSmbalmer
26831a9c160aSmrg    $opt_help || {
26841a9c160aSmrg      # Sanity checks first:
26851a9c160aSmrg      func_check_version_match
26861a9c160aSmrg
26871a9c160aSmrg      test yes != "$build_libtool_libs" \
26881a9c160aSmrg        && test yes != "$build_old_libs" \
26891a9c160aSmrg        && func_fatal_configuration "not configured to build any kind of library"
26901a9c160aSmrg
26911a9c160aSmrg      # Darwin sucks
26921a9c160aSmrg      eval std_shrext=\"$shrext_cmds\"
26931a9c160aSmrg
26941a9c160aSmrg      # Only execute mode is allowed to have -dlopen flags.
26951a9c160aSmrg      if test -n "$opt_dlopen" && test execute != "$opt_mode"; then
26961a9c160aSmrg        func_error "unrecognized option '-dlopen'"
26971a9c160aSmrg        $ECHO "$help" 1>&2
26981a9c160aSmrg        exit $EXIT_FAILURE
26991a9c160aSmrg      fi
2700dc407927Smrg
27011a9c160aSmrg      # Change the help message to a mode-specific one.
27021a9c160aSmrg      generic_help=$help
27031a9c160aSmrg      help="Try '$progname --help --mode=$opt_mode' for more information."
27041a9c160aSmrg    }
2705dc407927Smrg
27061a9c160aSmrg    # Pass back the unparsed argument list
2707621f50c3Smrg    func_quote eval ${1+"$@"}
2708621f50c3Smrg    libtool_validate_options_result=$func_quote_result
2709dd0822caSmrg}
27101a9c160aSmrgfunc_add_hook func_validate_options libtool_validate_options
2711dc407927Smrg
2712dc407927Smrg
27131a9c160aSmrg# Process options as early as possible so that --help and --version
27141a9c160aSmrg# can return quickly.
27151a9c160aSmrgfunc_options ${1+"$@"}
27161a9c160aSmrgeval set dummy "$func_options_result"; shift
27171a9c160aSmrg
27183eed67faSmbalmer
27193eed67faSmbalmer
2720dd0822caSmrg## ----------- ##
2721dd0822caSmrg##    Main.    ##
2722dd0822caSmrg## ----------- ##
27233eed67faSmbalmer
27241a9c160aSmrgmagic='%%%MAGIC variable%%%'
27251a9c160aSmrgmagic_exe='%%%MAGIC EXE variable%%%'
27261a9c160aSmrg
27271a9c160aSmrg# Global variables.
27281a9c160aSmrgextracted_archives=
27291a9c160aSmrgextracted_serial=0
27301a9c160aSmrg
27311a9c160aSmrg# If this variable is set in any of the actions, the command in it
27321a9c160aSmrg# will be execed at the end.  This prevents here-documents from being
27331a9c160aSmrg# left over by shells.
27341a9c160aSmrgexec_cmd=
27351a9c160aSmrg
27361a9c160aSmrg
27371a9c160aSmrg# A function that is used when there is no print builtin or printf.
27381a9c160aSmrgfunc_fallback_echo ()
27391a9c160aSmrg{
27401a9c160aSmrg  eval 'cat <<_LTECHO_EOF
27411a9c160aSmrg$1
27421a9c160aSmrg_LTECHO_EOF'
27431a9c160aSmrg}
27441a9c160aSmrg
27451a9c160aSmrg# func_generated_by_libtool
27461a9c160aSmrg# True iff stdin has been generated by Libtool. This function is only
27471a9c160aSmrg# a basic sanity check; it will hardly flush out determined imposters.
27481a9c160aSmrgfunc_generated_by_libtool_p ()
27491a9c160aSmrg{
27501a9c160aSmrg  $GREP "^# Generated by .*$PACKAGE" > /dev/null 2>&1
27511a9c160aSmrg}
27521a9c160aSmrg
2753dc407927Smrg# func_lalib_p file
27541a9c160aSmrg# True iff FILE is a libtool '.la' library or '.lo' object file.
2755dc407927Smrg# This function is only a basic sanity check; it will hardly flush out
2756dc407927Smrg# determined imposters.
2757dc407927Smrgfunc_lalib_p ()
2758dc407927Smrg{
2759dc407927Smrg    test -f "$1" &&
27601a9c160aSmrg      $SED -e 4q "$1" 2>/dev/null | func_generated_by_libtool_p
2761dc407927Smrg}
27623eed67faSmbalmer
2763dc407927Smrg# func_lalib_unsafe_p file
27641a9c160aSmrg# True iff FILE is a libtool '.la' library or '.lo' object file.
2765dc407927Smrg# This function implements the same check as func_lalib_p without
2766dc407927Smrg# resorting to external programs.  To this end, it redirects stdin and
2767dc407927Smrg# closes it afterwards, without saving the original file descriptor.
2768dc407927Smrg# As a safety measure, use it only where a negative result would be
27691a9c160aSmrg# fatal anyway.  Works if 'file' does not exist.
2770dc407927Smrgfunc_lalib_unsafe_p ()
2771dc407927Smrg{
2772dc407927Smrg    lalib_p=no
2773dc407927Smrg    if test -f "$1" && test -r "$1" && exec 5<&0 <"$1"; then
2774dc407927Smrg	for lalib_p_l in 1 2 3 4
2775dc407927Smrg	do
2776dc407927Smrg	    read lalib_p_line
27771a9c160aSmrg	    case $lalib_p_line in
2778dc407927Smrg		\#\ Generated\ by\ *$PACKAGE* ) lalib_p=yes; break;;
2779dc407927Smrg	    esac
2780dc407927Smrg	done
2781dc407927Smrg	exec 0<&5 5<&-
2782dc407927Smrg    fi
27831a9c160aSmrg    test yes = "$lalib_p"
2784dc407927Smrg}
27853eed67faSmbalmer
2786dc407927Smrg# func_ltwrapper_script_p file
2787dc407927Smrg# True iff FILE is a libtool wrapper script
2788dc407927Smrg# This function is only a basic sanity check; it will hardly flush out
2789dc407927Smrg# determined imposters.
2790dc407927Smrgfunc_ltwrapper_script_p ()
2791dc407927Smrg{
27921a9c160aSmrg    test -f "$1" &&
27931a9c160aSmrg      $lt_truncate_bin < "$1" 2>/dev/null | func_generated_by_libtool_p
2794dc407927Smrg}
27953eed67faSmbalmer
2796dc407927Smrg# func_ltwrapper_executable_p file
2797dc407927Smrg# True iff FILE is a libtool wrapper executable
2798dc407927Smrg# This function is only a basic sanity check; it will hardly flush out
2799dc407927Smrg# determined imposters.
2800dc407927Smrgfunc_ltwrapper_executable_p ()
2801dc407927Smrg{
2802dc407927Smrg    func_ltwrapper_exec_suffix=
2803dc407927Smrg    case $1 in
2804dc407927Smrg    *.exe) ;;
2805dc407927Smrg    *) func_ltwrapper_exec_suffix=.exe ;;
2806dc407927Smrg    esac
2807dc407927Smrg    $GREP "$magic_exe" "$1$func_ltwrapper_exec_suffix" >/dev/null 2>&1
2808dc407927Smrg}
28093eed67faSmbalmer
2810dc407927Smrg# func_ltwrapper_scriptname file
2811dc407927Smrg# Assumes file is an ltwrapper_executable
2812dc407927Smrg# uses $file to determine the appropriate filename for a
2813dc407927Smrg# temporary ltwrapper_script.
2814dc407927Smrgfunc_ltwrapper_scriptname ()
2815dc407927Smrg{
2816dd0822caSmrg    func_dirname_and_basename "$1" "" "."
2817dd0822caSmrg    func_stripname '' '.exe' "$func_basename_result"
28181a9c160aSmrg    func_ltwrapper_scriptname_result=$func_dirname_result/$objdir/${func_stripname_result}_ltshwrapper
2819dc407927Smrg}
2820dc407927Smrg
2821dc407927Smrg# func_ltwrapper_p file
2822dc407927Smrg# True iff FILE is a libtool wrapper script or wrapper executable
2823dc407927Smrg# This function is only a basic sanity check; it will hardly flush out
2824dc407927Smrg# determined imposters.
2825dc407927Smrgfunc_ltwrapper_p ()
2826dc407927Smrg{
2827dc407927Smrg    func_ltwrapper_script_p "$1" || func_ltwrapper_executable_p "$1"
2828dc407927Smrg}
2829dc407927Smrg
2830dc407927Smrg
2831dc407927Smrg# func_execute_cmds commands fail_cmd
2832dc407927Smrg# Execute tilde-delimited COMMANDS.
2833dc407927Smrg# If FAIL_CMD is given, eval that upon failure.
2834dc407927Smrg# FAIL_CMD may read-access the current command in variable CMD!
2835dc407927Smrgfunc_execute_cmds ()
2836dc407927Smrg{
28371a9c160aSmrg    $debug_cmd
28381a9c160aSmrg
2839dc407927Smrg    save_ifs=$IFS; IFS='~'
2840dc407927Smrg    for cmd in $1; do
28411a9c160aSmrg      IFS=$sp$nl
2842dc407927Smrg      eval cmd=\"$cmd\"
28431a9c160aSmrg      IFS=$save_ifs
2844dc407927Smrg      func_show_eval "$cmd" "${2-:}"
2845dc407927Smrg    done
2846dc407927Smrg    IFS=$save_ifs
2847dc407927Smrg}
2848dc407927Smrg
2849dc407927Smrg
2850dc407927Smrg# func_source file
2851dc407927Smrg# Source FILE, adding directory component if necessary.
2852dc407927Smrg# Note that it is not necessary on cygwin/mingw to append a dot to
2853dc407927Smrg# FILE even if both FILE and FILE.exe exist: automatic-append-.exe
2854dc407927Smrg# behavior happens only for exec(3), not for open(2)!  Also, sourcing
28551a9c160aSmrg# 'FILE.' does not work on cygwin managed mounts.
2856dc407927Smrgfunc_source ()
2857dc407927Smrg{
28581a9c160aSmrg    $debug_cmd
28591a9c160aSmrg
2860dc407927Smrg    case $1 in
2861dc407927Smrg    */* | *\\*)	. "$1" ;;
2862dc407927Smrg    *)		. "./$1" ;;
2863dc407927Smrg    esac
2864dc407927Smrg}
2865dc407927Smrg
2866dc407927Smrg
2867dd0822caSmrg# func_resolve_sysroot PATH
2868dd0822caSmrg# Replace a leading = in PATH with a sysroot.  Store the result into
2869dd0822caSmrg# func_resolve_sysroot_result
2870dd0822caSmrgfunc_resolve_sysroot ()
2871dd0822caSmrg{
2872dd0822caSmrg  func_resolve_sysroot_result=$1
2873dd0822caSmrg  case $func_resolve_sysroot_result in
2874dd0822caSmrg  =*)
2875dd0822caSmrg    func_stripname '=' '' "$func_resolve_sysroot_result"
2876dd0822caSmrg    func_resolve_sysroot_result=$lt_sysroot$func_stripname_result
2877dd0822caSmrg    ;;
2878dd0822caSmrg  esac
2879dd0822caSmrg}
2880dd0822caSmrg
2881dd0822caSmrg# func_replace_sysroot PATH
2882dd0822caSmrg# If PATH begins with the sysroot, replace it with = and
2883dd0822caSmrg# store the result into func_replace_sysroot_result.
2884dd0822caSmrgfunc_replace_sysroot ()
2885dd0822caSmrg{
28861a9c160aSmrg  case $lt_sysroot:$1 in
2887dd0822caSmrg  ?*:"$lt_sysroot"*)
2888dd0822caSmrg    func_stripname "$lt_sysroot" '' "$1"
28891a9c160aSmrg    func_replace_sysroot_result='='$func_stripname_result
2890dd0822caSmrg    ;;
2891dd0822caSmrg  *)
2892dd0822caSmrg    # Including no sysroot.
2893dd0822caSmrg    func_replace_sysroot_result=$1
2894dd0822caSmrg    ;;
2895dd0822caSmrg  esac
2896dd0822caSmrg}
2897dd0822caSmrg
2898dc407927Smrg# func_infer_tag arg
2899dc407927Smrg# Infer tagged configuration to use if any are available and
2900dc407927Smrg# if one wasn't chosen via the "--tag" command line option.
2901dc407927Smrg# Only attempt this if the compiler in the base compile
2902dc407927Smrg# command doesn't match the default compiler.
2903dc407927Smrg# arg is usually of the form 'gcc ...'
2904dc407927Smrgfunc_infer_tag ()
2905dc407927Smrg{
29061a9c160aSmrg    $debug_cmd
29071a9c160aSmrg
2908dc407927Smrg    if test -n "$available_tags" && test -z "$tagname"; then
2909dc407927Smrg      CC_quoted=
2910dc407927Smrg      for arg in $CC; do
2911dd0822caSmrg	func_append_quoted CC_quoted "$arg"
2912dc407927Smrg      done
2913dd0822caSmrg      CC_expanded=`func_echo_all $CC`
2914dd0822caSmrg      CC_quoted_expanded=`func_echo_all $CC_quoted`
2915dc407927Smrg      case $@ in
2916dc407927Smrg      # Blanks in the command may have been stripped by the calling shell,
2917dc407927Smrg      # but not from the CC environment variable when configure was run.
2918dd0822caSmrg      " $CC "* | "$CC "* | " $CC_expanded "* | "$CC_expanded "* | \
2919dd0822caSmrg      " $CC_quoted"* | "$CC_quoted "* | " $CC_quoted_expanded "* | "$CC_quoted_expanded "*) ;;
2920dc407927Smrg      # Blanks at the start of $base_compile will cause this to fail
2921dc407927Smrg      # if we don't check for them as well.
2922dc407927Smrg      *)
2923dc407927Smrg	for z in $available_tags; do
2924dc407927Smrg	  if $GREP "^# ### BEGIN LIBTOOL TAG CONFIG: $z$" < "$progpath" > /dev/null; then
2925dc407927Smrg	    # Evaluate the configuration.
29261a9c160aSmrg	    eval "`$SED -n -e '/^# ### BEGIN LIBTOOL TAG CONFIG: '$z'$/,/^# ### END LIBTOOL TAG CONFIG: '$z'$/p' < $progpath`"
2927dc407927Smrg	    CC_quoted=
2928dc407927Smrg	    for arg in $CC; do
2929dc407927Smrg	      # Double-quote args containing other shell metacharacters.
2930dd0822caSmrg	      func_append_quoted CC_quoted "$arg"
2931dc407927Smrg	    done
2932dd0822caSmrg	    CC_expanded=`func_echo_all $CC`
2933dd0822caSmrg	    CC_quoted_expanded=`func_echo_all $CC_quoted`
2934dc407927Smrg	    case "$@ " in
2935dd0822caSmrg	    " $CC "* | "$CC "* | " $CC_expanded "* | "$CC_expanded "* | \
2936dd0822caSmrg	    " $CC_quoted"* | "$CC_quoted "* | " $CC_quoted_expanded "* | "$CC_quoted_expanded "*)
2937dc407927Smrg	      # The compiler in the base compile command matches
2938dc407927Smrg	      # the one in the tagged configuration.
2939dc407927Smrg	      # Assume this is the tagged configuration we want.
2940dc407927Smrg	      tagname=$z
2941dc407927Smrg	      break
2942dc407927Smrg	      ;;
2943dc407927Smrg	    esac
2944dc407927Smrg	  fi
2945dc407927Smrg	done
2946dc407927Smrg	# If $tagname still isn't set, then no tagged configuration
2947dc407927Smrg	# was found and let the user know that the "--tag" command
2948dc407927Smrg	# line option must be used.
2949dc407927Smrg	if test -z "$tagname"; then
2950dc407927Smrg	  func_echo "unable to infer tagged configuration"
29511a9c160aSmrg	  func_fatal_error "specify a tag with '--tag'"
2952dc407927Smrg#	else
2953dc407927Smrg#	  func_verbose "using $tagname tagged configuration"
2954dc407927Smrg	fi
2955dc407927Smrg	;;
2956dc407927Smrg      esac
2957dc407927Smrg    fi
2958dc407927Smrg}
2959dc407927Smrg
2960dc407927Smrg
2961dc407927Smrg
2962dc407927Smrg# func_write_libtool_object output_name pic_name nonpic_name
2963dc407927Smrg# Create a libtool object file (analogous to a ".la" file),
2964dc407927Smrg# but don't create it if we're doing a dry run.
2965dc407927Smrgfunc_write_libtool_object ()
2966dc407927Smrg{
29671a9c160aSmrg    write_libobj=$1
29681a9c160aSmrg    if test yes = "$build_libtool_libs"; then
29691a9c160aSmrg      write_lobj=\'$2\'
2970dc407927Smrg    else
2971dc407927Smrg      write_lobj=none
2972dc407927Smrg    fi
2973dc407927Smrg
29741a9c160aSmrg    if test yes = "$build_old_libs"; then
29751a9c160aSmrg      write_oldobj=\'$3\'
2976dc407927Smrg    else
2977dc407927Smrg      write_oldobj=none
2978dc407927Smrg    fi
2979dc407927Smrg
2980dc407927Smrg    $opt_dry_run || {
2981dc407927Smrg      cat >${write_libobj}T <<EOF
2982dc407927Smrg# $write_libobj - a libtool object file
29831a9c160aSmrg# Generated by $PROGRAM (GNU $PACKAGE) $VERSION
2984dc407927Smrg#
2985dc407927Smrg# Please DO NOT delete this file!
2986dc407927Smrg# It is necessary for linking the library.
2987dc407927Smrg
2988dc407927Smrg# Name of the PIC object.
2989dc407927Smrgpic_object=$write_lobj
2990dc407927Smrg
2991dc407927Smrg# Name of the non-PIC object
2992dc407927Smrgnon_pic_object=$write_oldobj
2993dc407927Smrg
2994dc407927SmrgEOF
29951a9c160aSmrg      $MV "${write_libobj}T" "$write_libobj"
2996dc407927Smrg    }
2997dc407927Smrg}
2998dc407927Smrg
2999dd0822caSmrg
3000dd0822caSmrg##################################################
3001dd0822caSmrg# FILE NAME AND PATH CONVERSION HELPER FUNCTIONS #
3002dd0822caSmrg##################################################
3003dd0822caSmrg
3004dd0822caSmrg# func_convert_core_file_wine_to_w32 ARG
3005dd0822caSmrg# Helper function used by file name conversion functions when $build is *nix,
3006dd0822caSmrg# and $host is mingw, cygwin, or some other w32 environment. Relies on a
3007dd0822caSmrg# correctly configured wine environment available, with the winepath program
3008dd0822caSmrg# in $build's $PATH.
3009dd0822caSmrg#
3010dd0822caSmrg# ARG is the $build file name to be converted to w32 format.
3011dd0822caSmrg# Result is available in $func_convert_core_file_wine_to_w32_result, and will
3012dd0822caSmrg# be empty on error (or when ARG is empty)
3013dd0822caSmrgfunc_convert_core_file_wine_to_w32 ()
3014dd0822caSmrg{
30151a9c160aSmrg  $debug_cmd
30161a9c160aSmrg
30171a9c160aSmrg  func_convert_core_file_wine_to_w32_result=$1
3018dd0822caSmrg  if test -n "$1"; then
3019dd0822caSmrg    # Unfortunately, winepath does not exit with a non-zero error code, so we
3020dd0822caSmrg    # are forced to check the contents of stdout. On the other hand, if the
3021dd0822caSmrg    # command is not found, the shell will set an exit code of 127 and print
3022dd0822caSmrg    # *an error message* to stdout. So we must check for both error code of
3023dd0822caSmrg    # zero AND non-empty stdout, which explains the odd construction:
3024dd0822caSmrg    func_convert_core_file_wine_to_w32_tmp=`winepath -w "$1" 2>/dev/null`
30251a9c160aSmrg    if test "$?" -eq 0 && test -n "$func_convert_core_file_wine_to_w32_tmp"; then
3026dd0822caSmrg      func_convert_core_file_wine_to_w32_result=`$ECHO "$func_convert_core_file_wine_to_w32_tmp" |
30271a9c160aSmrg        $SED -e "$sed_naive_backslashify"`
3028dd0822caSmrg    else
3029dd0822caSmrg      func_convert_core_file_wine_to_w32_result=
3030dd0822caSmrg    fi
3031dd0822caSmrg  fi
3032dd0822caSmrg}
3033dd0822caSmrg# end: func_convert_core_file_wine_to_w32
3034dd0822caSmrg
3035dd0822caSmrg
3036dd0822caSmrg# func_convert_core_path_wine_to_w32 ARG
3037dd0822caSmrg# Helper function used by path conversion functions when $build is *nix, and
3038dd0822caSmrg# $host is mingw, cygwin, or some other w32 environment. Relies on a correctly
3039dd0822caSmrg# configured wine environment available, with the winepath program in $build's
3040dd0822caSmrg# $PATH. Assumes ARG has no leading or trailing path separator characters.
3041dd0822caSmrg#
3042dd0822caSmrg# ARG is path to be converted from $build format to win32.
3043dd0822caSmrg# Result is available in $func_convert_core_path_wine_to_w32_result.
3044dd0822caSmrg# Unconvertible file (directory) names in ARG are skipped; if no directory names
3045dd0822caSmrg# are convertible, then the result may be empty.
3046dd0822caSmrgfunc_convert_core_path_wine_to_w32 ()
3047dd0822caSmrg{
30481a9c160aSmrg  $debug_cmd
30491a9c160aSmrg
3050dd0822caSmrg  # unfortunately, winepath doesn't convert paths, only file names
30511a9c160aSmrg  func_convert_core_path_wine_to_w32_result=
3052dd0822caSmrg  if test -n "$1"; then
3053dd0822caSmrg    oldIFS=$IFS
3054dd0822caSmrg    IFS=:
3055dd0822caSmrg    for func_convert_core_path_wine_to_w32_f in $1; do
3056dd0822caSmrg      IFS=$oldIFS
3057dd0822caSmrg      func_convert_core_file_wine_to_w32 "$func_convert_core_path_wine_to_w32_f"
30581a9c160aSmrg      if test -n "$func_convert_core_file_wine_to_w32_result"; then
3059dd0822caSmrg        if test -z "$func_convert_core_path_wine_to_w32_result"; then
30601a9c160aSmrg          func_convert_core_path_wine_to_w32_result=$func_convert_core_file_wine_to_w32_result
3061dd0822caSmrg        else
3062dd0822caSmrg          func_append func_convert_core_path_wine_to_w32_result ";$func_convert_core_file_wine_to_w32_result"
3063dd0822caSmrg        fi
3064dd0822caSmrg      fi
3065dd0822caSmrg    done
3066dd0822caSmrg    IFS=$oldIFS
3067dd0822caSmrg  fi
3068dd0822caSmrg}
3069dd0822caSmrg# end: func_convert_core_path_wine_to_w32
3070dd0822caSmrg
3071dd0822caSmrg
3072dd0822caSmrg# func_cygpath ARGS...
3073dd0822caSmrg# Wrapper around calling the cygpath program via LT_CYGPATH. This is used when
3074dd0822caSmrg# when (1) $build is *nix and Cygwin is hosted via a wine environment; or (2)
3075dd0822caSmrg# $build is MSYS and $host is Cygwin, or (3) $build is Cygwin. In case (1) or
3076dd0822caSmrg# (2), returns the Cygwin file name or path in func_cygpath_result (input
3077dd0822caSmrg# file name or path is assumed to be in w32 format, as previously converted
3078dd0822caSmrg# from $build's *nix or MSYS format). In case (3), returns the w32 file name
3079dd0822caSmrg# or path in func_cygpath_result (input file name or path is assumed to be in
3080dd0822caSmrg# Cygwin format). Returns an empty string on error.
3081dd0822caSmrg#
3082dd0822caSmrg# ARGS are passed to cygpath, with the last one being the file name or path to
3083dd0822caSmrg# be converted.
3084dd0822caSmrg#
3085dd0822caSmrg# Specify the absolute *nix (or w32) name to cygpath in the LT_CYGPATH
3086dd0822caSmrg# environment variable; do not put it in $PATH.
3087dd0822caSmrgfunc_cygpath ()
3088dd0822caSmrg{
30891a9c160aSmrg  $debug_cmd
30901a9c160aSmrg
3091dd0822caSmrg  if test -n "$LT_CYGPATH" && test -f "$LT_CYGPATH"; then
3092dd0822caSmrg    func_cygpath_result=`$LT_CYGPATH "$@" 2>/dev/null`
3093dd0822caSmrg    if test "$?" -ne 0; then
3094dd0822caSmrg      # on failure, ensure result is empty
3095dd0822caSmrg      func_cygpath_result=
3096dd0822caSmrg    fi
3097dd0822caSmrg  else
3098dd0822caSmrg    func_cygpath_result=
30991a9c160aSmrg    func_error "LT_CYGPATH is empty or specifies non-existent file: '$LT_CYGPATH'"
3100dd0822caSmrg  fi
3101dd0822caSmrg}
3102dd0822caSmrg#end: func_cygpath
3103dd0822caSmrg
3104dd0822caSmrg
3105dd0822caSmrg# func_convert_core_msys_to_w32 ARG
3106dd0822caSmrg# Convert file name or path ARG from MSYS format to w32 format.  Return
3107dd0822caSmrg# result in func_convert_core_msys_to_w32_result.
3108dd0822caSmrgfunc_convert_core_msys_to_w32 ()
3109dd0822caSmrg{
31101a9c160aSmrg  $debug_cmd
31111a9c160aSmrg
3112dd0822caSmrg  # awkward: cmd appends spaces to result
3113dd0822caSmrg  func_convert_core_msys_to_w32_result=`( cmd //c echo "$1" ) 2>/dev/null |
31141a9c160aSmrg    $SED -e 's/[ ]*$//' -e "$sed_naive_backslashify"`
3115dd0822caSmrg}
3116dd0822caSmrg#end: func_convert_core_msys_to_w32
3117dd0822caSmrg
3118dd0822caSmrg
3119dd0822caSmrg# func_convert_file_check ARG1 ARG2
3120dd0822caSmrg# Verify that ARG1 (a file name in $build format) was converted to $host
3121dd0822caSmrg# format in ARG2. Otherwise, emit an error message, but continue (resetting
3122dd0822caSmrg# func_to_host_file_result to ARG1).
3123dd0822caSmrgfunc_convert_file_check ()
3124dd0822caSmrg{
31251a9c160aSmrg  $debug_cmd
31261a9c160aSmrg
31271a9c160aSmrg  if test -z "$2" && test -n "$1"; then
3128dd0822caSmrg    func_error "Could not determine host file name corresponding to"
31291a9c160aSmrg    func_error "  '$1'"
3130dd0822caSmrg    func_error "Continuing, but uninstalled executables may not work."
3131dd0822caSmrg    # Fallback:
31321a9c160aSmrg    func_to_host_file_result=$1
3133dd0822caSmrg  fi
3134dd0822caSmrg}
3135dd0822caSmrg# end func_convert_file_check
3136dd0822caSmrg
3137dd0822caSmrg
3138dd0822caSmrg# func_convert_path_check FROM_PATHSEP TO_PATHSEP FROM_PATH TO_PATH
3139dd0822caSmrg# Verify that FROM_PATH (a path in $build format) was converted to $host
3140dd0822caSmrg# format in TO_PATH. Otherwise, emit an error message, but continue, resetting
3141dd0822caSmrg# func_to_host_file_result to a simplistic fallback value (see below).
3142dd0822caSmrgfunc_convert_path_check ()
3143dd0822caSmrg{
31441a9c160aSmrg  $debug_cmd
31451a9c160aSmrg
3146dd0822caSmrg  if test -z "$4" && test -n "$3"; then
3147dd0822caSmrg    func_error "Could not determine the host path corresponding to"
31481a9c160aSmrg    func_error "  '$3'"
3149dd0822caSmrg    func_error "Continuing, but uninstalled executables may not work."
3150dd0822caSmrg    # Fallback.  This is a deliberately simplistic "conversion" and
3151dd0822caSmrg    # should not be "improved".  See libtool.info.
3152dd0822caSmrg    if test "x$1" != "x$2"; then
3153dd0822caSmrg      lt_replace_pathsep_chars="s|$1|$2|g"
3154dd0822caSmrg      func_to_host_path_result=`echo "$3" |
3155dd0822caSmrg        $SED -e "$lt_replace_pathsep_chars"`
3156dd0822caSmrg    else
31571a9c160aSmrg      func_to_host_path_result=$3
3158dd0822caSmrg    fi
3159dd0822caSmrg  fi
3160dd0822caSmrg}
3161dd0822caSmrg# end func_convert_path_check
3162dd0822caSmrg
3163dd0822caSmrg
3164dd0822caSmrg# func_convert_path_front_back_pathsep FRONTPAT BACKPAT REPL ORIG
3165dd0822caSmrg# Modifies func_to_host_path_result by prepending REPL if ORIG matches FRONTPAT
3166dd0822caSmrg# and appending REPL if ORIG matches BACKPAT.
3167dd0822caSmrgfunc_convert_path_front_back_pathsep ()
3168dd0822caSmrg{
31691a9c160aSmrg  $debug_cmd
31701a9c160aSmrg
3171dd0822caSmrg  case $4 in
31721a9c160aSmrg  $1 ) func_to_host_path_result=$3$func_to_host_path_result
3173dd0822caSmrg    ;;
3174dd0822caSmrg  esac
3175dd0822caSmrg  case $4 in
3176dd0822caSmrg  $2 ) func_append func_to_host_path_result "$3"
3177dd0822caSmrg    ;;
3178dd0822caSmrg  esac
3179dd0822caSmrg}
3180dd0822caSmrg# end func_convert_path_front_back_pathsep
3181dd0822caSmrg
3182dd0822caSmrg
3183dd0822caSmrg##################################################
3184dd0822caSmrg# $build to $host FILE NAME CONVERSION FUNCTIONS #
3185dd0822caSmrg##################################################
31861a9c160aSmrg# invoked via '$to_host_file_cmd ARG'
3187dd0822caSmrg#
3188dd0822caSmrg# In each case, ARG is the path to be converted from $build to $host format.
3189dd0822caSmrg# Result will be available in $func_to_host_file_result.
3190dd0822caSmrg
3191dd0822caSmrg
3192dd0822caSmrg# func_to_host_file ARG
3193dd0822caSmrg# Converts the file name ARG from $build format to $host format. Return result
3194dd0822caSmrg# in func_to_host_file_result.
3195dd0822caSmrgfunc_to_host_file ()
3196dd0822caSmrg{
31971a9c160aSmrg  $debug_cmd
31981a9c160aSmrg
3199dd0822caSmrg  $to_host_file_cmd "$1"
3200dd0822caSmrg}
3201dd0822caSmrg# end func_to_host_file
3202dd0822caSmrg
3203dd0822caSmrg
3204dd0822caSmrg# func_to_tool_file ARG LAZY
3205dd0822caSmrg# converts the file name ARG from $build format to toolchain format. Return
3206dd0822caSmrg# result in func_to_tool_file_result.  If the conversion in use is listed
3207dd0822caSmrg# in (the comma separated) LAZY, no conversion takes place.
3208dd0822caSmrgfunc_to_tool_file ()
3209dd0822caSmrg{
32101a9c160aSmrg  $debug_cmd
32111a9c160aSmrg
3212dd0822caSmrg  case ,$2, in
3213dd0822caSmrg    *,"$to_tool_file_cmd",*)
3214dd0822caSmrg      func_to_tool_file_result=$1
3215dd0822caSmrg      ;;
3216dd0822caSmrg    *)
3217dd0822caSmrg      $to_tool_file_cmd "$1"
3218dd0822caSmrg      func_to_tool_file_result=$func_to_host_file_result
3219dd0822caSmrg      ;;
3220dd0822caSmrg  esac
3221dd0822caSmrg}
3222dd0822caSmrg# end func_to_tool_file
3223dd0822caSmrg
3224dd0822caSmrg
3225dd0822caSmrg# func_convert_file_noop ARG
3226dd0822caSmrg# Copy ARG to func_to_host_file_result.
3227dd0822caSmrgfunc_convert_file_noop ()
3228dd0822caSmrg{
32291a9c160aSmrg  func_to_host_file_result=$1
3230dd0822caSmrg}
3231dd0822caSmrg# end func_convert_file_noop
3232dd0822caSmrg
3233dd0822caSmrg
3234dd0822caSmrg# func_convert_file_msys_to_w32 ARG
3235dd0822caSmrg# Convert file name ARG from (mingw) MSYS to (mingw) w32 format; automatic
3236dd0822caSmrg# conversion to w32 is not available inside the cwrapper.  Returns result in
3237dd0822caSmrg# func_to_host_file_result.
3238dd0822caSmrgfunc_convert_file_msys_to_w32 ()
3239dd0822caSmrg{
32401a9c160aSmrg  $debug_cmd
32411a9c160aSmrg
32421a9c160aSmrg  func_to_host_file_result=$1
3243dd0822caSmrg  if test -n "$1"; then
3244dd0822caSmrg    func_convert_core_msys_to_w32 "$1"
32451a9c160aSmrg    func_to_host_file_result=$func_convert_core_msys_to_w32_result
3246dd0822caSmrg  fi
3247dd0822caSmrg  func_convert_file_check "$1" "$func_to_host_file_result"
3248dd0822caSmrg}
3249dd0822caSmrg# end func_convert_file_msys_to_w32
3250dd0822caSmrg
3251dd0822caSmrg
3252dd0822caSmrg# func_convert_file_cygwin_to_w32 ARG
3253dd0822caSmrg# Convert file name ARG from Cygwin to w32 format.  Returns result in
3254dd0822caSmrg# func_to_host_file_result.
3255dd0822caSmrgfunc_convert_file_cygwin_to_w32 ()
3256dd0822caSmrg{
32571a9c160aSmrg  $debug_cmd
32581a9c160aSmrg
32591a9c160aSmrg  func_to_host_file_result=$1
3260dd0822caSmrg  if test -n "$1"; then
3261dd0822caSmrg    # because $build is cygwin, we call "the" cygpath in $PATH; no need to use
3262dd0822caSmrg    # LT_CYGPATH in this case.
3263dd0822caSmrg    func_to_host_file_result=`cygpath -m "$1"`
3264dd0822caSmrg  fi
3265dd0822caSmrg  func_convert_file_check "$1" "$func_to_host_file_result"
3266dd0822caSmrg}
3267dd0822caSmrg# end func_convert_file_cygwin_to_w32
3268dd0822caSmrg
3269dd0822caSmrg
3270dd0822caSmrg# func_convert_file_nix_to_w32 ARG
3271dd0822caSmrg# Convert file name ARG from *nix to w32 format.  Requires a wine environment
3272dd0822caSmrg# and a working winepath. Returns result in func_to_host_file_result.
3273dd0822caSmrgfunc_convert_file_nix_to_w32 ()
3274dd0822caSmrg{
32751a9c160aSmrg  $debug_cmd
32761a9c160aSmrg
32771a9c160aSmrg  func_to_host_file_result=$1
3278dd0822caSmrg  if test -n "$1"; then
3279dd0822caSmrg    func_convert_core_file_wine_to_w32 "$1"
32801a9c160aSmrg    func_to_host_file_result=$func_convert_core_file_wine_to_w32_result
3281dd0822caSmrg  fi
3282dd0822caSmrg  func_convert_file_check "$1" "$func_to_host_file_result"
3283dd0822caSmrg}
3284dd0822caSmrg# end func_convert_file_nix_to_w32
3285dd0822caSmrg
3286dd0822caSmrg
3287dd0822caSmrg# func_convert_file_msys_to_cygwin ARG
3288dd0822caSmrg# Convert file name ARG from MSYS to Cygwin format.  Requires LT_CYGPATH set.
3289dd0822caSmrg# Returns result in func_to_host_file_result.
3290dd0822caSmrgfunc_convert_file_msys_to_cygwin ()
3291dd0822caSmrg{
32921a9c160aSmrg  $debug_cmd
32931a9c160aSmrg
32941a9c160aSmrg  func_to_host_file_result=$1
3295dd0822caSmrg  if test -n "$1"; then
3296dd0822caSmrg    func_convert_core_msys_to_w32 "$1"
3297dd0822caSmrg    func_cygpath -u "$func_convert_core_msys_to_w32_result"
32981a9c160aSmrg    func_to_host_file_result=$func_cygpath_result
3299dd0822caSmrg  fi
3300dd0822caSmrg  func_convert_file_check "$1" "$func_to_host_file_result"
3301dd0822caSmrg}
3302dd0822caSmrg# end func_convert_file_msys_to_cygwin
3303dd0822caSmrg
3304dd0822caSmrg
3305dd0822caSmrg# func_convert_file_nix_to_cygwin ARG
3306dd0822caSmrg# Convert file name ARG from *nix to Cygwin format.  Requires Cygwin installed
3307dd0822caSmrg# in a wine environment, working winepath, and LT_CYGPATH set.  Returns result
3308dd0822caSmrg# in func_to_host_file_result.
3309dd0822caSmrgfunc_convert_file_nix_to_cygwin ()
3310dd0822caSmrg{
33111a9c160aSmrg  $debug_cmd
33121a9c160aSmrg
33131a9c160aSmrg  func_to_host_file_result=$1
3314dd0822caSmrg  if test -n "$1"; then
3315dd0822caSmrg    # convert from *nix to w32, then use cygpath to convert from w32 to cygwin.
3316dd0822caSmrg    func_convert_core_file_wine_to_w32 "$1"
3317dd0822caSmrg    func_cygpath -u "$func_convert_core_file_wine_to_w32_result"
33181a9c160aSmrg    func_to_host_file_result=$func_cygpath_result
3319dd0822caSmrg  fi
3320dd0822caSmrg  func_convert_file_check "$1" "$func_to_host_file_result"
3321dd0822caSmrg}
3322dd0822caSmrg# end func_convert_file_nix_to_cygwin
3323dd0822caSmrg
3324dd0822caSmrg
3325dd0822caSmrg#############################################
3326dd0822caSmrg# $build to $host PATH CONVERSION FUNCTIONS #
3327dd0822caSmrg#############################################
33281a9c160aSmrg# invoked via '$to_host_path_cmd ARG'
3329dd0822caSmrg#
3330dd0822caSmrg# In each case, ARG is the path to be converted from $build to $host format.
3331dd0822caSmrg# The result will be available in $func_to_host_path_result.
3332dd0822caSmrg#
3333dd0822caSmrg# Path separators are also converted from $build format to $host format.  If
3334dd0822caSmrg# ARG begins or ends with a path separator character, it is preserved (but
3335dd0822caSmrg# converted to $host format) on output.
3336dd0822caSmrg#
3337dd0822caSmrg# All path conversion functions are named using the following convention:
3338dd0822caSmrg#   file name conversion function    : func_convert_file_X_to_Y ()
3339dd0822caSmrg#   path conversion function         : func_convert_path_X_to_Y ()
3340dd0822caSmrg# where, for any given $build/$host combination the 'X_to_Y' value is the
3341dd0822caSmrg# same.  If conversion functions are added for new $build/$host combinations,
3342dd0822caSmrg# the two new functions must follow this pattern, or func_init_to_host_path_cmd
3343dd0822caSmrg# will break.
3344dd0822caSmrg
3345dd0822caSmrg
3346dd0822caSmrg# func_init_to_host_path_cmd
3347dd0822caSmrg# Ensures that function "pointer" variable $to_host_path_cmd is set to the
3348dd0822caSmrg# appropriate value, based on the value of $to_host_file_cmd.
3349dd0822caSmrgto_host_path_cmd=
3350dd0822caSmrgfunc_init_to_host_path_cmd ()
3351dd0822caSmrg{
33521a9c160aSmrg  $debug_cmd
33531a9c160aSmrg
3354dd0822caSmrg  if test -z "$to_host_path_cmd"; then
3355dd0822caSmrg    func_stripname 'func_convert_file_' '' "$to_host_file_cmd"
33561a9c160aSmrg    to_host_path_cmd=func_convert_path_$func_stripname_result
3357dd0822caSmrg  fi
3358dd0822caSmrg}
3359dd0822caSmrg
3360dd0822caSmrg
3361dd0822caSmrg# func_to_host_path ARG
3362dd0822caSmrg# Converts the path ARG from $build format to $host format. Return result
3363dd0822caSmrg# in func_to_host_path_result.
3364dd0822caSmrgfunc_to_host_path ()
3365dd0822caSmrg{
33661a9c160aSmrg  $debug_cmd
33671a9c160aSmrg
3368dd0822caSmrg  func_init_to_host_path_cmd
3369dd0822caSmrg  $to_host_path_cmd "$1"
3370dd0822caSmrg}
3371dd0822caSmrg# end func_to_host_path
3372dd0822caSmrg
3373dd0822caSmrg
3374dd0822caSmrg# func_convert_path_noop ARG
3375dd0822caSmrg# Copy ARG to func_to_host_path_result.
3376dd0822caSmrgfunc_convert_path_noop ()
3377dd0822caSmrg{
33781a9c160aSmrg  func_to_host_path_result=$1
3379dd0822caSmrg}
3380dd0822caSmrg# end func_convert_path_noop
3381dd0822caSmrg
3382dd0822caSmrg
3383dd0822caSmrg# func_convert_path_msys_to_w32 ARG
3384dd0822caSmrg# Convert path ARG from (mingw) MSYS to (mingw) w32 format; automatic
3385dd0822caSmrg# conversion to w32 is not available inside the cwrapper.  Returns result in
3386dd0822caSmrg# func_to_host_path_result.
3387dd0822caSmrgfunc_convert_path_msys_to_w32 ()
3388dd0822caSmrg{
33891a9c160aSmrg  $debug_cmd
33901a9c160aSmrg
33911a9c160aSmrg  func_to_host_path_result=$1
3392dd0822caSmrg  if test -n "$1"; then
3393dd0822caSmrg    # Remove leading and trailing path separator characters from ARG.  MSYS
3394dd0822caSmrg    # behavior is inconsistent here; cygpath turns them into '.;' and ';.';
3395dd0822caSmrg    # and winepath ignores them completely.
3396dd0822caSmrg    func_stripname : : "$1"
3397dd0822caSmrg    func_to_host_path_tmp1=$func_stripname_result
3398dd0822caSmrg    func_convert_core_msys_to_w32 "$func_to_host_path_tmp1"
33991a9c160aSmrg    func_to_host_path_result=$func_convert_core_msys_to_w32_result
3400dd0822caSmrg    func_convert_path_check : ";" \
3401dd0822caSmrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
3402dd0822caSmrg    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
3403dd0822caSmrg  fi
3404dd0822caSmrg}
3405dd0822caSmrg# end func_convert_path_msys_to_w32
3406dd0822caSmrg
3407dd0822caSmrg
3408dd0822caSmrg# func_convert_path_cygwin_to_w32 ARG
3409dd0822caSmrg# Convert path ARG from Cygwin to w32 format.  Returns result in
3410dd0822caSmrg# func_to_host_file_result.
3411dd0822caSmrgfunc_convert_path_cygwin_to_w32 ()
3412dd0822caSmrg{
34131a9c160aSmrg  $debug_cmd
34141a9c160aSmrg
34151a9c160aSmrg  func_to_host_path_result=$1
3416dd0822caSmrg  if test -n "$1"; then
3417dd0822caSmrg    # See func_convert_path_msys_to_w32:
3418dd0822caSmrg    func_stripname : : "$1"
3419dd0822caSmrg    func_to_host_path_tmp1=$func_stripname_result
3420dd0822caSmrg    func_to_host_path_result=`cygpath -m -p "$func_to_host_path_tmp1"`
3421dd0822caSmrg    func_convert_path_check : ";" \
3422dd0822caSmrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
3423dd0822caSmrg    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
3424dd0822caSmrg  fi
3425dd0822caSmrg}
3426dd0822caSmrg# end func_convert_path_cygwin_to_w32
3427dd0822caSmrg
3428dd0822caSmrg
3429dd0822caSmrg# func_convert_path_nix_to_w32 ARG
3430dd0822caSmrg# Convert path ARG from *nix to w32 format.  Requires a wine environment and
3431dd0822caSmrg# a working winepath.  Returns result in func_to_host_file_result.
3432dd0822caSmrgfunc_convert_path_nix_to_w32 ()
3433dd0822caSmrg{
34341a9c160aSmrg  $debug_cmd
34351a9c160aSmrg
34361a9c160aSmrg  func_to_host_path_result=$1
3437dd0822caSmrg  if test -n "$1"; then
3438dd0822caSmrg    # See func_convert_path_msys_to_w32:
3439dd0822caSmrg    func_stripname : : "$1"
3440dd0822caSmrg    func_to_host_path_tmp1=$func_stripname_result
3441dd0822caSmrg    func_convert_core_path_wine_to_w32 "$func_to_host_path_tmp1"
34421a9c160aSmrg    func_to_host_path_result=$func_convert_core_path_wine_to_w32_result
3443dd0822caSmrg    func_convert_path_check : ";" \
3444dd0822caSmrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
3445dd0822caSmrg    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
3446dd0822caSmrg  fi
3447dd0822caSmrg}
3448dd0822caSmrg# end func_convert_path_nix_to_w32
3449dd0822caSmrg
3450dd0822caSmrg
3451dd0822caSmrg# func_convert_path_msys_to_cygwin ARG
3452dd0822caSmrg# Convert path ARG from MSYS to Cygwin format.  Requires LT_CYGPATH set.
3453dd0822caSmrg# Returns result in func_to_host_file_result.
3454dd0822caSmrgfunc_convert_path_msys_to_cygwin ()
3455dd0822caSmrg{
34561a9c160aSmrg  $debug_cmd
34571a9c160aSmrg
34581a9c160aSmrg  func_to_host_path_result=$1
3459dd0822caSmrg  if test -n "$1"; then
3460dd0822caSmrg    # See func_convert_path_msys_to_w32:
3461dd0822caSmrg    func_stripname : : "$1"
3462dd0822caSmrg    func_to_host_path_tmp1=$func_stripname_result
3463dd0822caSmrg    func_convert_core_msys_to_w32 "$func_to_host_path_tmp1"
3464dd0822caSmrg    func_cygpath -u -p "$func_convert_core_msys_to_w32_result"
34651a9c160aSmrg    func_to_host_path_result=$func_cygpath_result
3466dd0822caSmrg    func_convert_path_check : : \
3467dd0822caSmrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
3468dd0822caSmrg    func_convert_path_front_back_pathsep ":*" "*:" : "$1"
3469dd0822caSmrg  fi
3470dd0822caSmrg}
3471dd0822caSmrg# end func_convert_path_msys_to_cygwin
3472dd0822caSmrg
3473dd0822caSmrg
3474dd0822caSmrg# func_convert_path_nix_to_cygwin ARG
3475dd0822caSmrg# Convert path ARG from *nix to Cygwin format.  Requires Cygwin installed in a
3476dd0822caSmrg# a wine environment, working winepath, and LT_CYGPATH set.  Returns result in
3477dd0822caSmrg# func_to_host_file_result.
3478dd0822caSmrgfunc_convert_path_nix_to_cygwin ()
3479dd0822caSmrg{
34801a9c160aSmrg  $debug_cmd
34811a9c160aSmrg
34821a9c160aSmrg  func_to_host_path_result=$1
3483dd0822caSmrg  if test -n "$1"; then
3484dd0822caSmrg    # Remove leading and trailing path separator characters from
3485dd0822caSmrg    # ARG. msys behavior is inconsistent here, cygpath turns them
3486dd0822caSmrg    # into '.;' and ';.', and winepath ignores them completely.
3487dd0822caSmrg    func_stripname : : "$1"
3488dd0822caSmrg    func_to_host_path_tmp1=$func_stripname_result
3489dd0822caSmrg    func_convert_core_path_wine_to_w32 "$func_to_host_path_tmp1"
3490dd0822caSmrg    func_cygpath -u -p "$func_convert_core_path_wine_to_w32_result"
34911a9c160aSmrg    func_to_host_path_result=$func_cygpath_result
3492dd0822caSmrg    func_convert_path_check : : \
3493dd0822caSmrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
3494dd0822caSmrg    func_convert_path_front_back_pathsep ":*" "*:" : "$1"
3495dd0822caSmrg  fi
3496dd0822caSmrg}
3497dd0822caSmrg# end func_convert_path_nix_to_cygwin
3498dd0822caSmrg
3499dd0822caSmrg
35001a9c160aSmrg# func_dll_def_p FILE
35011a9c160aSmrg# True iff FILE is a Windows DLL '.def' file.
35021a9c160aSmrg# Keep in sync with _LT_DLL_DEF_P in libtool.m4
35031a9c160aSmrgfunc_dll_def_p ()
35041a9c160aSmrg{
35051a9c160aSmrg  $debug_cmd
35061a9c160aSmrg
35071a9c160aSmrg  func_dll_def_p_tmp=`$SED -n \
35081a9c160aSmrg    -e 's/^[	 ]*//' \
35091a9c160aSmrg    -e '/^\(;.*\)*$/d' \
35101a9c160aSmrg    -e 's/^\(EXPORTS\|LIBRARY\)\([	 ].*\)*$/DEF/p' \
35111a9c160aSmrg    -e q \
35121a9c160aSmrg    "$1"`
35131a9c160aSmrg  test DEF = "$func_dll_def_p_tmp"
35141a9c160aSmrg}
35151a9c160aSmrg
35161a9c160aSmrg
3517dc407927Smrg# func_mode_compile arg...
3518dc407927Smrgfunc_mode_compile ()
3519dc407927Smrg{
35201a9c160aSmrg    $debug_cmd
35211a9c160aSmrg
3522dc407927Smrg    # Get the compilation command and the source file.
3523dc407927Smrg    base_compile=
35241a9c160aSmrg    srcfile=$nonopt  #  always keep a non-empty value in "srcfile"
3525dc407927Smrg    suppress_opt=yes
3526dc407927Smrg    suppress_output=
3527dc407927Smrg    arg_mode=normal
3528dc407927Smrg    libobj=
3529dc407927Smrg    later=
3530dc407927Smrg    pie_flag=
3531dc407927Smrg
3532dc407927Smrg    for arg
3533dc407927Smrg    do
3534dc407927Smrg      case $arg_mode in
3535dc407927Smrg      arg  )
3536dc407927Smrg	# do not "continue".  Instead, add this to base_compile
35371a9c160aSmrg	lastarg=$arg
3538dc407927Smrg	arg_mode=normal
3539dc407927Smrg	;;
3540dc407927Smrg
3541dc407927Smrg      target )
35421a9c160aSmrg	libobj=$arg
3543dc407927Smrg	arg_mode=normal
3544dc407927Smrg	continue
3545dc407927Smrg	;;
3546dc407927Smrg
3547dc407927Smrg      normal )
3548dc407927Smrg	# Accept any command-line options.
3549dc407927Smrg	case $arg in
3550dc407927Smrg	-o)
3551dc407927Smrg	  test -n "$libobj" && \
35521a9c160aSmrg	    func_fatal_error "you cannot specify '-o' more than once"
3553dc407927Smrg	  arg_mode=target
3554dc407927Smrg	  continue
3555dc407927Smrg	  ;;
3556dc407927Smrg
3557dc407927Smrg	-pie | -fpie | -fPIE)
3558dd0822caSmrg          func_append pie_flag " $arg"
3559dc407927Smrg	  continue
3560dc407927Smrg	  ;;
3561dc407927Smrg
3562dc407927Smrg	-shared | -static | -prefer-pic | -prefer-non-pic)
3563dd0822caSmrg	  func_append later " $arg"
3564dc407927Smrg	  continue
3565dc407927Smrg	  ;;
3566dc407927Smrg
3567dc407927Smrg	-no-suppress)
35683eed67faSmbalmer	  suppress_opt=no
35693eed67faSmbalmer	  continue
35703eed67faSmbalmer	  ;;
35713eed67faSmbalmer
35723eed67faSmbalmer	-Xcompiler)
35733eed67faSmbalmer	  arg_mode=arg  #  the next one goes into the "base_compile" arg list
35743eed67faSmbalmer	  continue      #  The current "srcfile" will either be retained or
35753eed67faSmbalmer	  ;;            #  replaced later.  I would guess that would be a bug.
35763eed67faSmbalmer
35773eed67faSmbalmer	-Wc,*)
3578dc407927Smrg	  func_stripname '-Wc,' '' "$arg"
3579dc407927Smrg	  args=$func_stripname_result
35803eed67faSmbalmer	  lastarg=
35811a9c160aSmrg	  save_ifs=$IFS; IFS=,
3582dc407927Smrg	  for arg in $args; do
35831a9c160aSmrg	    IFS=$save_ifs
3584dd0822caSmrg	    func_append_quoted lastarg "$arg"
35853eed67faSmbalmer	  done
35861a9c160aSmrg	  IFS=$save_ifs
3587dc407927Smrg	  func_stripname ' ' '' "$lastarg"
3588dc407927Smrg	  lastarg=$func_stripname_result
35893eed67faSmbalmer
35903eed67faSmbalmer	  # Add the arguments to base_compile.
3591dd0822caSmrg	  func_append base_compile " $lastarg"
35923eed67faSmbalmer	  continue
35933eed67faSmbalmer	  ;;
35943eed67faSmbalmer
3595dc407927Smrg	*)
35963eed67faSmbalmer	  # Accept the current argument as the source file.
35973eed67faSmbalmer	  # The previous "srcfile" becomes the current argument.
35983eed67faSmbalmer	  #
35991a9c160aSmrg	  lastarg=$srcfile
36001a9c160aSmrg	  srcfile=$arg
36013eed67faSmbalmer	  ;;
36023eed67faSmbalmer	esac  #  case $arg
36033eed67faSmbalmer	;;
36043eed67faSmbalmer      esac    #  case $arg_mode
36053eed67faSmbalmer
36063eed67faSmbalmer      # Aesthetically quote the previous argument.
3607dd0822caSmrg      func_append_quoted base_compile "$lastarg"
36083eed67faSmbalmer    done # for arg
36093eed67faSmbalmer
36103eed67faSmbalmer    case $arg_mode in
36113eed67faSmbalmer    arg)
3612dc407927Smrg      func_fatal_error "you must specify an argument for -Xcompile"
36133eed67faSmbalmer      ;;
36143eed67faSmbalmer    target)
36151a9c160aSmrg      func_fatal_error "you must specify a target with '-o'"
36163eed67faSmbalmer      ;;
36173eed67faSmbalmer    *)
36183eed67faSmbalmer      # Get the name of the library object.
3619dc407927Smrg      test -z "$libobj" && {
3620dc407927Smrg	func_basename "$srcfile"
36211a9c160aSmrg	libobj=$func_basename_result
3622dc407927Smrg      }
36233eed67faSmbalmer      ;;
36243eed67faSmbalmer    esac
36253eed67faSmbalmer
36263eed67faSmbalmer    # Recognize several different file suffixes.
36273eed67faSmbalmer    # If the user specifies -o file.o, it is replaced with file.lo
36283eed67faSmbalmer    case $libobj in
3629dc407927Smrg    *.[cCFSifmso] | \
3630dc407927Smrg    *.ada | *.adb | *.ads | *.asm | \
3631dc407927Smrg    *.c++ | *.cc | *.ii | *.class | *.cpp | *.cxx | \
363275cbef56Smrg    *.[fF][09]? | *.for | *.java | *.go | *.obj | *.sx | *.cu | *.cup)
3633dc407927Smrg      func_xform "$libobj"
3634dc407927Smrg      libobj=$func_xform_result
3635dc407927Smrg      ;;
36363eed67faSmbalmer    esac
36373eed67faSmbalmer
36383eed67faSmbalmer    case $libobj in
3639dc407927Smrg    *.lo) func_lo2o "$libobj"; obj=$func_lo2o_result ;;
36403eed67faSmbalmer    *)
36411a9c160aSmrg      func_fatal_error "cannot determine name of library object from '$libobj'"
36423eed67faSmbalmer      ;;
36433eed67faSmbalmer    esac
36443eed67faSmbalmer
36453eed67faSmbalmer    func_infer_tag $base_compile
36463eed67faSmbalmer
36473eed67faSmbalmer    for arg in $later; do
36483eed67faSmbalmer      case $arg in
3649dc407927Smrg      -shared)
36501a9c160aSmrg	test yes = "$build_libtool_libs" \
36511a9c160aSmrg	  || func_fatal_configuration "cannot build a shared library"
3652dc407927Smrg	build_old_libs=no
3653dc407927Smrg	continue
3654dc407927Smrg	;;
3655dc407927Smrg
36563eed67faSmbalmer      -static)
3657dc407927Smrg	build_libtool_libs=no
36583eed67faSmbalmer	build_old_libs=yes
36593eed67faSmbalmer	continue
36603eed67faSmbalmer	;;
36613eed67faSmbalmer
36623eed67faSmbalmer      -prefer-pic)
36633eed67faSmbalmer	pic_mode=yes
36643eed67faSmbalmer	continue
36653eed67faSmbalmer	;;
36663eed67faSmbalmer
36673eed67faSmbalmer      -prefer-non-pic)
36683eed67faSmbalmer	pic_mode=no
36693eed67faSmbalmer	continue
36703eed67faSmbalmer	;;
36713eed67faSmbalmer      esac
36723eed67faSmbalmer    done
36733eed67faSmbalmer
3674621f50c3Smrg    func_quote_arg pretty "$libobj"
3675621f50c3Smrg    test "X$libobj" != "X$func_quote_arg_result" \
3676dc407927Smrg      && $ECHO "X$libobj" | $GREP '[]~#^*{};<>?"'"'"'	 &()|`$[]' \
36771a9c160aSmrg      && func_warning "libobj name '$libobj' may not contain shell special characters."
3678dc407927Smrg    func_dirname_and_basename "$obj" "/" ""
36791a9c160aSmrg    objname=$func_basename_result
36801a9c160aSmrg    xdir=$func_dirname_result
36811a9c160aSmrg    lobj=$xdir$objdir/$objname
36823eed67faSmbalmer
3683dc407927Smrg    test -z "$base_compile" && \
3684dc407927Smrg      func_fatal_help "you must specify a compilation command"
36853eed67faSmbalmer
36863eed67faSmbalmer    # Delete any leftover library objects.
36871a9c160aSmrg    if test yes = "$build_old_libs"; then
36883eed67faSmbalmer      removelist="$obj $lobj $libobj ${libobj}T"
36893eed67faSmbalmer    else
36903eed67faSmbalmer      removelist="$lobj $libobj ${libobj}T"
36913eed67faSmbalmer    fi
36923eed67faSmbalmer
36933eed67faSmbalmer    # On Cygwin there's no "real" PIC flag so we must build both object types
36943eed67faSmbalmer    case $host_os in
3695dc407927Smrg    cygwin* | mingw* | pw32* | os2* | cegcc*)
36963eed67faSmbalmer      pic_mode=default
36973eed67faSmbalmer      ;;
36983eed67faSmbalmer    esac
36991a9c160aSmrg    if test no = "$pic_mode" && test pass_all != "$deplibs_check_method"; then
37003eed67faSmbalmer      # non-PIC code in shared libraries is not supported
37013eed67faSmbalmer      pic_mode=default
37023eed67faSmbalmer    fi
37033eed67faSmbalmer
37043eed67faSmbalmer    # Calculate the filename of the output object if compiler does
37053eed67faSmbalmer    # not support -o with -c
37061a9c160aSmrg    if test no = "$compiler_c_o"; then
37071a9c160aSmrg      output_obj=`$ECHO "$srcfile" | $SED 's%^.*/%%; s%\.[^.]*$%%'`.$objext
37081a9c160aSmrg      lockfile=$output_obj.lock
37093eed67faSmbalmer    else
37103eed67faSmbalmer      output_obj=
37113eed67faSmbalmer      need_locks=no
37123eed67faSmbalmer      lockfile=
37133eed67faSmbalmer    fi
37143eed67faSmbalmer
37153eed67faSmbalmer    # Lock this critical section if it is needed
37163eed67faSmbalmer    # We use this script file to make the link, it avoids creating a new file
37171a9c160aSmrg    if test yes = "$need_locks"; then
3718dc407927Smrg      until $opt_dry_run || ln "$progpath" "$lockfile" 2>/dev/null; do
3719dc407927Smrg	func_echo "Waiting for $lockfile to be removed"
37203eed67faSmbalmer	sleep 2
37213eed67faSmbalmer      done
37221a9c160aSmrg    elif test warn = "$need_locks"; then
37233eed67faSmbalmer      if test -f "$lockfile"; then
3724dc407927Smrg	$ECHO "\
37253eed67faSmbalmer*** ERROR, $lockfile exists and contains:
37263eed67faSmbalmer`cat $lockfile 2>/dev/null`
37273eed67faSmbalmer
37283eed67faSmbalmerThis indicates that another process is trying to use the same
37293eed67faSmbalmertemporary object file, and libtool could not work around it because
37301a9c160aSmrgyour compiler does not support '-c' and '-o' together.  If you
37313eed67faSmbalmerrepeat this compilation, it may succeed, by chance, but you had better
37323eed67faSmbalmeravoid parallel builds (make -j) in this platform, or get a better
37333eed67faSmbalmercompiler."
37343eed67faSmbalmer
3735dc407927Smrg	$opt_dry_run || $RM $removelist
37363eed67faSmbalmer	exit $EXIT_FAILURE
37373eed67faSmbalmer      fi
3738dd0822caSmrg      func_append removelist " $output_obj"
3739dc407927Smrg      $ECHO "$srcfile" > "$lockfile"
37403eed67faSmbalmer    fi
37413eed67faSmbalmer
3742dc407927Smrg    $opt_dry_run || $RM $removelist
3743dd0822caSmrg    func_append removelist " $lockfile"
3744dc407927Smrg    trap '$opt_dry_run || $RM $removelist; exit $EXIT_FAILURE' 1 2 15
3745dc407927Smrg
3746dd0822caSmrg    func_to_tool_file "$srcfile" func_convert_file_msys_to_w32
3747dd0822caSmrg    srcfile=$func_to_tool_file_result
3748621f50c3Smrg    func_quote_arg pretty "$srcfile"
3749621f50c3Smrg    qsrcfile=$func_quote_arg_result
37503eed67faSmbalmer
37513eed67faSmbalmer    # Only build a PIC object if we are building libtool libraries.
37521a9c160aSmrg    if test yes = "$build_libtool_libs"; then
37533eed67faSmbalmer      # Without this assignment, base_compile gets emptied.
37543eed67faSmbalmer      fbsd_hideous_sh_bug=$base_compile
37553eed67faSmbalmer
37561a9c160aSmrg      if test no != "$pic_mode"; then
37573eed67faSmbalmer	command="$base_compile $qsrcfile $pic_flag"
37583eed67faSmbalmer      else
37593eed67faSmbalmer	# Don't build PIC code
37603eed67faSmbalmer	command="$base_compile $qsrcfile"
37613eed67faSmbalmer      fi
37623eed67faSmbalmer
3763dc407927Smrg      func_mkdir_p "$xdir$objdir"
37643eed67faSmbalmer
37653eed67faSmbalmer      if test -z "$output_obj"; then
37663eed67faSmbalmer	# Place PIC objects in $objdir
3767dd0822caSmrg	func_append command " -o $lobj"
37683eed67faSmbalmer      fi
37693eed67faSmbalmer
3770dc407927Smrg      func_show_eval_locale "$command"	\
3771dc407927Smrg          'test -n "$output_obj" && $RM $removelist; exit $EXIT_FAILURE'
37723eed67faSmbalmer
37731a9c160aSmrg      if test warn = "$need_locks" &&
37743eed67faSmbalmer	 test "X`cat $lockfile 2>/dev/null`" != "X$srcfile"; then
3775dc407927Smrg	$ECHO "\
37763eed67faSmbalmer*** ERROR, $lockfile contains:
37773eed67faSmbalmer`cat $lockfile 2>/dev/null`
37783eed67faSmbalmer
37793eed67faSmbalmerbut it should contain:
37803eed67faSmbalmer$srcfile
37813eed67faSmbalmer
37823eed67faSmbalmerThis indicates that another process is trying to use the same
37833eed67faSmbalmertemporary object file, and libtool could not work around it because
37841a9c160aSmrgyour compiler does not support '-c' and '-o' together.  If you
37853eed67faSmbalmerrepeat this compilation, it may succeed, by chance, but you had better
37863eed67faSmbalmeravoid parallel builds (make -j) in this platform, or get a better
37873eed67faSmbalmercompiler."
37883eed67faSmbalmer
3789dc407927Smrg	$opt_dry_run || $RM $removelist
37903eed67faSmbalmer	exit $EXIT_FAILURE
37913eed67faSmbalmer      fi
37923eed67faSmbalmer
37933eed67faSmbalmer      # Just move the object if needed, then go on to compile the next one
37943eed67faSmbalmer      if test -n "$output_obj" && test "X$output_obj" != "X$lobj"; then
3795dc407927Smrg	func_show_eval '$MV "$output_obj" "$lobj"' \
3796dc407927Smrg	  'error=$?; $opt_dry_run || $RM $removelist; exit $error'
37973eed67faSmbalmer      fi
37983eed67faSmbalmer
37993eed67faSmbalmer      # Allow error messages only from the first compilation.
38001a9c160aSmrg      if test yes = "$suppress_opt"; then
3801dc407927Smrg	suppress_output=' >/dev/null 2>&1'
38023eed67faSmbalmer      fi
38033eed67faSmbalmer    fi
38043eed67faSmbalmer
38053eed67faSmbalmer    # Only build a position-dependent object if we build old libraries.
38061a9c160aSmrg    if test yes = "$build_old_libs"; then
38071a9c160aSmrg      if test yes != "$pic_mode"; then
38083eed67faSmbalmer	# Don't build PIC code
3809dc407927Smrg	command="$base_compile $qsrcfile$pie_flag"
38103eed67faSmbalmer      else
38113eed67faSmbalmer	command="$base_compile $qsrcfile $pic_flag"
38123eed67faSmbalmer      fi
38131a9c160aSmrg      if test yes = "$compiler_c_o"; then
3814dd0822caSmrg	func_append command " -o $obj"
38153eed67faSmbalmer      fi
38163eed67faSmbalmer
38173eed67faSmbalmer      # Suppress compiler output if we already did a PIC compilation.
3818dd0822caSmrg      func_append command "$suppress_output"
3819dc407927Smrg      func_show_eval_locale "$command" \
3820dc407927Smrg        '$opt_dry_run || $RM $removelist; exit $EXIT_FAILURE'
38213eed67faSmbalmer
38221a9c160aSmrg      if test warn = "$need_locks" &&
38233eed67faSmbalmer	 test "X`cat $lockfile 2>/dev/null`" != "X$srcfile"; then
3824dc407927Smrg	$ECHO "\
38253eed67faSmbalmer*** ERROR, $lockfile contains:
38263eed67faSmbalmer`cat $lockfile 2>/dev/null`
38273eed67faSmbalmer
38283eed67faSmbalmerbut it should contain:
38293eed67faSmbalmer$srcfile
38303eed67faSmbalmer
38313eed67faSmbalmerThis indicates that another process is trying to use the same
38323eed67faSmbalmertemporary object file, and libtool could not work around it because
38331a9c160aSmrgyour compiler does not support '-c' and '-o' together.  If you
38343eed67faSmbalmerrepeat this compilation, it may succeed, by chance, but you had better
38353eed67faSmbalmeravoid parallel builds (make -j) in this platform, or get a better
38363eed67faSmbalmercompiler."
38373eed67faSmbalmer
3838dc407927Smrg	$opt_dry_run || $RM $removelist
38393eed67faSmbalmer	exit $EXIT_FAILURE
38403eed67faSmbalmer      fi
38413eed67faSmbalmer
38423eed67faSmbalmer      # Just move the object if needed
38433eed67faSmbalmer      if test -n "$output_obj" && test "X$output_obj" != "X$obj"; then
3844dc407927Smrg	func_show_eval '$MV "$output_obj" "$obj"' \
3845dc407927Smrg	  'error=$?; $opt_dry_run || $RM $removelist; exit $error'
38463eed67faSmbalmer      fi
38473eed67faSmbalmer    fi
38483eed67faSmbalmer
3849dc407927Smrg    $opt_dry_run || {
3850dc407927Smrg      func_write_libtool_object "$libobj" "$objdir/$objname" "$objname"
38513eed67faSmbalmer
3852dc407927Smrg      # Unlock the critical section if it was locked
38531a9c160aSmrg      if test no != "$need_locks"; then
3854dc407927Smrg	removelist=$lockfile
3855dc407927Smrg        $RM "$lockfile"
3856dc407927Smrg      fi
3857dc407927Smrg    }
38583eed67faSmbalmer
38593eed67faSmbalmer    exit $EXIT_SUCCESS
3860dc407927Smrg}
38613eed67faSmbalmer
3862dc407927Smrg$opt_help || {
38631a9c160aSmrg  test compile = "$opt_mode" && func_mode_compile ${1+"$@"}
3864dc407927Smrg}
38653eed67faSmbalmer
3866dc407927Smrgfunc_mode_help ()
3867dc407927Smrg{
3868dc407927Smrg    # We need to display help for each of the modes.
3869dd0822caSmrg    case $opt_mode in
3870dc407927Smrg      "")
3871dc407927Smrg        # Generic help is extracted from the usage comments
3872dc407927Smrg        # at the start of this file.
3873dc407927Smrg        func_help
3874dc407927Smrg        ;;
38753eed67faSmbalmer
3876dc407927Smrg      clean)
3877dc407927Smrg        $ECHO \
3878dc407927Smrg"Usage: $progname [OPTION]... --mode=clean RM [RM-OPTION]... FILE...
38793eed67faSmbalmer
3880dc407927SmrgRemove files from the build directory.
38813eed67faSmbalmer
3882dc407927SmrgRM is the name of the program to use to delete files associated with each FILE
38831a9c160aSmrg(typically '/bin/rm').  RM-OPTIONS are options (such as '-f') to be passed
3884dc407927Smrgto RM.
38853eed67faSmbalmer
3886dc407927SmrgIf FILE is a libtool library, object or program, all the files associated
3887dc407927Smrgwith it are deleted. Otherwise, only FILE itself is deleted using RM."
3888dc407927Smrg        ;;
38893eed67faSmbalmer
3890dc407927Smrg      compile)
3891dc407927Smrg      $ECHO \
3892dc407927Smrg"Usage: $progname [OPTION]... --mode=compile COMPILE-COMMAND... SOURCEFILE
38933eed67faSmbalmer
3894dc407927SmrgCompile a source file into a libtool library object.
38953eed67faSmbalmer
3896dc407927SmrgThis mode accepts the following additional options:
38973eed67faSmbalmer
3898dc407927Smrg  -o OUTPUT-FILE    set the output file name to OUTPUT-FILE
3899dc407927Smrg  -no-suppress      do not suppress compiler output for multiple passes
3900dd0822caSmrg  -prefer-pic       try to build PIC objects only
3901dd0822caSmrg  -prefer-non-pic   try to build non-PIC objects only
39021a9c160aSmrg  -shared           do not build a '.o' file suitable for static linking
39031a9c160aSmrg  -static           only build a '.o' file suitable for static linking
3904621f50c3Smrg  -Wc,FLAG
3905621f50c3Smrg  -Xcompiler FLAG   pass FLAG directly to the compiler
39063eed67faSmbalmer
39071a9c160aSmrgCOMPILE-COMMAND is a command to be used in creating a 'standard' object file
3908dc407927Smrgfrom the given SOURCEFILE.
39093eed67faSmbalmer
3910dc407927SmrgThe output file name is determined by removing the directory component from
39111a9c160aSmrgSOURCEFILE, then substituting the C source code suffix '.c' with the
39121a9c160aSmrglibrary object suffix, '.lo'."
3913dc407927Smrg        ;;
39143eed67faSmbalmer
3915dc407927Smrg      execute)
3916dc407927Smrg        $ECHO \
3917dc407927Smrg"Usage: $progname [OPTION]... --mode=execute COMMAND [ARGS]...
39183eed67faSmbalmer
3919dc407927SmrgAutomatically set library path, then run a program.
39203eed67faSmbalmer
3921dc407927SmrgThis mode accepts the following additional options:
39223eed67faSmbalmer
3923dc407927Smrg  -dlopen FILE      add the directory containing FILE to the library path
39243eed67faSmbalmer
39251a9c160aSmrgThis mode sets the library path environment variable according to '-dlopen'
3926dc407927Smrgflags.
39273eed67faSmbalmer
3928dc407927SmrgIf any of the ARGS are libtool executable wrappers, then they are translated
3929dc407927Smrginto their corresponding uninstalled binary, and any of their required library
3930dc407927Smrgdirectories are added to the library path.
39313eed67faSmbalmer
3932dc407927SmrgThen, COMMAND is executed, with ARGS as arguments."
3933dc407927Smrg        ;;
39343eed67faSmbalmer
3935dc407927Smrg      finish)
3936dc407927Smrg        $ECHO \
3937dc407927Smrg"Usage: $progname [OPTION]... --mode=finish [LIBDIR]...
39383eed67faSmbalmer
3939dc407927SmrgComplete the installation of libtool libraries.
39403eed67faSmbalmer
3941dc407927SmrgEach LIBDIR is a directory that contains libtool libraries.
39423eed67faSmbalmer
3943dc407927SmrgThe commands that this mode executes may require superuser privileges.  Use
39441a9c160aSmrgthe '--dry-run' option if you just want to see what would be executed."
3945dc407927Smrg        ;;
39463eed67faSmbalmer
3947dc407927Smrg      install)
3948dc407927Smrg        $ECHO \
3949dc407927Smrg"Usage: $progname [OPTION]... --mode=install INSTALL-COMMAND...
39503eed67faSmbalmer
3951dc407927SmrgInstall executables or libraries.
39523eed67faSmbalmer
3953dc407927SmrgINSTALL-COMMAND is the installation command.  The first component should be
39541a9c160aSmrgeither the 'install' or 'cp' program.
39553eed67faSmbalmer
3956dc407927SmrgThe following components of INSTALL-COMMAND are treated specially:
39573eed67faSmbalmer
3958dd0822caSmrg  -inst-prefix-dir PREFIX-DIR  Use PREFIX-DIR as a staging area for installation
39593eed67faSmbalmer
3960dc407927SmrgThe rest of the components are interpreted as arguments to that command (only
3961dc407927SmrgBSD-compatible install options are recognized)."
3962dc407927Smrg        ;;
39633eed67faSmbalmer
3964dc407927Smrg      link)
3965dc407927Smrg        $ECHO \
3966dc407927Smrg"Usage: $progname [OPTION]... --mode=link LINK-COMMAND...
39673eed67faSmbalmer
3968dc407927SmrgLink object files or libraries together to form another library, or to
3969dc407927Smrgcreate an executable program.
39703eed67faSmbalmer
3971dc407927SmrgLINK-COMMAND is a command using the C compiler that you would use to create
3972dc407927Smrga program from several object files.
39733eed67faSmbalmer
3974dc407927SmrgThe following components of LINK-COMMAND are treated specially:
39753eed67faSmbalmer
3976dc407927Smrg  -all-static       do not do any dynamic linking at all
3977dc407927Smrg  -avoid-version    do not add a version suffix if possible
3978dd0822caSmrg  -bindir BINDIR    specify path to binaries directory (for systems where
3979dd0822caSmrg                    libraries must be found in the PATH setting at runtime)
39801a9c160aSmrg  -dlopen FILE      '-dlpreopen' FILE if it cannot be dlopened at runtime
3981dc407927Smrg  -dlpreopen FILE   link in FILE and add its symbols to lt_preloaded_symbols
3982dc407927Smrg  -export-dynamic   allow symbols from OUTPUT-FILE to be resolved with dlsym(3)
3983dc407927Smrg  -export-symbols SYMFILE
3984dc407927Smrg                    try to export only the symbols listed in SYMFILE
3985dc407927Smrg  -export-symbols-regex REGEX
3986dc407927Smrg                    try to export only the symbols matching REGEX
3987dc407927Smrg  -LLIBDIR          search LIBDIR for required installed libraries
3988dc407927Smrg  -lNAME            OUTPUT-FILE requires the installed library libNAME
3989dc407927Smrg  -module           build a library that can dlopened
3990dc407927Smrg  -no-fast-install  disable the fast-install mode
3991dc407927Smrg  -no-install       link a not-installable executable
3992dc407927Smrg  -no-undefined     declare that a library does not refer to external symbols
3993dc407927Smrg  -o OUTPUT-FILE    create OUTPUT-FILE from the specified objects
39941a9c160aSmrg  -objectlist FILE  use a list of object files found in FILE to specify objects
39951a9c160aSmrg  -os2dllname NAME  force a short DLL name on OS/2 (no effect on other OSes)
3996dc407927Smrg  -precious-files-regex REGEX
3997dc407927Smrg                    don't remove output files matching REGEX
3998dc407927Smrg  -release RELEASE  specify package release information
3999dc407927Smrg  -rpath LIBDIR     the created library will eventually be installed in LIBDIR
4000dc407927Smrg  -R[ ]LIBDIR       add LIBDIR to the runtime path of programs and libraries
4001dc407927Smrg  -shared           only do dynamic linking of libtool libraries
4002dc407927Smrg  -shrext SUFFIX    override the standard shared library file extension
4003dc407927Smrg  -static           do not do any dynamic linking of uninstalled libtool libraries
4004dc407927Smrg  -static-libtool-libs
4005dc407927Smrg                    do not do any dynamic linking of libtool libraries
4006dc407927Smrg  -version-info CURRENT[:REVISION[:AGE]]
4007dc407927Smrg                    specify library version info [each variable defaults to 0]
4008dc407927Smrg  -weak LIBNAME     declare that the target provides the LIBNAME interface
4009dd0822caSmrg  -Wc,FLAG
4010dd0822caSmrg  -Xcompiler FLAG   pass linker-specific FLAG directly to the compiler
4011621f50c3Smrg  -Wa,FLAG
4012621f50c3Smrg  -Xassembler FLAG  pass linker-specific FLAG directly to the assembler
4013dd0822caSmrg  -Wl,FLAG
4014dd0822caSmrg  -Xlinker FLAG     pass linker-specific FLAG directly to the linker
4015dd0822caSmrg  -XCClinker FLAG   pass link-specific FLAG to the compiler driver (CC)
40163eed67faSmbalmer
40171a9c160aSmrgAll other options (arguments beginning with '-') are ignored.
40183eed67faSmbalmer
40191a9c160aSmrgEvery other argument is treated as a filename.  Files ending in '.la' are
4020dc407927Smrgtreated as uninstalled libtool libraries, other files are standard or library
4021dc407927Smrgobject files.
40223eed67faSmbalmer
40231a9c160aSmrgIf the OUTPUT-FILE ends in '.la', then a libtool library is created,
40241a9c160aSmrgonly library objects ('.lo' files) may be specified, and '-rpath' is
4025dc407927Smrgrequired, except when creating a convenience library.
40263eed67faSmbalmer
40271a9c160aSmrgIf OUTPUT-FILE ends in '.a' or '.lib', then a standard library is created
40281a9c160aSmrgusing 'ar' and 'ranlib', or on Windows using 'lib'.
40293eed67faSmbalmer
40301a9c160aSmrgIf OUTPUT-FILE ends in '.lo' or '.$objext', then a reloadable object file
4031dc407927Smrgis created, otherwise an executable program is created."
40323eed67faSmbalmer        ;;
40333eed67faSmbalmer
4034dc407927Smrg      uninstall)
4035dc407927Smrg        $ECHO \
4036dc407927Smrg"Usage: $progname [OPTION]... --mode=uninstall RM [RM-OPTION]... FILE...
40373eed67faSmbalmer
4038dc407927SmrgRemove libraries from an installation directory.
40393eed67faSmbalmer
4040dc407927SmrgRM is the name of the program to use to delete files associated with each FILE
40411a9c160aSmrg(typically '/bin/rm').  RM-OPTIONS are options (such as '-f') to be passed
4042dc407927Smrgto RM.
40433eed67faSmbalmer
4044dc407927SmrgIf FILE is a libtool library, all the files associated with it are deleted.
4045dc407927SmrgOtherwise, only FILE itself is deleted using RM."
4046dc407927Smrg        ;;
40473eed67faSmbalmer
4048dc407927Smrg      *)
40491a9c160aSmrg        func_fatal_help "invalid operation mode '$opt_mode'"
4050dc407927Smrg        ;;
4051dc407927Smrg    esac
40523eed67faSmbalmer
4053dd0822caSmrg    echo
40541a9c160aSmrg    $ECHO "Try '$progname --help' for more information about other modes."
4055dc407927Smrg}
40563eed67faSmbalmer
4057dd0822caSmrg# Now that we've collected a possible --mode arg, show help if necessary
4058dd0822caSmrgif $opt_help; then
40591a9c160aSmrg  if test : = "$opt_help"; then
4060dd0822caSmrg    func_mode_help
4061dd0822caSmrg  else
4062dd0822caSmrg    {
4063dd0822caSmrg      func_help noexit
4064dd0822caSmrg      for opt_mode in compile link execute install finish uninstall clean; do
4065dd0822caSmrg	func_mode_help
4066dd0822caSmrg      done
40671a9c160aSmrg    } | $SED -n '1p; 2,$s/^Usage:/  or: /p'
4068dd0822caSmrg    {
4069dd0822caSmrg      func_help noexit
4070dd0822caSmrg      for opt_mode in compile link execute install finish uninstall clean; do
4071dd0822caSmrg	echo
4072dd0822caSmrg	func_mode_help
4073dd0822caSmrg      done
4074dd0822caSmrg    } |
40751a9c160aSmrg    $SED '1d
4076dd0822caSmrg      /^When reporting/,/^Report/{
4077dd0822caSmrg	H
4078dd0822caSmrg	d
4079dd0822caSmrg      }
4080dd0822caSmrg      $x
4081dd0822caSmrg      /information about other modes/d
4082dd0822caSmrg      /more detailed .*MODE/d
4083dd0822caSmrg      s/^Usage:.*--mode=\([^ ]*\) .*/Description of \1 mode:/'
4084dd0822caSmrg  fi
4085dd0822caSmrg  exit $?
4086dd0822caSmrgfi
40873eed67faSmbalmer
40883eed67faSmbalmer
4089dc407927Smrg# func_mode_execute arg...
4090dc407927Smrgfunc_mode_execute ()
4091dc407927Smrg{
40921a9c160aSmrg    $debug_cmd
40931a9c160aSmrg
4094dc407927Smrg    # The first argument is the command name.
40951a9c160aSmrg    cmd=$nonopt
4096dc407927Smrg    test -z "$cmd" && \
4097dc407927Smrg      func_fatal_help "you must specify a COMMAND"
40983eed67faSmbalmer
4099dc407927Smrg    # Handle -dlopen flags immediately.
4100dd0822caSmrg    for file in $opt_dlopen; do
4101dc407927Smrg      test -f "$file" \
41021a9c160aSmrg	|| func_fatal_help "'$file' is not a file"
41033eed67faSmbalmer
4104dc407927Smrg      dir=
4105dc407927Smrg      case $file in
4106dc407927Smrg      *.la)
4107dd0822caSmrg	func_resolve_sysroot "$file"
4108dd0822caSmrg	file=$func_resolve_sysroot_result
4109dd0822caSmrg
4110dc407927Smrg	# Check to see that this really is a libtool archive.
4111dc407927Smrg	func_lalib_unsafe_p "$file" \
41121a9c160aSmrg	  || func_fatal_help "'$lib' is not a valid libtool archive"
41133eed67faSmbalmer
4114dc407927Smrg	# Read the libtool library.
4115dc407927Smrg	dlname=
4116dc407927Smrg	library_names=
4117dc407927Smrg	func_source "$file"
41183eed67faSmbalmer
4119dc407927Smrg	# Skip this library if it cannot be dlopened.
4120dc407927Smrg	if test -z "$dlname"; then
4121dc407927Smrg	  # Warn if it was a shared library.
4122dc407927Smrg	  test -n "$library_names" && \
41231a9c160aSmrg	    func_warning "'$file' was not linked with '-export-dynamic'"
4124dc407927Smrg	  continue
4125dc407927Smrg	fi
41263eed67faSmbalmer
4127dc407927Smrg	func_dirname "$file" "" "."
41281a9c160aSmrg	dir=$func_dirname_result
41293eed67faSmbalmer
4130dc407927Smrg	if test -f "$dir/$objdir/$dlname"; then
4131dd0822caSmrg	  func_append dir "/$objdir"
4132dc407927Smrg	else
4133dc407927Smrg	  if test ! -f "$dir/$dlname"; then
41341a9c160aSmrg	    func_fatal_error "cannot find '$dlname' in '$dir' or '$dir/$objdir'"
4135dc407927Smrg	  fi
4136dc407927Smrg	fi
41373eed67faSmbalmer	;;
41383eed67faSmbalmer
4139dc407927Smrg      *.lo)
4140dc407927Smrg	# Just add the directory containing the .lo file.
4141dc407927Smrg	func_dirname "$file" "" "."
41421a9c160aSmrg	dir=$func_dirname_result
41433eed67faSmbalmer	;;
41443eed67faSmbalmer
4145dc407927Smrg      *)
41461a9c160aSmrg	func_warning "'-dlopen' is ignored for non-libtool libraries and objects"
41473eed67faSmbalmer	continue
41483eed67faSmbalmer	;;
4149dc407927Smrg      esac
41503eed67faSmbalmer
4151dc407927Smrg      # Get the absolute pathname.
4152dc407927Smrg      absdir=`cd "$dir" && pwd`
41531a9c160aSmrg      test -n "$absdir" && dir=$absdir
41543eed67faSmbalmer
4155dc407927Smrg      # Now add the directory to shlibpath_var.
4156dc407927Smrg      if eval "test -z \"\$$shlibpath_var\""; then
4157dc407927Smrg	eval "$shlibpath_var=\"\$dir\""
4158dc407927Smrg      else
4159dc407927Smrg	eval "$shlibpath_var=\"\$dir:\$$shlibpath_var\""
4160dc407927Smrg      fi
4161dc407927Smrg    done
41623eed67faSmbalmer
4163dc407927Smrg    # This variable tells wrapper scripts just to set shlibpath_var
4164dc407927Smrg    # rather than running their programs.
41651a9c160aSmrg    libtool_execute_magic=$magic
41663eed67faSmbalmer
4167dc407927Smrg    # Check if any of the arguments is a wrapper script.
4168dc407927Smrg    args=
4169dc407927Smrg    for file
4170dc407927Smrg    do
4171dc407927Smrg      case $file in
4172dd0822caSmrg      -* | *.la | *.lo ) ;;
4173dc407927Smrg      *)
4174dc407927Smrg	# Do a test to see if this is really a libtool program.
4175dc407927Smrg	if func_ltwrapper_script_p "$file"; then
4176dc407927Smrg	  func_source "$file"
4177dc407927Smrg	  # Transform arg to wrapped name.
41781a9c160aSmrg	  file=$progdir/$program
4179dc407927Smrg	elif func_ltwrapper_executable_p "$file"; then
4180dc407927Smrg	  func_ltwrapper_scriptname "$file"
4181dc407927Smrg	  func_source "$func_ltwrapper_scriptname_result"
4182dc407927Smrg	  # Transform arg to wrapped name.
41831a9c160aSmrg	  file=$progdir/$program
4184dc407927Smrg	fi
4185dc407927Smrg	;;
4186dc407927Smrg      esac
4187dc407927Smrg      # Quote arguments (to preserve shell metacharacters).
4188dd0822caSmrg      func_append_quoted args "$file"
4189dc407927Smrg    done
41903eed67faSmbalmer
41911a9c160aSmrg    if $opt_dry_run; then
41921a9c160aSmrg      # Display what would be done.
41931a9c160aSmrg      if test -n "$shlibpath_var"; then
41941a9c160aSmrg	eval "\$ECHO \"\$shlibpath_var=\$$shlibpath_var\""
41951a9c160aSmrg	echo "export $shlibpath_var"
41961a9c160aSmrg      fi
41971a9c160aSmrg      $ECHO "$cmd$args"
41981a9c160aSmrg      exit $EXIT_SUCCESS
41991a9c160aSmrg    else
4200dc407927Smrg      if test -n "$shlibpath_var"; then
4201dc407927Smrg	# Export the shlibpath_var.
4202dc407927Smrg	eval "export $shlibpath_var"
4203dc407927Smrg      fi
42043eed67faSmbalmer
4205dc407927Smrg      # Restore saved environment variables
4206dc407927Smrg      for lt_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES
4207dc407927Smrg      do
4208dc407927Smrg	eval "if test \"\${save_$lt_var+set}\" = set; then
4209dc407927Smrg                $lt_var=\$save_$lt_var; export $lt_var
4210dc407927Smrg	      else
4211dc407927Smrg		$lt_unset $lt_var
4212dc407927Smrg	      fi"
4213dc407927Smrg      done
42143eed67faSmbalmer
4215dc407927Smrg      # Now prepare to actually exec the command.
42161a9c160aSmrg      exec_cmd=\$cmd$args
4217dc407927Smrg    fi
4218dc407927Smrg}
42193eed67faSmbalmer
42201a9c160aSmrgtest execute = "$opt_mode" && func_mode_execute ${1+"$@"}
4221dd0822caSmrg
4222dd0822caSmrg
4223dd0822caSmrg# func_mode_finish arg...
4224dd0822caSmrgfunc_mode_finish ()
4225dd0822caSmrg{
42261a9c160aSmrg    $debug_cmd
42271a9c160aSmrg
4228dd0822caSmrg    libs=
4229dd0822caSmrg    libdirs=
4230dd0822caSmrg    admincmds=
4231dd0822caSmrg
4232dd0822caSmrg    for opt in "$nonopt" ${1+"$@"}
4233dd0822caSmrg    do
4234dd0822caSmrg      if test -d "$opt"; then
4235dd0822caSmrg	func_append libdirs " $opt"
4236dd0822caSmrg
4237dd0822caSmrg      elif test -f "$opt"; then
4238dd0822caSmrg	if func_lalib_unsafe_p "$opt"; then
4239dd0822caSmrg	  func_append libs " $opt"
4240dd0822caSmrg	else
42411a9c160aSmrg	  func_warning "'$opt' is not a valid libtool archive"
4242dd0822caSmrg	fi
4243dd0822caSmrg
4244dd0822caSmrg      else
42451a9c160aSmrg	func_fatal_error "invalid argument '$opt'"
4246dd0822caSmrg      fi
4247dd0822caSmrg    done
42483eed67faSmbalmer
4249dd0822caSmrg    if test -n "$libs"; then
4250dd0822caSmrg      if test -n "$lt_sysroot"; then
4251dd0822caSmrg        sysroot_regex=`$ECHO "$lt_sysroot" | $SED "$sed_make_literal_regex"`
4252dd0822caSmrg        sysroot_cmd="s/\([ ']\)$sysroot_regex/\1/g;"
4253dd0822caSmrg      else
4254dd0822caSmrg        sysroot_cmd=
4255dd0822caSmrg      fi
42563eed67faSmbalmer
4257dd0822caSmrg      # Remove sysroot references
4258dd0822caSmrg      if $opt_dry_run; then
4259dd0822caSmrg        for lib in $libs; do
42601a9c160aSmrg          echo "removing references to $lt_sysroot and '=' prefixes from $lib"
4261dd0822caSmrg        done
4262dd0822caSmrg      else
4263dd0822caSmrg        tmpdir=`func_mktempdir`
4264dd0822caSmrg        for lib in $libs; do
42651a9c160aSmrg	  $SED -e "$sysroot_cmd s/\([ ']-[LR]\)=/\1/g; s/\([ ']\)=/\1/g" $lib \
4266dd0822caSmrg	    > $tmpdir/tmp-la
4267dd0822caSmrg	  mv -f $tmpdir/tmp-la $lib
4268dd0822caSmrg	done
4269dd0822caSmrg        ${RM}r "$tmpdir"
4270dd0822caSmrg      fi
4271dd0822caSmrg    fi
42723eed67faSmbalmer
4273dc407927Smrg    if test -n "$finish_cmds$finish_eval" && test -n "$libdirs"; then
4274dc407927Smrg      for libdir in $libdirs; do
4275dc407927Smrg	if test -n "$finish_cmds"; then
4276dc407927Smrg	  # Do each command in the finish commands.
4277dc407927Smrg	  func_execute_cmds "$finish_cmds" 'admincmds="$admincmds
4278dc407927Smrg'"$cmd"'"'
4279dc407927Smrg	fi
4280dc407927Smrg	if test -n "$finish_eval"; then
4281dc407927Smrg	  # Do the single finish_eval.
4282dc407927Smrg	  eval cmds=\"$finish_eval\"
4283dd0822caSmrg	  $opt_dry_run || eval "$cmds" || func_append admincmds "
4284dc407927Smrg       $cmds"
4285dc407927Smrg	fi
4286dc407927Smrg      done
4287dc407927Smrg    fi
42883eed67faSmbalmer
4289dc407927Smrg    # Exit here if they wanted silent mode.
42901a9c160aSmrg    $opt_quiet && exit $EXIT_SUCCESS
42913eed67faSmbalmer
4292dd0822caSmrg    if test -n "$finish_cmds$finish_eval" && test -n "$libdirs"; then
4293dd0822caSmrg      echo "----------------------------------------------------------------------"
4294dd0822caSmrg      echo "Libraries have been installed in:"
4295dd0822caSmrg      for libdir in $libdirs; do
4296dd0822caSmrg	$ECHO "   $libdir"
4297dd0822caSmrg      done
4298dd0822caSmrg      echo
4299dd0822caSmrg      echo "If you ever happen to want to link against installed libraries"
4300dd0822caSmrg      echo "in a given directory, LIBDIR, you must either use libtool, and"
43011a9c160aSmrg      echo "specify the full pathname of the library, or use the '-LLIBDIR'"
4302dd0822caSmrg      echo "flag during linking and do at least one of the following:"
4303dd0822caSmrg      if test -n "$shlibpath_var"; then
43041a9c160aSmrg	echo "   - add LIBDIR to the '$shlibpath_var' environment variable"
4305dd0822caSmrg	echo "     during execution"
4306dd0822caSmrg      fi
4307dd0822caSmrg      if test -n "$runpath_var"; then
43081a9c160aSmrg	echo "   - add LIBDIR to the '$runpath_var' environment variable"
4309dd0822caSmrg	echo "     during linking"
4310dd0822caSmrg      fi
4311dd0822caSmrg      if test -n "$hardcode_libdir_flag_spec"; then
4312dd0822caSmrg	libdir=LIBDIR
4313dd0822caSmrg	eval flag=\"$hardcode_libdir_flag_spec\"
43143eed67faSmbalmer
43151a9c160aSmrg	$ECHO "   - use the '$flag' linker flag"
4316dd0822caSmrg      fi
4317dd0822caSmrg      if test -n "$admincmds"; then
4318dd0822caSmrg	$ECHO "   - have your system administrator run these commands:$admincmds"
4319dd0822caSmrg      fi
4320dd0822caSmrg      if test -f /etc/ld.so.conf; then
43211a9c160aSmrg	echo "   - have your system administrator add LIBDIR to '/etc/ld.so.conf'"
4322dd0822caSmrg      fi
4323dd0822caSmrg      echo
43243eed67faSmbalmer
4325dd0822caSmrg      echo "See any operating system documentation about shared libraries for"
4326dd0822caSmrg      case $host in
4327dd0822caSmrg	solaris2.[6789]|solaris2.1[0-9])
4328dd0822caSmrg	  echo "more information, such as the ld(1), crle(1) and ld.so(8) manual"
4329dd0822caSmrg	  echo "pages."
4330dd0822caSmrg	  ;;
4331dd0822caSmrg	*)
4332dd0822caSmrg	  echo "more information, such as the ld(1) and ld.so(8) manual pages."
4333dd0822caSmrg	  ;;
4334dd0822caSmrg      esac
4335dd0822caSmrg      echo "----------------------------------------------------------------------"
4336dd0822caSmrg    fi
4337dc407927Smrg    exit $EXIT_SUCCESS
4338dc407927Smrg}
43393eed67faSmbalmer
43401a9c160aSmrgtest finish = "$opt_mode" && func_mode_finish ${1+"$@"}
43413eed67faSmbalmer
4342dc407927Smrg
4343dc407927Smrg# func_mode_install arg...
4344dc407927Smrgfunc_mode_install ()
4345dc407927Smrg{
43461a9c160aSmrg    $debug_cmd
43471a9c160aSmrg
4348dc407927Smrg    # There may be an optional sh(1) argument at the beginning of
4349dc407927Smrg    # install_prog (especially on Windows NT).
43501a9c160aSmrg    if test "$SHELL" = "$nonopt" || test /bin/sh = "$nonopt" ||
4351dc407927Smrg       # Allow the use of GNU shtool's install command.
43521a9c160aSmrg       case $nonopt in *shtool*) :;; *) false;; esac
43531a9c160aSmrg    then
4354dc407927Smrg      # Aesthetically quote it.
4355621f50c3Smrg      func_quote_arg pretty "$nonopt"
4356621f50c3Smrg      install_prog="$func_quote_arg_result "
4357dc407927Smrg      arg=$1
4358dc407927Smrg      shift
4359dc407927Smrg    else
4360dc407927Smrg      install_prog=
4361dc407927Smrg      arg=$nonopt
4362dc407927Smrg    fi
4363dc407927Smrg
4364dc407927Smrg    # The real first argument should be the name of the installation program.
4365dc407927Smrg    # Aesthetically quote it.
4366621f50c3Smrg    func_quote_arg pretty "$arg"
4367621f50c3Smrg    func_append install_prog "$func_quote_arg_result"
4368dd0822caSmrg    install_shared_prog=$install_prog
4369dd0822caSmrg    case " $install_prog " in
4370dd0822caSmrg      *[\\\ /]cp\ *) install_cp=: ;;
4371dd0822caSmrg      *) install_cp=false ;;
4372dd0822caSmrg    esac
4373dc407927Smrg
4374dc407927Smrg    # We need to accept at least all the BSD install flags.
4375dc407927Smrg    dest=
4376dc407927Smrg    files=
4377dc407927Smrg    opts=
4378dc407927Smrg    prev=
4379dc407927Smrg    install_type=
43801a9c160aSmrg    isdir=false
4381dc407927Smrg    stripme=
4382dd0822caSmrg    no_mode=:
4383dc407927Smrg    for arg
4384dc407927Smrg    do
4385dd0822caSmrg      arg2=
4386dc407927Smrg      if test -n "$dest"; then
4387dd0822caSmrg	func_append files " $dest"
4388dc407927Smrg	dest=$arg
4389dc407927Smrg	continue
4390dc407927Smrg      fi
4391dc407927Smrg
4392dc407927Smrg      case $arg in
43931a9c160aSmrg      -d) isdir=: ;;
4394dc407927Smrg      -f)
4395dd0822caSmrg	if $install_cp; then :; else
4396dd0822caSmrg	  prev=$arg
4397dd0822caSmrg	fi
4398dc407927Smrg	;;
4399dc407927Smrg      -g | -m | -o)
4400dc407927Smrg	prev=$arg
4401dc407927Smrg	;;
4402dc407927Smrg      -s)
4403dc407927Smrg	stripme=" -s"
4404dc407927Smrg	continue
4405dc407927Smrg	;;
4406dc407927Smrg      -*)
4407dc407927Smrg	;;
4408dc407927Smrg      *)
4409dc407927Smrg	# If the previous option needed an argument, then skip it.
4410dc407927Smrg	if test -n "$prev"; then
44111a9c160aSmrg	  if test X-m = "X$prev" && test -n "$install_override_mode"; then
4412dd0822caSmrg	    arg2=$install_override_mode
4413dd0822caSmrg	    no_mode=false
4414dd0822caSmrg	  fi
44153eed67faSmbalmer	  prev=
44163eed67faSmbalmer	else
4417dc407927Smrg	  dest=$arg
4418dc407927Smrg	  continue
44193eed67faSmbalmer	fi
44203eed67faSmbalmer	;;
4421dc407927Smrg      esac
44223eed67faSmbalmer
4423dc407927Smrg      # Aesthetically quote the argument.
4424621f50c3Smrg      func_quote_arg pretty "$arg"
4425621f50c3Smrg      func_append install_prog " $func_quote_arg_result"
4426dd0822caSmrg      if test -n "$arg2"; then
4427621f50c3Smrg	func_quote_arg pretty "$arg2"
4428dd0822caSmrg      fi
4429621f50c3Smrg      func_append install_shared_prog " $func_quote_arg_result"
4430dc407927Smrg    done
44313eed67faSmbalmer
4432dc407927Smrg    test -z "$install_prog" && \
4433dc407927Smrg      func_fatal_help "you must specify an install program"
44343eed67faSmbalmer
4435dc407927Smrg    test -n "$prev" && \
44361a9c160aSmrg      func_fatal_help "the '$prev' option requires an argument"
44373eed67faSmbalmer
4438dd0822caSmrg    if test -n "$install_override_mode" && $no_mode; then
4439dd0822caSmrg      if $install_cp; then :; else
4440621f50c3Smrg	func_quote_arg pretty "$install_override_mode"
4441621f50c3Smrg	func_append install_shared_prog " -m $func_quote_arg_result"
4442dd0822caSmrg      fi
4443dd0822caSmrg    fi
4444dd0822caSmrg
4445dc407927Smrg    if test -z "$files"; then
4446dc407927Smrg      if test -z "$dest"; then
4447dc407927Smrg	func_fatal_help "no file or destination specified"
4448dc407927Smrg      else
4449dc407927Smrg	func_fatal_help "you must specify a destination"
4450dc407927Smrg      fi
44513eed67faSmbalmer    fi
44523eed67faSmbalmer
4453dc407927Smrg    # Strip any trailing slash from the destination.
4454dc407927Smrg    func_stripname '' '/' "$dest"
4455dc407927Smrg    dest=$func_stripname_result
44563eed67faSmbalmer
4457dc407927Smrg    # Check to see that the destination is a directory.
44581a9c160aSmrg    test -d "$dest" && isdir=:
44591a9c160aSmrg    if $isdir; then
44601a9c160aSmrg      destdir=$dest
4461dc407927Smrg      destname=
44623eed67faSmbalmer    else
4463dc407927Smrg      func_dirname_and_basename "$dest" "" "."
44641a9c160aSmrg      destdir=$func_dirname_result
44651a9c160aSmrg      destname=$func_basename_result
44663eed67faSmbalmer
4467dc407927Smrg      # Not a directory, so check to see that there is only one file specified.
4468dc407927Smrg      set dummy $files; shift
4469dc407927Smrg      test "$#" -gt 1 && \
44701a9c160aSmrg	func_fatal_help "'$dest' is not a directory"
44713eed67faSmbalmer    fi
4472dc407927Smrg    case $destdir in
4473dc407927Smrg    [\\/]* | [A-Za-z]:[\\/]*) ;;
44743eed67faSmbalmer    *)
4475dc407927Smrg      for file in $files; do
4476dc407927Smrg	case $file in
4477dc407927Smrg	*.lo) ;;
4478dc407927Smrg	*)
44791a9c160aSmrg	  func_fatal_help "'$destdir' must be an absolute directory name"
4480dc407927Smrg	  ;;
4481dc407927Smrg	esac
4482dc407927Smrg      done
44833eed67faSmbalmer      ;;
44843eed67faSmbalmer    esac
44853eed67faSmbalmer
4486dc407927Smrg    # This variable tells wrapper scripts just to set variables rather
4487dc407927Smrg    # than running their programs.
44881a9c160aSmrg    libtool_install_magic=$magic
44893eed67faSmbalmer
4490dc407927Smrg    staticlibs=
4491dc407927Smrg    future_libdirs=
4492dc407927Smrg    current_libdirs=
4493dc407927Smrg    for file in $files; do
44943eed67faSmbalmer
4495dc407927Smrg      # Do each installation.
4496dc407927Smrg      case $file in
4497dc407927Smrg      *.$libext)
4498dc407927Smrg	# Do the static libraries later.
4499dd0822caSmrg	func_append staticlibs " $file"
4500dc407927Smrg	;;
4501dc407927Smrg
4502dc407927Smrg      *.la)
4503dd0822caSmrg	func_resolve_sysroot "$file"
4504dd0822caSmrg	file=$func_resolve_sysroot_result
4505dd0822caSmrg
4506dc407927Smrg	# Check to see that this really is a libtool archive.
4507dc407927Smrg	func_lalib_unsafe_p "$file" \
45081a9c160aSmrg	  || func_fatal_help "'$file' is not a valid libtool archive"
4509dc407927Smrg
4510dc407927Smrg	library_names=
4511dc407927Smrg	old_library=
4512dc407927Smrg	relink_command=
4513dc407927Smrg	func_source "$file"
4514dc407927Smrg
4515dc407927Smrg	# Add the libdir to current_libdirs if it is the destination.
4516dc407927Smrg	if test "X$destdir" = "X$libdir"; then
4517dc407927Smrg	  case "$current_libdirs " in
4518dc407927Smrg	  *" $libdir "*) ;;
4519dd0822caSmrg	  *) func_append current_libdirs " $libdir" ;;
45203eed67faSmbalmer	  esac
4521dc407927Smrg	else
4522dc407927Smrg	  # Note the libdir as a future libdir.
4523dc407927Smrg	  case "$future_libdirs " in
4524dc407927Smrg	  *" $libdir "*) ;;
4525dd0822caSmrg	  *) func_append future_libdirs " $libdir" ;;
4526dc407927Smrg	  esac
4527dc407927Smrg	fi
45283eed67faSmbalmer
4529dc407927Smrg	func_dirname "$file" "/" ""
45301a9c160aSmrg	dir=$func_dirname_result
4531dd0822caSmrg	func_append dir "$objdir"
4532dc407927Smrg
4533dc407927Smrg	if test -n "$relink_command"; then
4534dc407927Smrg	  # Determine the prefix the user has applied to our future dir.
4535dd0822caSmrg	  inst_prefix_dir=`$ECHO "$destdir" | $SED -e "s%$libdir\$%%"`
4536dc407927Smrg
4537dc407927Smrg	  # Don't allow the user to place us outside of our expected
4538dc407927Smrg	  # location b/c this prevents finding dependent libraries that
4539dc407927Smrg	  # are installed to the same prefix.
4540dc407927Smrg	  # At present, this check doesn't affect windows .dll's that
4541dc407927Smrg	  # are installed into $libdir/../bin (currently, that works fine)
4542dc407927Smrg	  # but it's something to keep an eye on.
4543dc407927Smrg	  test "$inst_prefix_dir" = "$destdir" && \
45441a9c160aSmrg	    func_fatal_error "error: cannot install '$file' to a directory not ending in $libdir"
4545dc407927Smrg
4546dc407927Smrg	  if test -n "$inst_prefix_dir"; then
4547dc407927Smrg	    # Stick the inst_prefix_dir data into the link command.
4548dd0822caSmrg	    relink_command=`$ECHO "$relink_command" | $SED "s%@inst_prefix_dir@%-inst-prefix-dir $inst_prefix_dir%"`
4549dc407927Smrg	  else
4550dd0822caSmrg	    relink_command=`$ECHO "$relink_command" | $SED "s%@inst_prefix_dir@%%"`
4551dc407927Smrg	  fi
4552dc407927Smrg
45531a9c160aSmrg	  func_warning "relinking '$file'"
4554dc407927Smrg	  func_show_eval "$relink_command" \
45551a9c160aSmrg	    'func_fatal_error "error: relink '\''$file'\'' with the above command before installing it"'
4556dc407927Smrg	fi
4557dc407927Smrg
4558dc407927Smrg	# See the names of the shared library.
4559dc407927Smrg	set dummy $library_names; shift
4560dc407927Smrg	if test -n "$1"; then
45611a9c160aSmrg	  realname=$1
4562dc407927Smrg	  shift
4563dc407927Smrg
45641a9c160aSmrg	  srcname=$realname
45651a9c160aSmrg	  test -n "$relink_command" && srcname=${realname}T
4566dc407927Smrg
4567dc407927Smrg	  # Install the shared library and build the symlinks.
4568dd0822caSmrg	  func_show_eval "$install_shared_prog $dir/$srcname $destdir/$realname" \
4569dc407927Smrg	      'exit $?'
45701a9c160aSmrg	  tstripme=$stripme
4571dc407927Smrg	  case $host_os in
4572dc407927Smrg	  cygwin* | mingw* | pw32* | cegcc*)
4573dc407927Smrg	    case $realname in
4574dc407927Smrg	    *.dll.a)
45751a9c160aSmrg	      tstripme=
45761a9c160aSmrg	      ;;
45771a9c160aSmrg	    esac
45781a9c160aSmrg	    ;;
45791a9c160aSmrg	  os2*)
45801a9c160aSmrg	    case $realname in
45811a9c160aSmrg	    *_dll.a)
45821a9c160aSmrg	      tstripme=
4583dc407927Smrg	      ;;
4584dc407927Smrg	    esac
45853eed67faSmbalmer	    ;;
45863eed67faSmbalmer	  esac
4587dc407927Smrg	  if test -n "$tstripme" && test -n "$striplib"; then
4588dc407927Smrg	    func_show_eval "$striplib $destdir/$realname" 'exit $?'
45893eed67faSmbalmer	  fi
4590dc407927Smrg
4591dc407927Smrg	  if test "$#" -gt 0; then
4592dc407927Smrg	    # Delete the old symlinks, and create new ones.
45931a9c160aSmrg	    # Try 'ln -sf' first, because the 'ln' binary might depend on
4594dc407927Smrg	    # the symlink we replace!  Solaris /bin/ln does not understand -f,
4595dc407927Smrg	    # so we also need to try rm && ln -s.
4596dc407927Smrg	    for linkname
4597dc407927Smrg	    do
4598dc407927Smrg	      test "$linkname" != "$realname" \
4599dc407927Smrg		&& func_show_eval "(cd $destdir && { $LN_S -f $realname $linkname || { $RM $linkname && $LN_S $realname $linkname; }; })"
46003eed67faSmbalmer	    done
46013eed67faSmbalmer	  fi
46023eed67faSmbalmer
4603dc407927Smrg	  # Do each command in the postinstall commands.
46041a9c160aSmrg	  lib=$destdir/$realname
4605dc407927Smrg	  func_execute_cmds "$postinstall_cmds" 'exit $?'
46063eed67faSmbalmer	fi
46073eed67faSmbalmer
4608dc407927Smrg	# Install the pseudo-library for information purposes.
4609dc407927Smrg	func_basename "$file"
46101a9c160aSmrg	name=$func_basename_result
46111a9c160aSmrg	instname=$dir/${name}i
4612dc407927Smrg	func_show_eval "$install_prog $instname $destdir/$name" 'exit $?'
46133eed67faSmbalmer
4614dc407927Smrg	# Maybe install the static library, too.
4615dd0822caSmrg	test -n "$old_library" && func_append staticlibs " $dir/$old_library"
4616dc407927Smrg	;;
46173eed67faSmbalmer
4618dc407927Smrg      *.lo)
4619dc407927Smrg	# Install (i.e. copy) a libtool object.
46203eed67faSmbalmer
4621dc407927Smrg	# Figure out destination file name, if it wasn't already specified.
4622dc407927Smrg	if test -n "$destname"; then
46231a9c160aSmrg	  destfile=$destdir/$destname
4624dc407927Smrg	else
4625dc407927Smrg	  func_basename "$file"
46261a9c160aSmrg	  destfile=$func_basename_result
46271a9c160aSmrg	  destfile=$destdir/$destfile
4628dc407927Smrg	fi
4629dc407927Smrg
4630dc407927Smrg	# Deduce the name of the destination old-style object file.
4631dc407927Smrg	case $destfile in
4632dc407927Smrg	*.lo)
4633dc407927Smrg	  func_lo2o "$destfile"
4634dc407927Smrg	  staticdest=$func_lo2o_result
4635dc407927Smrg	  ;;
4636dc407927Smrg	*.$objext)
46371a9c160aSmrg	  staticdest=$destfile
4638dc407927Smrg	  destfile=
4639dc407927Smrg	  ;;
4640dc407927Smrg	*)
46411a9c160aSmrg	  func_fatal_help "cannot copy a libtool object to '$destfile'"
4642dc407927Smrg	  ;;
46433eed67faSmbalmer	esac
46443eed67faSmbalmer
4645dc407927Smrg	# Install the libtool object if requested.
4646dc407927Smrg	test -n "$destfile" && \
4647dc407927Smrg	  func_show_eval "$install_prog $file $destfile" 'exit $?'
4648dc407927Smrg
4649dc407927Smrg	# Install the old object if enabled.
46501a9c160aSmrg	if test yes = "$build_old_libs"; then
4651dc407927Smrg	  # Deduce the name of the old-style object file.
4652dc407927Smrg	  func_lo2o "$file"
4653dc407927Smrg	  staticobj=$func_lo2o_result
4654dc407927Smrg	  func_show_eval "$install_prog \$staticobj \$staticdest" 'exit $?'
46553eed67faSmbalmer	fi
4656dc407927Smrg	exit $EXIT_SUCCESS
4657dc407927Smrg	;;
46583eed67faSmbalmer
4659dc407927Smrg      *)
4660dc407927Smrg	# Figure out destination file name, if it wasn't already specified.
4661dc407927Smrg	if test -n "$destname"; then
46621a9c160aSmrg	  destfile=$destdir/$destname
4663dc407927Smrg	else
4664dc407927Smrg	  func_basename "$file"
46651a9c160aSmrg	  destfile=$func_basename_result
46661a9c160aSmrg	  destfile=$destdir/$destfile
4667dc407927Smrg	fi
4668dc407927Smrg
4669dc407927Smrg	# If the file is missing, and there is a .exe on the end, strip it
4670dc407927Smrg	# because it is most likely a libtool script we actually want to
4671dc407927Smrg	# install
46721a9c160aSmrg	stripped_ext=
4673dc407927Smrg	case $file in
4674dc407927Smrg	  *.exe)
4675dc407927Smrg	    if test ! -f "$file"; then
4676dc407927Smrg	      func_stripname '' '.exe' "$file"
4677dc407927Smrg	      file=$func_stripname_result
46781a9c160aSmrg	      stripped_ext=.exe
46793eed67faSmbalmer	    fi
4680dc407927Smrg	    ;;
4681dc407927Smrg	esac
4682dc407927Smrg
4683dc407927Smrg	# Do a test to see if this is really a libtool program.
4684dc407927Smrg	case $host in
4685dc407927Smrg	*cygwin* | *mingw*)
4686dc407927Smrg	    if func_ltwrapper_executable_p "$file"; then
4687dc407927Smrg	      func_ltwrapper_scriptname "$file"
4688dc407927Smrg	      wrapper=$func_ltwrapper_scriptname_result
4689dc407927Smrg	    else
4690dc407927Smrg	      func_stripname '' '.exe' "$file"
4691dc407927Smrg	      wrapper=$func_stripname_result
4692dc407927Smrg	    fi
4693dc407927Smrg	    ;;
4694dc407927Smrg	*)
4695dc407927Smrg	    wrapper=$file
4696dc407927Smrg	    ;;
4697dc407927Smrg	esac
4698dc407927Smrg	if func_ltwrapper_script_p "$wrapper"; then
4699dc407927Smrg	  notinst_deplibs=
4700dc407927Smrg	  relink_command=
47013eed67faSmbalmer
4702dc407927Smrg	  func_source "$wrapper"
47033eed67faSmbalmer
4704dc407927Smrg	  # Check the variables that should have been set.
4705dc407927Smrg	  test -z "$generated_by_libtool_version" && \
47061a9c160aSmrg	    func_fatal_error "invalid libtool wrapper script '$wrapper'"
47073eed67faSmbalmer
47081a9c160aSmrg	  finalize=:
4709dc407927Smrg	  for lib in $notinst_deplibs; do
4710dc407927Smrg	    # Check to see that each library is installed.
4711dc407927Smrg	    libdir=
4712dc407927Smrg	    if test -f "$lib"; then
4713dc407927Smrg	      func_source "$lib"
4714dc407927Smrg	    fi
47151a9c160aSmrg	    libfile=$libdir/`$ECHO "$lib" | $SED 's%^.*/%%g'`
4716dc407927Smrg	    if test -n "$libdir" && test ! -f "$libfile"; then
47171a9c160aSmrg	      func_warning "'$lib' has not been installed in '$libdir'"
47181a9c160aSmrg	      finalize=false
4719dc407927Smrg	    fi
4720dc407927Smrg	  done
4721dc407927Smrg
4722dc407927Smrg	  relink_command=
4723dc407927Smrg	  func_source "$wrapper"
4724dc407927Smrg
4725dc407927Smrg	  outputname=
47261a9c160aSmrg	  if test no = "$fast_install" && test -n "$relink_command"; then
4727dc407927Smrg	    $opt_dry_run || {
47281a9c160aSmrg	      if $finalize; then
4729dc407927Smrg	        tmpdir=`func_mktempdir`
4730dc407927Smrg		func_basename "$file$stripped_ext"
47311a9c160aSmrg		file=$func_basename_result
47321a9c160aSmrg	        outputname=$tmpdir/$file
4733dc407927Smrg	        # Replace the output file specification.
4734dd0822caSmrg	        relink_command=`$ECHO "$relink_command" | $SED 's%@OUTPUT@%'"$outputname"'%g'`
4735dc407927Smrg
47361a9c160aSmrg	        $opt_quiet || {
4737621f50c3Smrg	          func_quote_arg expand,pretty "$relink_command"
4738621f50c3Smrg		  eval "func_echo $func_quote_arg_result"
4739dc407927Smrg	        }
4740dc407927Smrg	        if eval "$relink_command"; then :
4741dc407927Smrg	          else
47421a9c160aSmrg		  func_error "error: relink '$file' with the above command before installing it"
4743dc407927Smrg		  $opt_dry_run || ${RM}r "$tmpdir"
4744dc407927Smrg		  continue
4745dc407927Smrg	        fi
47461a9c160aSmrg	        file=$outputname
4747dc407927Smrg	      else
47481a9c160aSmrg	        func_warning "cannot relink '$file'"
4749dc407927Smrg	      fi
4750dc407927Smrg	    }
47513eed67faSmbalmer	  else
4752dc407927Smrg	    # Install the binary that we compiled earlier.
4753dd0822caSmrg	    file=`$ECHO "$file$stripped_ext" | $SED "s%\([^/]*\)$%$objdir/\1%"`
47543eed67faSmbalmer	  fi
4755dc407927Smrg	fi
47563eed67faSmbalmer
4757dc407927Smrg	# remove .exe since cygwin /usr/bin/install will append another
4758dc407927Smrg	# one anyway
4759dc407927Smrg	case $install_prog,$host in
4760dc407927Smrg	*/usr/bin/install*,*cygwin*)
4761dc407927Smrg	  case $file:$destfile in
4762dc407927Smrg	  *.exe:*.exe)
4763dc407927Smrg	    # this is ok
4764dc407927Smrg	    ;;
4765dc407927Smrg	  *.exe:*)
4766dc407927Smrg	    destfile=$destfile.exe
4767dc407927Smrg	    ;;
4768dc407927Smrg	  *:*.exe)
4769dc407927Smrg	    func_stripname '' '.exe' "$destfile"
4770dc407927Smrg	    destfile=$func_stripname_result
4771dc407927Smrg	    ;;
4772dc407927Smrg	  esac
47733eed67faSmbalmer	  ;;
47743eed67faSmbalmer	esac
4775dc407927Smrg	func_show_eval "$install_prog\$stripme \$file \$destfile" 'exit $?'
4776dc407927Smrg	$opt_dry_run || if test -n "$outputname"; then
4777dc407927Smrg	  ${RM}r "$tmpdir"
4778dc407927Smrg	fi
4779dc407927Smrg	;;
4780dc407927Smrg      esac
4781dc407927Smrg    done
47823eed67faSmbalmer
4783dc407927Smrg    for file in $staticlibs; do
4784dc407927Smrg      func_basename "$file"
47851a9c160aSmrg      name=$func_basename_result
4786dc407927Smrg
4787dc407927Smrg      # Set up the ranlib parameters.
47881a9c160aSmrg      oldlib=$destdir/$name
478975cbef56Smrg      func_to_tool_file "$oldlib" func_convert_file_msys_to_w32
479075cbef56Smrg      tool_oldlib=$func_to_tool_file_result
4791dc407927Smrg
4792dc407927Smrg      func_show_eval "$install_prog \$file \$oldlib" 'exit $?'
4793dc407927Smrg
4794dc407927Smrg      if test -n "$stripme" && test -n "$old_striplib"; then
479575cbef56Smrg	func_show_eval "$old_striplib $tool_oldlib" 'exit $?'
4796dc407927Smrg      fi
4797dc407927Smrg
4798dc407927Smrg      # Do each command in the postinstall commands.
4799dc407927Smrg      func_execute_cmds "$old_postinstall_cmds" 'exit $?'
4800dc407927Smrg    done
4801dc407927Smrg
4802dc407927Smrg    test -n "$future_libdirs" && \
48031a9c160aSmrg      func_warning "remember to run '$progname --finish$future_libdirs'"
4804dc407927Smrg
4805dc407927Smrg    if test -n "$current_libdirs"; then
4806dc407927Smrg      # Maybe just do a dry run.
4807dc407927Smrg      $opt_dry_run && current_libdirs=" -n$current_libdirs"
48081a9c160aSmrg      exec_cmd='$SHELL "$progpath" $preserve_args --finish$current_libdirs'
4809dc407927Smrg    else
4810dc407927Smrg      exit $EXIT_SUCCESS
4811dc407927Smrg    fi
4812dc407927Smrg}
4813dc407927Smrg
48141a9c160aSmrgtest install = "$opt_mode" && func_mode_install ${1+"$@"}
4815dc407927Smrg
4816dc407927Smrg
4817dc407927Smrg# func_generate_dlsyms outputname originator pic_p
4818dc407927Smrg# Extract symbols from dlprefiles and create ${outputname}S.o with
4819dc407927Smrg# a dlpreopen symbol table.
4820dc407927Smrgfunc_generate_dlsyms ()
4821dc407927Smrg{
48221a9c160aSmrg    $debug_cmd
48231a9c160aSmrg
48241a9c160aSmrg    my_outputname=$1
48251a9c160aSmrg    my_originator=$2
48261a9c160aSmrg    my_pic_p=${3-false}
48271a9c160aSmrg    my_prefix=`$ECHO "$my_originator" | $SED 's%[^a-zA-Z0-9]%_%g'`
4828dc407927Smrg    my_dlsyms=
4829dc407927Smrg
48301a9c160aSmrg    if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then
4831dc407927Smrg      if test -n "$NM" && test -n "$global_symbol_pipe"; then
48321a9c160aSmrg	my_dlsyms=${my_outputname}S.c
4833dc407927Smrg      else
4834dc407927Smrg	func_error "not configured to extract global symbols from dlpreopened files"
4835dc407927Smrg      fi
4836dc407927Smrg    fi
4837dc407927Smrg
4838dc407927Smrg    if test -n "$my_dlsyms"; then
4839dc407927Smrg      case $my_dlsyms in
4840dc407927Smrg      "") ;;
4841dc407927Smrg      *.c)
4842dc407927Smrg	# Discover the nlist of each of the dlfiles.
48431a9c160aSmrg	nlist=$output_objdir/$my_outputname.nm
4844dc407927Smrg
4845dc407927Smrg	func_show_eval "$RM $nlist ${nlist}S ${nlist}T"
4846dc407927Smrg
4847dc407927Smrg	# Parse the name list into a source file.
4848dc407927Smrg	func_verbose "creating $output_objdir/$my_dlsyms"
4849dc407927Smrg
4850dc407927Smrg	$opt_dry_run || $ECHO > "$output_objdir/$my_dlsyms" "\
48511a9c160aSmrg/* $my_dlsyms - symbol resolution table for '$my_outputname' dlsym emulation. */
48521a9c160aSmrg/* Generated by $PROGRAM (GNU $PACKAGE) $VERSION */
4853dc407927Smrg
4854dc407927Smrg#ifdef __cplusplus
4855dc407927Smrgextern \"C\" {
4856dc407927Smrg#endif
4857dc407927Smrg
48581a9c160aSmrg#if defined __GNUC__ && (((__GNUC__ == 4) && (__GNUC_MINOR__ >= 4)) || (__GNUC__ > 4))
4859dd0822caSmrg#pragma GCC diagnostic ignored \"-Wstrict-prototypes\"
4860dd0822caSmrg#endif
4861dd0822caSmrg
4862dd0822caSmrg/* Keep this code in sync between libtool.m4, ltmain, lt_system.h, and tests.  */
48631a9c160aSmrg#if defined _WIN32 || defined __CYGWIN__ || defined _WIN32_WCE
48641a9c160aSmrg/* DATA imports from DLLs on WIN32 can't be const, because runtime
4865dd0822caSmrg   relocations are performed -- see ld's documentation on pseudo-relocs.  */
4866dd0822caSmrg# define LT_DLSYM_CONST
48671a9c160aSmrg#elif defined __osf__
4868dd0822caSmrg/* This system does not cope well with relocations in const data.  */
4869dd0822caSmrg# define LT_DLSYM_CONST
4870dd0822caSmrg#else
4871dd0822caSmrg# define LT_DLSYM_CONST const
4872dd0822caSmrg#endif
4873dd0822caSmrg
48741a9c160aSmrg#define STREQ(s1, s2) (strcmp ((s1), (s2)) == 0)
48751a9c160aSmrg
4876dc407927Smrg/* External symbol declarations for the compiler. */\
4877dc407927Smrg"
4878dc407927Smrg
48791a9c160aSmrg	if test yes = "$dlself"; then
48801a9c160aSmrg	  func_verbose "generating symbol list for '$output'"
4881dc407927Smrg
4882dc407927Smrg	  $opt_dry_run || echo ': @PROGRAM@ ' > "$nlist"
4883dc407927Smrg
4884dc407927Smrg	  # Add our own program objects to the symbol list.
4885dd0822caSmrg	  progfiles=`$ECHO "$objs$old_deplibs" | $SP2NL | $SED "$lo2o" | $NL2SP`
4886dc407927Smrg	  for progfile in $progfiles; do
4887dd0822caSmrg	    func_to_tool_file "$progfile" func_convert_file_msys_to_w32
48881a9c160aSmrg	    func_verbose "extracting global C symbols from '$func_to_tool_file_result'"
4889dd0822caSmrg	    $opt_dry_run || eval "$NM $func_to_tool_file_result | $global_symbol_pipe >> '$nlist'"
4890dc407927Smrg	  done
4891dc407927Smrg
4892dc407927Smrg	  if test -n "$exclude_expsyms"; then
4893dc407927Smrg	    $opt_dry_run || {
4894dc407927Smrg	      eval '$EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T'
4895dc407927Smrg	      eval '$MV "$nlist"T "$nlist"'
4896dc407927Smrg	    }
48973eed67faSmbalmer	  fi
4898dc407927Smrg
4899dc407927Smrg	  if test -n "$export_symbols_regex"; then
4900dc407927Smrg	    $opt_dry_run || {
4901dc407927Smrg	      eval '$EGREP -e "$export_symbols_regex" "$nlist" > "$nlist"T'
4902dc407927Smrg	      eval '$MV "$nlist"T "$nlist"'
4903dc407927Smrg	    }
4904dc407927Smrg	  fi
4905dc407927Smrg
4906dc407927Smrg	  # Prepare the list of exported symbols
4907dc407927Smrg	  if test -z "$export_symbols"; then
49081a9c160aSmrg	    export_symbols=$output_objdir/$outputname.exp
4909dc407927Smrg	    $opt_dry_run || {
4910dc407927Smrg	      $RM $export_symbols
49111a9c160aSmrg	      eval "$SED -n -e '/^: @PROGRAM@ $/d' -e 's/^.* \(.*\)$/\1/p' "'< "$nlist" > "$export_symbols"'
4912dc407927Smrg	      case $host in
4913dc407927Smrg	      *cygwin* | *mingw* | *cegcc* )
4914dc407927Smrg                eval "echo EXPORTS "'> "$output_objdir/$outputname.def"'
4915dc407927Smrg                eval 'cat "$export_symbols" >> "$output_objdir/$outputname.def"'
4916dc407927Smrg	        ;;
4917dc407927Smrg	      esac
4918dc407927Smrg	    }
49193eed67faSmbalmer	  else
4920dc407927Smrg	    $opt_dry_run || {
49211a9c160aSmrg	      eval "$SED -e 's/\([].[*^$]\)/\\\\\1/g' -e 's/^/ /' -e 's/$/$/'"' < "$export_symbols" > "$output_objdir/$outputname.exp"'
4922dc407927Smrg	      eval '$GREP -f "$output_objdir/$outputname.exp" < "$nlist" > "$nlist"T'
4923dc407927Smrg	      eval '$MV "$nlist"T "$nlist"'
4924dc407927Smrg	      case $host in
4925dd0822caSmrg	        *cygwin* | *mingw* | *cegcc* )
4926dc407927Smrg	          eval "echo EXPORTS "'> "$output_objdir/$outputname.def"'
4927dc407927Smrg	          eval 'cat "$nlist" >> "$output_objdir/$outputname.def"'
4928dc407927Smrg	          ;;
4929dc407927Smrg	      esac
4930dc407927Smrg	    }
49313eed67faSmbalmer	  fi
4932dc407927Smrg	fi
49333eed67faSmbalmer
4934dc407927Smrg	for dlprefile in $dlprefiles; do
49351a9c160aSmrg	  func_verbose "extracting global C symbols from '$dlprefile'"
4936dc407927Smrg	  func_basename "$dlprefile"
49371a9c160aSmrg	  name=$func_basename_result
4938dd0822caSmrg          case $host in
4939dd0822caSmrg	    *cygwin* | *mingw* | *cegcc* )
4940dd0822caSmrg	      # if an import library, we need to obtain dlname
4941dd0822caSmrg	      if func_win32_import_lib_p "$dlprefile"; then
4942dd0822caSmrg	        func_tr_sh "$dlprefile"
4943dd0822caSmrg	        eval "curr_lafile=\$libfile_$func_tr_sh_result"
49441a9c160aSmrg	        dlprefile_dlbasename=
4945dd0822caSmrg	        if test -n "$curr_lafile" && func_lalib_p "$curr_lafile"; then
4946dd0822caSmrg	          # Use subshell, to avoid clobbering current variable values
4947dd0822caSmrg	          dlprefile_dlname=`source "$curr_lafile" && echo "$dlname"`
49481a9c160aSmrg	          if test -n "$dlprefile_dlname"; then
4949dd0822caSmrg	            func_basename "$dlprefile_dlname"
49501a9c160aSmrg	            dlprefile_dlbasename=$func_basename_result
4951dd0822caSmrg	          else
4952dd0822caSmrg	            # no lafile. user explicitly requested -dlpreopen <import library>.
4953dd0822caSmrg	            $sharedlib_from_linklib_cmd "$dlprefile"
4954dd0822caSmrg	            dlprefile_dlbasename=$sharedlib_from_linklib_result
4955dd0822caSmrg	          fi
4956dd0822caSmrg	        fi
4957dd0822caSmrg	        $opt_dry_run || {
49581a9c160aSmrg	          if test -n "$dlprefile_dlbasename"; then
4959dd0822caSmrg	            eval '$ECHO ": $dlprefile_dlbasename" >> "$nlist"'
4960dd0822caSmrg	          else
4961dd0822caSmrg	            func_warning "Could not compute DLL name from $name"
4962dd0822caSmrg	            eval '$ECHO ": $name " >> "$nlist"'
4963dd0822caSmrg	          fi
4964dd0822caSmrg	          func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
4965dd0822caSmrg	          eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe |
4966dd0822caSmrg	            $SED -e '/I __imp/d' -e 's/I __nm_/D /;s/_nm__//' >> '$nlist'"
4967dd0822caSmrg	        }
4968dd0822caSmrg	      else # not an import lib
4969dd0822caSmrg	        $opt_dry_run || {
4970dd0822caSmrg	          eval '$ECHO ": $name " >> "$nlist"'
4971dd0822caSmrg	          func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
4972dd0822caSmrg	          eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe >> '$nlist'"
4973dd0822caSmrg	        }
4974dd0822caSmrg	      fi
4975dd0822caSmrg	    ;;
4976dd0822caSmrg	    *)
4977dd0822caSmrg	      $opt_dry_run || {
4978dd0822caSmrg	        eval '$ECHO ": $name " >> "$nlist"'
4979dd0822caSmrg	        func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
4980dd0822caSmrg	        eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe >> '$nlist'"
4981dd0822caSmrg	      }
4982dd0822caSmrg	    ;;
4983dd0822caSmrg          esac
4984dc407927Smrg	done
4985dc407927Smrg
4986dc407927Smrg	$opt_dry_run || {
4987dc407927Smrg	  # Make sure we have at least an empty file.
4988dc407927Smrg	  test -f "$nlist" || : > "$nlist"
4989dc407927Smrg
4990dc407927Smrg	  if test -n "$exclude_expsyms"; then
4991dc407927Smrg	    $EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T
4992dc407927Smrg	    $MV "$nlist"T "$nlist"
49933eed67faSmbalmer	  fi
4994dc407927Smrg
4995dc407927Smrg	  # Try sorting and uniquifying the output.
4996dc407927Smrg	  if $GREP -v "^: " < "$nlist" |
4997dc407927Smrg	      if sort -k 3 </dev/null >/dev/null 2>&1; then
4998dc407927Smrg		sort -k 3
4999dc407927Smrg	      else
5000dc407927Smrg		sort +2
5001dc407927Smrg	      fi |
5002dc407927Smrg	      uniq > "$nlist"S; then
5003dc407927Smrg	    :
50043eed67faSmbalmer	  else
5005dc407927Smrg	    $GREP -v "^: " < "$nlist" > "$nlist"S
50063eed67faSmbalmer	  fi
50073eed67faSmbalmer
5008dc407927Smrg	  if test -f "$nlist"S; then
5009dc407927Smrg	    eval "$global_symbol_to_cdecl"' < "$nlist"S >> "$output_objdir/$my_dlsyms"'
50103eed67faSmbalmer	  else
5011dd0822caSmrg	    echo '/* NONE */' >> "$output_objdir/$my_dlsyms"
50123eed67faSmbalmer	  fi
50133eed67faSmbalmer
50141a9c160aSmrg	  func_show_eval '$RM "${nlist}I"'
50151a9c160aSmrg	  if test -n "$global_symbol_to_import"; then
50161a9c160aSmrg	    eval "$global_symbol_to_import"' < "$nlist"S > "$nlist"I'
50171a9c160aSmrg	  fi
50181a9c160aSmrg
5019dd0822caSmrg	  echo >> "$output_objdir/$my_dlsyms" "\
50203eed67faSmbalmer
5021dc407927Smrg/* The mapping between symbol names and symbols.  */
5022dc407927Smrgtypedef struct {
5023dc407927Smrg  const char *name;
5024dc407927Smrg  void *address;
5025dc407927Smrg} lt_dlsymlist;
5026dd0822caSmrgextern LT_DLSYM_CONST lt_dlsymlist
50271a9c160aSmrglt_${my_prefix}_LTX_preloaded_symbols[];\
50281a9c160aSmrg"
50291a9c160aSmrg
50301a9c160aSmrg	  if test -s "$nlist"I; then
50311a9c160aSmrg	    echo >> "$output_objdir/$my_dlsyms" "\
50321a9c160aSmrgstatic void lt_syminit(void)
50331a9c160aSmrg{
50341a9c160aSmrg  LT_DLSYM_CONST lt_dlsymlist *symbol = lt_${my_prefix}_LTX_preloaded_symbols;
50351a9c160aSmrg  for (; symbol->name; ++symbol)
50361a9c160aSmrg    {"
50371a9c160aSmrg	    $SED 's/.*/      if (STREQ (symbol->name, \"&\")) symbol->address = (void *) \&&;/' < "$nlist"I >> "$output_objdir/$my_dlsyms"
50381a9c160aSmrg	    echo >> "$output_objdir/$my_dlsyms" "\
50391a9c160aSmrg    }
50401a9c160aSmrg}"
50411a9c160aSmrg	  fi
50421a9c160aSmrg	  echo >> "$output_objdir/$my_dlsyms" "\
5043dd0822caSmrgLT_DLSYM_CONST lt_dlsymlist
5044dc407927Smrglt_${my_prefix}_LTX_preloaded_symbols[] =
50451a9c160aSmrg{ {\"$my_originator\", (void *) 0},"
50461a9c160aSmrg
50471a9c160aSmrg	  if test -s "$nlist"I; then
50481a9c160aSmrg	    echo >> "$output_objdir/$my_dlsyms" "\
50491a9c160aSmrg  {\"@INIT@\", (void *) &lt_syminit},"
50501a9c160aSmrg	  fi
50513eed67faSmbalmer
5052dc407927Smrg	  case $need_lib_prefix in
5053dc407927Smrg	  no)
5054dc407927Smrg	    eval "$global_symbol_to_c_name_address" < "$nlist" >> "$output_objdir/$my_dlsyms"
5055dc407927Smrg	    ;;
5056dc407927Smrg	  *)
5057dc407927Smrg	    eval "$global_symbol_to_c_name_address_lib_prefix" < "$nlist" >> "$output_objdir/$my_dlsyms"
5058dc407927Smrg	    ;;
5059dc407927Smrg	  esac
5060dd0822caSmrg	  echo >> "$output_objdir/$my_dlsyms" "\
5061dc407927Smrg  {0, (void *) 0}
5062dc407927Smrg};
50633eed67faSmbalmer
5064dc407927Smrg/* This works around a problem in FreeBSD linker */
5065dc407927Smrg#ifdef FREEBSD_WORKAROUND
5066dc407927Smrgstatic const void *lt_preloaded_setup() {
5067dc407927Smrg  return lt_${my_prefix}_LTX_preloaded_symbols;
5068dc407927Smrg}
5069dc407927Smrg#endif
5070dc407927Smrg
5071dc407927Smrg#ifdef __cplusplus
5072dc407927Smrg}
5073dc407927Smrg#endif\
5074dc407927Smrg"
5075dc407927Smrg	} # !$opt_dry_run
5076dc407927Smrg
5077dc407927Smrg	pic_flag_for_symtable=
5078dc407927Smrg	case "$compile_command " in
5079dc407927Smrg	*" -static "*) ;;
5080dc407927Smrg	*)
5081dc407927Smrg	  case $host in
5082dc407927Smrg	  # compiling the symbol table file with pic_flag works around
5083dc407927Smrg	  # a FreeBSD bug that causes programs to crash when -lm is
5084dc407927Smrg	  # linked before any other PIC object.  But we must not use
5085dc407927Smrg	  # pic_flag when linking with -static.  The problem exists in
5086dc407927Smrg	  # FreeBSD 2.2.6 and is fixed in FreeBSD 3.1.
508775cbef56Smrg	  *-*-freebsd2.*|*-*-freebsd3.0*|*-*-freebsdelf3.0*)
5088dc407927Smrg	    pic_flag_for_symtable=" $pic_flag -DFREEBSD_WORKAROUND" ;;
5089dc407927Smrg	  *-*-hpux*)
5090dc407927Smrg	    pic_flag_for_symtable=" $pic_flag"  ;;
5091dc407927Smrg	  *)
50921a9c160aSmrg	    $my_pic_p && pic_flag_for_symtable=" $pic_flag"
5093dc407927Smrg	    ;;
5094dc407927Smrg	  esac
5095dc407927Smrg	  ;;
5096dc407927Smrg	esac
5097dc407927Smrg	symtab_cflags=
5098dc407927Smrg	for arg in $LTCFLAGS; do
5099dc407927Smrg	  case $arg in
5100dc407927Smrg	  -pie | -fpie | -fPIE) ;;
5101dd0822caSmrg	  *) func_append symtab_cflags " $arg" ;;
5102dc407927Smrg	  esac
5103dc407927Smrg	done
51043eed67faSmbalmer
5105dc407927Smrg	# Now compile the dynamic symbol file.
5106dc407927Smrg	func_show_eval '(cd $output_objdir && $LTCC$symtab_cflags -c$no_builtin_flag$pic_flag_for_symtable "$my_dlsyms")' 'exit $?'
51073eed67faSmbalmer
5108dc407927Smrg	# Clean up the generated files.
51091a9c160aSmrg	func_show_eval '$RM "$output_objdir/$my_dlsyms" "$nlist" "${nlist}S" "${nlist}T" "${nlist}I"'
51103eed67faSmbalmer
5111dc407927Smrg	# Transform the symbol file into the correct name.
51121a9c160aSmrg	symfileobj=$output_objdir/${my_outputname}S.$objext
5113dc407927Smrg	case $host in
5114dc407927Smrg	*cygwin* | *mingw* | *cegcc* )
5115dc407927Smrg	  if test -f "$output_objdir/$my_outputname.def"; then
5116dd0822caSmrg	    compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$output_objdir/$my_outputname.def $symfileobj%"`
5117dd0822caSmrg	    finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$output_objdir/$my_outputname.def $symfileobj%"`
5118dc407927Smrg	  else
5119dd0822caSmrg	    compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$symfileobj%"`
5120dd0822caSmrg	    finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$symfileobj%"`
51213eed67faSmbalmer	  fi
5122dc407927Smrg	  ;;
5123dc407927Smrg	*)
5124dd0822caSmrg	  compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$symfileobj%"`
5125dd0822caSmrg	  finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$symfileobj%"`
5126dc407927Smrg	  ;;
5127dc407927Smrg	esac
5128dc407927Smrg	;;
5129dc407927Smrg      *)
51301a9c160aSmrg	func_fatal_error "unknown suffix for '$my_dlsyms'"
5131dc407927Smrg	;;
5132dc407927Smrg      esac
5133dc407927Smrg    else
5134dc407927Smrg      # We keep going just in case the user didn't refer to
5135dc407927Smrg      # lt_preloaded_symbols.  The linker will fail if global_symbol_pipe
5136dc407927Smrg      # really was required.
51373eed67faSmbalmer
5138dc407927Smrg      # Nullify the symbol file.
5139dd0822caSmrg      compile_command=`$ECHO "$compile_command" | $SED "s% @SYMFILE@%%"`
5140dd0822caSmrg      finalize_command=`$ECHO "$finalize_command" | $SED "s% @SYMFILE@%%"`
5141dc407927Smrg    fi
5142dc407927Smrg}
51433eed67faSmbalmer
51441a9c160aSmrg# func_cygming_gnu_implib_p ARG
51451a9c160aSmrg# This predicate returns with zero status (TRUE) if
51461a9c160aSmrg# ARG is a GNU/binutils-style import library. Returns
51471a9c160aSmrg# with nonzero status (FALSE) otherwise.
51481a9c160aSmrgfunc_cygming_gnu_implib_p ()
51491a9c160aSmrg{
51501a9c160aSmrg  $debug_cmd
51511a9c160aSmrg
51521a9c160aSmrg  func_to_tool_file "$1" func_convert_file_msys_to_w32
51531a9c160aSmrg  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)$'`
51541a9c160aSmrg  test -n "$func_cygming_gnu_implib_tmp"
51551a9c160aSmrg}
51561a9c160aSmrg
51571a9c160aSmrg# func_cygming_ms_implib_p ARG
51581a9c160aSmrg# This predicate returns with zero status (TRUE) if
51591a9c160aSmrg# ARG is an MS-style import library. Returns
51601a9c160aSmrg# with nonzero status (FALSE) otherwise.
51611a9c160aSmrgfunc_cygming_ms_implib_p ()
51621a9c160aSmrg{
51631a9c160aSmrg  $debug_cmd
51641a9c160aSmrg
51651a9c160aSmrg  func_to_tool_file "$1" func_convert_file_msys_to_w32
51661a9c160aSmrg  func_cygming_ms_implib_tmp=`$NM "$func_to_tool_file_result" | eval "$global_symbol_pipe" | $GREP '_NULL_IMPORT_DESCRIPTOR'`
51671a9c160aSmrg  test -n "$func_cygming_ms_implib_tmp"
51681a9c160aSmrg}
51691a9c160aSmrg
5170dc407927Smrg# func_win32_libid arg
5171dc407927Smrg# return the library type of file 'arg'
5172dc407927Smrg#
5173dc407927Smrg# Need a lot of goo to handle *both* DLLs and import libs
5174dc407927Smrg# Has to be a shell function in order to 'eat' the argument
5175dc407927Smrg# that is supplied when $file_magic_command is called.
5176dd0822caSmrg# Despite the name, also deal with 64 bit binaries.
5177dc407927Smrgfunc_win32_libid ()
5178dc407927Smrg{
51791a9c160aSmrg  $debug_cmd
51801a9c160aSmrg
51811a9c160aSmrg  win32_libid_type=unknown
5182dc407927Smrg  win32_fileres=`file -L $1 2>/dev/null`
5183dc407927Smrg  case $win32_fileres in
5184dc407927Smrg  *ar\ archive\ import\ library*) # definitely import
5185dc407927Smrg    win32_libid_type="x86 archive import"
5186dc407927Smrg    ;;
5187dc407927Smrg  *ar\ archive*) # could be an import, or static
5188dd0822caSmrg    # Keep the egrep pattern in sync with the one in _LT_CHECK_MAGIC_METHOD.
5189dc407927Smrg    if eval $OBJDUMP -f $1 | $SED -e '10q' 2>/dev/null |
5190dd0822caSmrg       $EGREP 'file format (pei*-i386(.*architecture: i386)?|pe-arm-wince|pe-x86-64)' >/dev/null; then
51911a9c160aSmrg      case $nm_interface in
51921a9c160aSmrg      "MS dumpbin")
51931a9c160aSmrg	if func_cygming_ms_implib_p "$1" ||
51941a9c160aSmrg	   func_cygming_gnu_implib_p "$1"
51951a9c160aSmrg	then
51961a9c160aSmrg	  win32_nmres=import
51971a9c160aSmrg	else
51981a9c160aSmrg	  win32_nmres=
51991a9c160aSmrg	fi
52001a9c160aSmrg	;;
52011a9c160aSmrg      *)
52021a9c160aSmrg	func_to_tool_file "$1" func_convert_file_msys_to_w32
52031a9c160aSmrg	win32_nmres=`eval $NM -f posix -A \"$func_to_tool_file_result\" |
52041a9c160aSmrg	  $SED -n -e '
5205dc407927Smrg	    1,100{
5206dc407927Smrg		/ I /{
52071a9c160aSmrg		    s|.*|import|
5208dc407927Smrg		    p
5209dc407927Smrg		    q
5210dc407927Smrg		}
5211dc407927Smrg	    }'`
52121a9c160aSmrg	;;
52131a9c160aSmrg      esac
5214dc407927Smrg      case $win32_nmres in
5215dc407927Smrg      import*)  win32_libid_type="x86 archive import";;
5216dc407927Smrg      *)        win32_libid_type="x86 archive static";;
5217dc407927Smrg      esac
5218dc407927Smrg    fi
5219dc407927Smrg    ;;
5220dc407927Smrg  *DLL*)
5221dc407927Smrg    win32_libid_type="x86 DLL"
5222dc407927Smrg    ;;
5223dc407927Smrg  *executable*) # but shell scripts are "executable" too...
5224dc407927Smrg    case $win32_fileres in
5225dc407927Smrg    *MS\ Windows\ PE\ Intel*)
5226dc407927Smrg      win32_libid_type="x86 DLL"
5227dc407927Smrg      ;;
5228dc407927Smrg    esac
5229dc407927Smrg    ;;
5230dc407927Smrg  esac
5231dc407927Smrg  $ECHO "$win32_libid_type"
5232dc407927Smrg}
52333eed67faSmbalmer
5234dd0822caSmrg# func_cygming_dll_for_implib ARG
5235dd0822caSmrg#
5236dd0822caSmrg# Platform-specific function to extract the
5237dd0822caSmrg# name of the DLL associated with the specified
5238dd0822caSmrg# import library ARG.
5239dd0822caSmrg# Invoked by eval'ing the libtool variable
5240dd0822caSmrg#    $sharedlib_from_linklib_cmd
5241dd0822caSmrg# Result is available in the variable
5242dd0822caSmrg#    $sharedlib_from_linklib_result
5243dd0822caSmrgfunc_cygming_dll_for_implib ()
5244dd0822caSmrg{
52451a9c160aSmrg  $debug_cmd
52461a9c160aSmrg
5247dd0822caSmrg  sharedlib_from_linklib_result=`$DLLTOOL --identify-strict --identify "$1"`
5248dd0822caSmrg}
5249dd0822caSmrg
5250dd0822caSmrg# func_cygming_dll_for_implib_fallback_core SECTION_NAME LIBNAMEs
5251dd0822caSmrg#
5252dd0822caSmrg# The is the core of a fallback implementation of a
5253dd0822caSmrg# platform-specific function to extract the name of the
5254dd0822caSmrg# DLL associated with the specified import library LIBNAME.
5255dd0822caSmrg#
5256dd0822caSmrg# SECTION_NAME is either .idata$6 or .idata$7, depending
5257dd0822caSmrg# on the platform and compiler that created the implib.
5258dd0822caSmrg#
5259dd0822caSmrg# Echos the name of the DLL associated with the
5260dd0822caSmrg# specified import library.
5261dd0822caSmrgfunc_cygming_dll_for_implib_fallback_core ()
5262dd0822caSmrg{
52631a9c160aSmrg  $debug_cmd
52641a9c160aSmrg
5265dd0822caSmrg  match_literal=`$ECHO "$1" | $SED "$sed_make_literal_regex"`
5266dd0822caSmrg  $OBJDUMP -s --section "$1" "$2" 2>/dev/null |
5267dd0822caSmrg    $SED '/^Contents of section '"$match_literal"':/{
5268dd0822caSmrg      # Place marker at beginning of archive member dllname section
5269dd0822caSmrg      s/.*/====MARK====/
5270dd0822caSmrg      p
5271dd0822caSmrg      d
5272dd0822caSmrg    }
5273dd0822caSmrg    # These lines can sometimes be longer than 43 characters, but
5274dd0822caSmrg    # are always uninteresting
5275dd0822caSmrg    /:[	 ]*file format pe[i]\{,1\}-/d
5276dd0822caSmrg    /^In archive [^:]*:/d
5277dd0822caSmrg    # Ensure marker is printed
5278dd0822caSmrg    /^====MARK====/p
5279dd0822caSmrg    # Remove all lines with less than 43 characters
5280dd0822caSmrg    /^.\{43\}/!d
5281dd0822caSmrg    # From remaining lines, remove first 43 characters
5282dd0822caSmrg    s/^.\{43\}//' |
5283dd0822caSmrg    $SED -n '
5284dd0822caSmrg      # Join marker and all lines until next marker into a single line
5285dd0822caSmrg      /^====MARK====/ b para
5286dd0822caSmrg      H
5287dd0822caSmrg      $ b para
5288dd0822caSmrg      b
5289dd0822caSmrg      :para
5290dd0822caSmrg      x
5291dd0822caSmrg      s/\n//g
5292dd0822caSmrg      # Remove the marker
5293dd0822caSmrg      s/^====MARK====//
5294dd0822caSmrg      # Remove trailing dots and whitespace
5295dd0822caSmrg      s/[\. \t]*$//
5296dd0822caSmrg      # Print
5297dd0822caSmrg      /./p' |
5298dd0822caSmrg    # we now have a list, one entry per line, of the stringified
5299dd0822caSmrg    # contents of the appropriate section of all members of the
53001a9c160aSmrg    # archive that possess that section. Heuristic: eliminate
53011a9c160aSmrg    # all those that have a first or second character that is
5302dd0822caSmrg    # a '.' (that is, objdump's representation of an unprintable
5303dd0822caSmrg    # character.) This should work for all archives with less than
5304dd0822caSmrg    # 0x302f exports -- but will fail for DLLs whose name actually
5305dd0822caSmrg    # begins with a literal '.' or a single character followed by
5306dd0822caSmrg    # a '.'.
5307dd0822caSmrg    #
5308dd0822caSmrg    # Of those that remain, print the first one.
5309dd0822caSmrg    $SED -e '/^\./d;/^.\./d;q'
5310dd0822caSmrg}
5311dd0822caSmrg
5312dd0822caSmrg# func_cygming_dll_for_implib_fallback ARG
5313dd0822caSmrg# Platform-specific function to extract the
5314dd0822caSmrg# name of the DLL associated with the specified
5315dd0822caSmrg# import library ARG.
5316dd0822caSmrg#
5317dd0822caSmrg# This fallback implementation is for use when $DLLTOOL
5318dd0822caSmrg# does not support the --identify-strict option.
5319dd0822caSmrg# Invoked by eval'ing the libtool variable
5320dd0822caSmrg#    $sharedlib_from_linklib_cmd
5321dd0822caSmrg# Result is available in the variable
5322dd0822caSmrg#    $sharedlib_from_linklib_result
5323dd0822caSmrgfunc_cygming_dll_for_implib_fallback ()
5324dd0822caSmrg{
53251a9c160aSmrg  $debug_cmd
53261a9c160aSmrg
53271a9c160aSmrg  if func_cygming_gnu_implib_p "$1"; then
5328dd0822caSmrg    # binutils import library
5329dd0822caSmrg    sharedlib_from_linklib_result=`func_cygming_dll_for_implib_fallback_core '.idata$7' "$1"`
53301a9c160aSmrg  elif func_cygming_ms_implib_p "$1"; then
5331dd0822caSmrg    # ms-generated import library
5332dd0822caSmrg    sharedlib_from_linklib_result=`func_cygming_dll_for_implib_fallback_core '.idata$6' "$1"`
5333dd0822caSmrg  else
5334dd0822caSmrg    # unknown
53351a9c160aSmrg    sharedlib_from_linklib_result=
5336dd0822caSmrg  fi
5337dd0822caSmrg}
53383eed67faSmbalmer
53393eed67faSmbalmer
5340dc407927Smrg# func_extract_an_archive dir oldlib
5341dc407927Smrgfunc_extract_an_archive ()
5342dc407927Smrg{
53431a9c160aSmrg    $debug_cmd
53441a9c160aSmrg
53451a9c160aSmrg    f_ex_an_ar_dir=$1; shift
53461a9c160aSmrg    f_ex_an_ar_oldlib=$1
53471a9c160aSmrg    if test yes = "$lock_old_archive_extraction"; then
5348dd0822caSmrg      lockfile=$f_ex_an_ar_oldlib.lock
5349dd0822caSmrg      until $opt_dry_run || ln "$progpath" "$lockfile" 2>/dev/null; do
5350dd0822caSmrg	func_echo "Waiting for $lockfile to be removed"
5351dd0822caSmrg	sleep 2
5352dd0822caSmrg      done
5353dd0822caSmrg    fi
5354dd0822caSmrg    func_show_eval "(cd \$f_ex_an_ar_dir && $AR x \"\$f_ex_an_ar_oldlib\")" \
5355dd0822caSmrg		   'stat=$?; rm -f "$lockfile"; exit $stat'
53561a9c160aSmrg    if test yes = "$lock_old_archive_extraction"; then
5357dd0822caSmrg      $opt_dry_run || rm -f "$lockfile"
5358dd0822caSmrg    fi
5359dc407927Smrg    if ($AR t "$f_ex_an_ar_oldlib" | sort | sort -uc >/dev/null 2>&1); then
5360dc407927Smrg     :
5361dc407927Smrg    else
5362dc407927Smrg      func_fatal_error "object name conflicts in archive: $f_ex_an_ar_dir/$f_ex_an_ar_oldlib"
5363dc407927Smrg    fi
5364dc407927Smrg}
53653eed67faSmbalmer
53663eed67faSmbalmer
5367dc407927Smrg# func_extract_archives gentop oldlib ...
5368dc407927Smrgfunc_extract_archives ()
5369dc407927Smrg{
53701a9c160aSmrg    $debug_cmd
53711a9c160aSmrg
53721a9c160aSmrg    my_gentop=$1; shift
5373dc407927Smrg    my_oldlibs=${1+"$@"}
53741a9c160aSmrg    my_oldobjs=
53751a9c160aSmrg    my_xlib=
53761a9c160aSmrg    my_xabs=
53771a9c160aSmrg    my_xdir=
53783eed67faSmbalmer
5379dc407927Smrg    for my_xlib in $my_oldlibs; do
5380dc407927Smrg      # Extract the objects.
5381dc407927Smrg      case $my_xlib in
53821a9c160aSmrg	[\\/]* | [A-Za-z]:[\\/]*) my_xabs=$my_xlib ;;
5383dc407927Smrg	*) my_xabs=`pwd`"/$my_xlib" ;;
5384dc407927Smrg      esac
5385dc407927Smrg      func_basename "$my_xlib"
53861a9c160aSmrg      my_xlib=$func_basename_result
5387dc407927Smrg      my_xlib_u=$my_xlib
5388dc407927Smrg      while :; do
5389dc407927Smrg        case " $extracted_archives " in
5390dc407927Smrg	*" $my_xlib_u "*)
5391dc407927Smrg	  func_arith $extracted_serial + 1
5392dc407927Smrg	  extracted_serial=$func_arith_result
5393dc407927Smrg	  my_xlib_u=lt$extracted_serial-$my_xlib ;;
5394dc407927Smrg	*) break ;;
5395dc407927Smrg	esac
5396dc407927Smrg      done
5397dc407927Smrg      extracted_archives="$extracted_archives $my_xlib_u"
53981a9c160aSmrg      my_xdir=$my_gentop/$my_xlib_u
53993eed67faSmbalmer
5400dc407927Smrg      func_mkdir_p "$my_xdir"
54013eed67faSmbalmer
5402dc407927Smrg      case $host in
5403dc407927Smrg      *-darwin*)
5404dc407927Smrg	func_verbose "Extracting $my_xabs"
5405dc407927Smrg	# Do not bother doing anything if just a dry run
5406dc407927Smrg	$opt_dry_run || {
5407dc407927Smrg	  darwin_orig_dir=`pwd`
5408dc407927Smrg	  cd $my_xdir || exit $?
5409dc407927Smrg	  darwin_archive=$my_xabs
5410dc407927Smrg	  darwin_curdir=`pwd`
54111a9c160aSmrg	  func_basename "$darwin_archive"
54121a9c160aSmrg	  darwin_base_archive=$func_basename_result
5413dc407927Smrg	  darwin_arches=`$LIPO -info "$darwin_archive" 2>/dev/null | $GREP Architectures 2>/dev/null || true`
5414dc407927Smrg	  if test -n "$darwin_arches"; then
5415dc407927Smrg	    darwin_arches=`$ECHO "$darwin_arches" | $SED -e 's/.*are://'`
5416dc407927Smrg	    darwin_arch=
5417dc407927Smrg	    func_verbose "$darwin_base_archive has multiple architectures $darwin_arches"
54181a9c160aSmrg	    for darwin_arch in  $darwin_arches; do
54191a9c160aSmrg	      func_mkdir_p "unfat-$$/$darwin_base_archive-$darwin_arch"
54201a9c160aSmrg	      $LIPO -thin $darwin_arch -output "unfat-$$/$darwin_base_archive-$darwin_arch/$darwin_base_archive" "$darwin_archive"
54211a9c160aSmrg	      cd "unfat-$$/$darwin_base_archive-$darwin_arch"
54221a9c160aSmrg	      func_extract_an_archive "`pwd`" "$darwin_base_archive"
5423dc407927Smrg	      cd "$darwin_curdir"
54241a9c160aSmrg	      $RM "unfat-$$/$darwin_base_archive-$darwin_arch/$darwin_base_archive"
5425dc407927Smrg	    done # $darwin_arches
5426dc407927Smrg            ## Okay now we've a bunch of thin objects, gotta fatten them up :)
54271a9c160aSmrg	    darwin_filelist=`find unfat-$$ -type f -name \*.o -print -o -name \*.lo -print | $SED -e "$sed_basename" | sort -u`
5428dc407927Smrg	    darwin_file=
5429dc407927Smrg	    darwin_files=
5430dc407927Smrg	    for darwin_file in $darwin_filelist; do
5431dd0822caSmrg	      darwin_files=`find unfat-$$ -name $darwin_file -print | sort | $NL2SP`
5432dc407927Smrg	      $LIPO -create -output "$darwin_file" $darwin_files
5433dc407927Smrg	    done # $darwin_filelist
5434dc407927Smrg	    $RM -rf unfat-$$
5435dc407927Smrg	    cd "$darwin_orig_dir"
54363eed67faSmbalmer	  else
5437dc407927Smrg	    cd $darwin_orig_dir
5438dc407927Smrg	    func_extract_an_archive "$my_xdir" "$my_xabs"
5439dc407927Smrg	  fi # $darwin_arches
5440dc407927Smrg	} # !$opt_dry_run
5441dc407927Smrg	;;
5442dc407927Smrg      *)
5443dc407927Smrg        func_extract_an_archive "$my_xdir" "$my_xabs"
5444dc407927Smrg	;;
5445dc407927Smrg      esac
5446dd0822caSmrg      my_oldobjs="$my_oldobjs "`find $my_xdir -name \*.$objext -print -o -name \*.lo -print | sort | $NL2SP`
5447dc407927Smrg    done
54483eed67faSmbalmer
54491a9c160aSmrg    func_extract_archives_result=$my_oldobjs
5450dc407927Smrg}
54513eed67faSmbalmer
54523eed67faSmbalmer
5453dd0822caSmrg# func_emit_wrapper [arg=no]
5454dd0822caSmrg#
5455dd0822caSmrg# Emit a libtool wrapper script on stdout.
5456dd0822caSmrg# Don't directly open a file because we may want to
5457dd0822caSmrg# incorporate the script contents within a cygwin/mingw
5458dd0822caSmrg# wrapper executable.  Must ONLY be called from within
5459dd0822caSmrg# func_mode_link because it depends on a number of variables
5460dd0822caSmrg# set therein.
5461dc407927Smrg#
5462dd0822caSmrg# ARG is the value that the WRAPPER_SCRIPT_BELONGS_IN_OBJDIR
5463dd0822caSmrg# variable will take.  If 'yes', then the emitted script
54641a9c160aSmrg# will assume that the directory where it is stored is
5465dd0822caSmrg# the $objdir directory.  This is a cygwin/mingw-specific
5466dd0822caSmrg# behavior.
5467dd0822caSmrgfunc_emit_wrapper ()
5468dc407927Smrg{
5469dd0822caSmrg	func_emit_wrapper_arg1=${1-no}
54703eed67faSmbalmer
5471dc407927Smrg	$ECHO "\
5472dc407927Smrg#! $SHELL
54733eed67faSmbalmer
5474dc407927Smrg# $output - temporary wrapper script for $objdir/$outputname
54751a9c160aSmrg# Generated by $PROGRAM (GNU $PACKAGE) $VERSION
5476dc407927Smrg#
5477dc407927Smrg# The $output program cannot be directly executed until all the libtool
5478dc407927Smrg# libraries that it depends on are installed.
5479dc407927Smrg#
5480dc407927Smrg# This wrapper script should never be moved out of the build directory.
5481dc407927Smrg# If it is, it will not operate correctly.
54823eed67faSmbalmer
5483dc407927Smrg# Sed substitution that helps us do robust quoting.  It backslashifies
5484dc407927Smrg# metacharacters that are still active within double-quoted strings.
5485dc407927Smrgsed_quote_subst='$sed_quote_subst'
54863eed67faSmbalmer
5487dc407927Smrg# Be Bourne compatible
5488dc407927Smrgif test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then
5489dc407927Smrg  emulate sh
5490dc407927Smrg  NULLCMD=:
5491dc407927Smrg  # Zsh 3.x and 4.x performs word splitting on \${1+\"\$@\"}, which
5492dc407927Smrg  # is contrary to our usage.  Disable this feature.
5493dc407927Smrg  alias -g '\${1+\"\$@\"}'='\"\$@\"'
5494dc407927Smrg  setopt NO_GLOB_SUBST
5495dc407927Smrgelse
5496dc407927Smrg  case \`(set -o) 2>/dev/null\` in *posix*) set -o posix;; esac
5497dc407927Smrgfi
5498dc407927SmrgBIN_SH=xpg4; export BIN_SH # for Tru64
5499dc407927SmrgDUALCASE=1; export DUALCASE # for MKS sh
55003eed67faSmbalmer
5501dc407927Smrg# The HP-UX ksh and POSIX shell print the target directory to stdout
5502dc407927Smrg# if CDPATH is set.
5503dc407927Smrg(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
55043eed67faSmbalmer
5505dc407927Smrgrelink_command=\"$relink_command\"
55063eed67faSmbalmer
5507dc407927Smrg# This environment variable determines our operation mode.
5508dc407927Smrgif test \"\$libtool_install_magic\" = \"$magic\"; then
5509dc407927Smrg  # install mode needs the following variables:
5510dc407927Smrg  generated_by_libtool_version='$macro_version'
5511dc407927Smrg  notinst_deplibs='$notinst_deplibs'
5512dc407927Smrgelse
5513dc407927Smrg  # When we are sourced in execute mode, \$file and \$ECHO are already set.
5514dc407927Smrg  if test \"\$libtool_execute_magic\" != \"$magic\"; then
5515dd0822caSmrg    file=\"\$0\""
5516dd0822caSmrg
5517621f50c3Smrg    func_quote_arg pretty "$ECHO"
5518621f50c3Smrg    qECHO=$func_quote_arg_result
5519dd0822caSmrg    $ECHO "\
5520dd0822caSmrg
5521dd0822caSmrg# A function that is used when there is no print builtin or printf.
5522dd0822caSmrgfunc_fallback_echo ()
5523dd0822caSmrg{
5524dd0822caSmrg  eval 'cat <<_LTECHO_EOF
5525dd0822caSmrg\$1
5526dd0822caSmrg_LTECHO_EOF'
5527dd0822caSmrg}
5528621f50c3Smrg    ECHO=$qECHO
5529dd0822caSmrg  fi
5530dd0822caSmrg
5531dd0822caSmrg# Very basic option parsing. These options are (a) specific to
5532dd0822caSmrg# the libtool wrapper, (b) are identical between the wrapper
55331a9c160aSmrg# /script/ and the wrapper /executable/ that is used only on
5534dd0822caSmrg# windows platforms, and (c) all begin with the string "--lt-"
55351a9c160aSmrg# (application programs are unlikely to have options that match
5536dd0822caSmrg# this pattern).
5537dd0822caSmrg#
5538dd0822caSmrg# There are only two supported options: --lt-debug and
5539dd0822caSmrg# --lt-dump-script. There is, deliberately, no --lt-help.
5540dd0822caSmrg#
5541dd0822caSmrg# The first argument to this parsing function should be the
5542dd0822caSmrg# script's $0 value, followed by "$@".
5543dd0822caSmrglt_option_debug=
5544dd0822caSmrgfunc_parse_lt_options ()
5545dd0822caSmrg{
5546dd0822caSmrg  lt_script_arg0=\$0
5547dd0822caSmrg  shift
5548dd0822caSmrg  for lt_opt
5549dd0822caSmrg  do
5550dd0822caSmrg    case \"\$lt_opt\" in
5551dd0822caSmrg    --lt-debug) lt_option_debug=1 ;;
5552dd0822caSmrg    --lt-dump-script)
5553dd0822caSmrg        lt_dump_D=\`\$ECHO \"X\$lt_script_arg0\" | $SED -e 's/^X//' -e 's%/[^/]*$%%'\`
5554dd0822caSmrg        test \"X\$lt_dump_D\" = \"X\$lt_script_arg0\" && lt_dump_D=.
5555dd0822caSmrg        lt_dump_F=\`\$ECHO \"X\$lt_script_arg0\" | $SED -e 's/^X//' -e 's%^.*/%%'\`
5556dd0822caSmrg        cat \"\$lt_dump_D/\$lt_dump_F\"
5557dd0822caSmrg        exit 0
5558dd0822caSmrg      ;;
5559dd0822caSmrg    --lt-*)
5560dd0822caSmrg        \$ECHO \"Unrecognized --lt- option: '\$lt_opt'\" 1>&2
5561dd0822caSmrg        exit 1
5562dd0822caSmrg      ;;
5563dd0822caSmrg    esac
5564dd0822caSmrg  done
5565dd0822caSmrg
5566dd0822caSmrg  # Print the debug banner immediately:
5567dd0822caSmrg  if test -n \"\$lt_option_debug\"; then
55681a9c160aSmrg    echo \"$outputname:$output:\$LINENO: libtool wrapper (GNU $PACKAGE) $VERSION\" 1>&2
5569dd0822caSmrg  fi
5570dd0822caSmrg}
5571dd0822caSmrg
5572dd0822caSmrg# Used when --lt-debug. Prints its arguments to stdout
5573dd0822caSmrg# (redirection is the responsibility of the caller)
5574dd0822caSmrgfunc_lt_dump_args ()
5575dd0822caSmrg{
5576dd0822caSmrg  lt_dump_args_N=1;
5577dd0822caSmrg  for lt_arg
5578dd0822caSmrg  do
55791a9c160aSmrg    \$ECHO \"$outputname:$output:\$LINENO: newargv[\$lt_dump_args_N]: \$lt_arg\"
5580dd0822caSmrg    lt_dump_args_N=\`expr \$lt_dump_args_N + 1\`
5581dd0822caSmrg  done
5582dd0822caSmrg}
5583dd0822caSmrg
5584dd0822caSmrg# Core function for launching the target application
5585dd0822caSmrgfunc_exec_program_core ()
5586dd0822caSmrg{
5587dc407927Smrg"
5588dd0822caSmrg  case $host in
5589dd0822caSmrg  # Backslashes separate directories on plain windows
5590dd0822caSmrg  *-*-mingw | *-*-os2* | *-cegcc*)
5591dd0822caSmrg    $ECHO "\
5592dd0822caSmrg      if test -n \"\$lt_option_debug\"; then
55931a9c160aSmrg        \$ECHO \"$outputname:$output:\$LINENO: newargv[0]: \$progdir\\\\\$program\" 1>&2
5594dd0822caSmrg        func_lt_dump_args \${1+\"\$@\"} 1>&2
5595dd0822caSmrg      fi
5596dd0822caSmrg      exec \"\$progdir\\\\\$program\" \${1+\"\$@\"}
5597dd0822caSmrg"
5598dd0822caSmrg    ;;
5599dd0822caSmrg
5600dd0822caSmrg  *)
5601dd0822caSmrg    $ECHO "\
5602dd0822caSmrg      if test -n \"\$lt_option_debug\"; then
56031a9c160aSmrg        \$ECHO \"$outputname:$output:\$LINENO: newargv[0]: \$progdir/\$program\" 1>&2
5604dd0822caSmrg        func_lt_dump_args \${1+\"\$@\"} 1>&2
5605dd0822caSmrg      fi
5606dd0822caSmrg      exec \"\$progdir/\$program\" \${1+\"\$@\"}
5607dd0822caSmrg"
5608dd0822caSmrg    ;;
5609dd0822caSmrg  esac
5610dd0822caSmrg  $ECHO "\
5611dd0822caSmrg      \$ECHO \"\$0: cannot exec \$program \$*\" 1>&2
5612dd0822caSmrg      exit 1
5613dd0822caSmrg}
5614dd0822caSmrg
5615dd0822caSmrg# A function to encapsulate launching the target application
5616dd0822caSmrg# Strips options in the --lt-* namespace from \$@ and
5617dd0822caSmrg# launches target application with the remaining arguments.
5618dd0822caSmrgfunc_exec_program ()
5619dd0822caSmrg{
562075cbef56Smrg  case \" \$* \" in
562175cbef56Smrg  *\\ --lt-*)
562275cbef56Smrg    for lt_wr_arg
562375cbef56Smrg    do
562475cbef56Smrg      case \$lt_wr_arg in
562575cbef56Smrg      --lt-*) ;;
562675cbef56Smrg      *) set x \"\$@\" \"\$lt_wr_arg\"; shift;;
562775cbef56Smrg      esac
562875cbef56Smrg      shift
562975cbef56Smrg    done ;;
563075cbef56Smrg  esac
5631dd0822caSmrg  func_exec_program_core \${1+\"\$@\"}
5632dd0822caSmrg}
5633dd0822caSmrg
5634dd0822caSmrg  # Parse options
5635dd0822caSmrg  func_parse_lt_options \"\$0\" \${1+\"\$@\"}
56363eed67faSmbalmer
5637dc407927Smrg  # Find the directory that this script lives in.
5638dd0822caSmrg  thisdir=\`\$ECHO \"\$file\" | $SED 's%/[^/]*$%%'\`
5639dc407927Smrg  test \"x\$thisdir\" = \"x\$file\" && thisdir=.
56403eed67faSmbalmer
5641dc407927Smrg  # Follow symbolic links until we get to the real thisdir.
5642dd0822caSmrg  file=\`ls -ld \"\$file\" | $SED -n 's/.*-> //p'\`
5643dc407927Smrg  while test -n \"\$file\"; do
5644dd0822caSmrg    destdir=\`\$ECHO \"\$file\" | $SED 's%/[^/]*\$%%'\`
56453eed67faSmbalmer
5646dc407927Smrg    # If there was a directory component, then change thisdir.
5647dc407927Smrg    if test \"x\$destdir\" != \"x\$file\"; then
5648dc407927Smrg      case \"\$destdir\" in
5649dc407927Smrg      [\\\\/]* | [A-Za-z]:[\\\\/]*) thisdir=\"\$destdir\" ;;
5650dc407927Smrg      *) thisdir=\"\$thisdir/\$destdir\" ;;
56513eed67faSmbalmer      esac
5652dc407927Smrg    fi
56533eed67faSmbalmer
5654dd0822caSmrg    file=\`\$ECHO \"\$file\" | $SED 's%^.*/%%'\`
5655dd0822caSmrg    file=\`ls -ld \"\$thisdir/\$file\" | $SED -n 's/.*-> //p'\`
5656dc407927Smrg  done
56573eed67faSmbalmer
5658dc407927Smrg  # Usually 'no', except on cygwin/mingw when embedded into
5659dc407927Smrg  # the cwrapper.
5660dd0822caSmrg  WRAPPER_SCRIPT_BELONGS_IN_OBJDIR=$func_emit_wrapper_arg1
5661dc407927Smrg  if test \"\$WRAPPER_SCRIPT_BELONGS_IN_OBJDIR\" = \"yes\"; then
5662dc407927Smrg    # special case for '.'
5663dc407927Smrg    if test \"\$thisdir\" = \".\"; then
5664dc407927Smrg      thisdir=\`pwd\`
5665dc407927Smrg    fi
5666dc407927Smrg    # remove .libs from thisdir
5667dc407927Smrg    case \"\$thisdir\" in
5668dd0822caSmrg    *[\\\\/]$objdir ) thisdir=\`\$ECHO \"\$thisdir\" | $SED 's%[\\\\/][^\\\\/]*$%%'\` ;;
5669dc407927Smrg    $objdir )   thisdir=. ;;
5670dc407927Smrg    esac
5671dc407927Smrg  fi
5672dc407927Smrg
5673dc407927Smrg  # Try to get the absolute directory name.
5674dc407927Smrg  absdir=\`cd \"\$thisdir\" && pwd\`
5675dc407927Smrg  test -n \"\$absdir\" && thisdir=\"\$absdir\"
5676dc407927Smrg"
5677dc407927Smrg
56781a9c160aSmrg	if test yes = "$fast_install"; then
5679dc407927Smrg	  $ECHO "\
5680dc407927Smrg  program=lt-'$outputname'$exeext
5681dc407927Smrg  progdir=\"\$thisdir/$objdir\"
5682dc407927Smrg
5683dc407927Smrg  if test ! -f \"\$progdir/\$program\" ||
56841a9c160aSmrg     { file=\`ls -1dt \"\$progdir/\$program\" \"\$progdir/../\$program\" 2>/dev/null | $SED 1q\`; \\
5685dc407927Smrg       test \"X\$file\" != \"X\$progdir/\$program\"; }; then
5686dc407927Smrg
5687dc407927Smrg    file=\"\$\$-\$program\"
5688dc407927Smrg
5689dc407927Smrg    if test ! -d \"\$progdir\"; then
5690dc407927Smrg      $MKDIR \"\$progdir\"
5691dc407927Smrg    else
5692dc407927Smrg      $RM \"\$progdir/\$file\"
5693dc407927Smrg    fi"
5694dc407927Smrg
5695dc407927Smrg	  $ECHO "\
5696dc407927Smrg
5697dc407927Smrg    # relink executable if necessary
5698dc407927Smrg    if test -n \"\$relink_command\"; then
5699dc407927Smrg      if relink_command_output=\`eval \$relink_command 2>&1\`; then :
5700dc407927Smrg      else
57011a9c160aSmrg	\$ECHO \"\$relink_command_output\" >&2
5702dc407927Smrg	$RM \"\$progdir/\$file\"
5703dc407927Smrg	exit 1
57043eed67faSmbalmer      fi
5705dc407927Smrg    fi
57063eed67faSmbalmer
5707dc407927Smrg    $MV \"\$progdir/\$file\" \"\$progdir/\$program\" 2>/dev/null ||
5708dc407927Smrg    { $RM \"\$progdir/\$program\";
5709dc407927Smrg      $MV \"\$progdir/\$file\" \"\$progdir/\$program\"; }
5710dc407927Smrg    $RM \"\$progdir/\$file\"
5711dc407927Smrg  fi"
5712dc407927Smrg	else
5713dc407927Smrg	  $ECHO "\
5714dc407927Smrg  program='$outputname'
5715dc407927Smrg  progdir=\"\$thisdir/$objdir\"
5716dc407927Smrg"
57173eed67faSmbalmer	fi
57183eed67faSmbalmer
5719dc407927Smrg	$ECHO "\
57203eed67faSmbalmer
5721dc407927Smrg  if test -f \"\$progdir/\$program\"; then"
57223eed67faSmbalmer
5723dd0822caSmrg	# fixup the dll searchpath if we need to.
5724dd0822caSmrg	#
5725dd0822caSmrg	# Fix the DLL searchpath if we need to.  Do this before prepending
5726dd0822caSmrg	# to shlibpath, because on Windows, both are PATH and uninstalled
5727dd0822caSmrg	# libraries must come first.
5728dd0822caSmrg	if test -n "$dllsearchpath"; then
5729dd0822caSmrg	  $ECHO "\
5730dd0822caSmrg    # Add the dll search path components to the executable PATH
5731dd0822caSmrg    PATH=$dllsearchpath:\$PATH
5732dd0822caSmrg"
5733dd0822caSmrg	fi
5734dd0822caSmrg
5735dc407927Smrg	# Export our shlibpath_var if we have one.
57361a9c160aSmrg	if test yes = "$shlibpath_overrides_runpath" && test -n "$shlibpath_var" && test -n "$temp_rpath"; then
5737dc407927Smrg	  $ECHO "\
5738dc407927Smrg    # Add our own library path to $shlibpath_var
5739dc407927Smrg    $shlibpath_var=\"$temp_rpath\$$shlibpath_var\"
5740dc407927Smrg
5741dc407927Smrg    # Some systems cannot cope with colon-terminated $shlibpath_var
5742dc407927Smrg    # The second colon is a workaround for a bug in BeOS R4 sed
5743dd0822caSmrg    $shlibpath_var=\`\$ECHO \"\$$shlibpath_var\" | $SED 's/::*\$//'\`
57443eed67faSmbalmer
5745dc407927Smrg    export $shlibpath_var
5746dc407927Smrg"
57473eed67faSmbalmer	fi
57483eed67faSmbalmer
5749dc407927Smrg	$ECHO "\
5750dc407927Smrg    if test \"\$libtool_execute_magic\" != \"$magic\"; then
5751dc407927Smrg      # Run the actual program with our arguments.
5752dd0822caSmrg      func_exec_program \${1+\"\$@\"}
5753dc407927Smrg    fi
5754dc407927Smrg  else
5755dc407927Smrg    # The program doesn't exist.
57561a9c160aSmrg    \$ECHO \"\$0: error: '\$progdir/\$program' does not exist\" 1>&2
5757dc407927Smrg    \$ECHO \"This script is just a wrapper for \$program.\" 1>&2
5758dd0822caSmrg    \$ECHO \"See the $PACKAGE documentation for more information.\" 1>&2
5759dc407927Smrg    exit 1
5760dc407927Smrg  fi
5761dc407927Smrgfi\
5762dc407927Smrg"
5763dc407927Smrg}
57643eed67faSmbalmer
57653eed67faSmbalmer
5766dc407927Smrg# func_emit_cwrapperexe_src
5767dc407927Smrg# emit the source code for a wrapper executable on stdout
5768dc407927Smrg# Must ONLY be called from within func_mode_link because
5769dc407927Smrg# it depends on a number of variable set therein.
5770dc407927Smrgfunc_emit_cwrapperexe_src ()
5771dc407927Smrg{
5772dc407927Smrg	cat <<EOF
57733eed67faSmbalmer
5774dc407927Smrg/* $cwrappersource - temporary wrapper executable for $objdir/$outputname
57751a9c160aSmrg   Generated by $PROGRAM (GNU $PACKAGE) $VERSION
57763eed67faSmbalmer
5777dc407927Smrg   The $output program cannot be directly executed until all the libtool
5778dc407927Smrg   libraries that it depends on are installed.
57793eed67faSmbalmer
5780dc407927Smrg   This wrapper executable should never be moved out of the build directory.
5781dc407927Smrg   If it is, it will not operate correctly.
5782dc407927Smrg*/
5783dc407927SmrgEOF
5784dc407927Smrg	    cat <<"EOF"
5785dd0822caSmrg#ifdef _MSC_VER
5786dd0822caSmrg# define _CRT_SECURE_NO_DEPRECATE 1
5787dd0822caSmrg#endif
5788dc407927Smrg#include <stdio.h>
5789dc407927Smrg#include <stdlib.h>
5790dc407927Smrg#ifdef _MSC_VER
5791dc407927Smrg# include <direct.h>
5792dc407927Smrg# include <process.h>
5793dc407927Smrg# include <io.h>
5794dc407927Smrg#else
5795dc407927Smrg# include <unistd.h>
5796dc407927Smrg# include <stdint.h>
5797dc407927Smrg# ifdef __CYGWIN__
5798dc407927Smrg#  include <io.h>
5799dc407927Smrg# endif
5800dc407927Smrg#endif
5801dc407927Smrg#include <malloc.h>
5802dc407927Smrg#include <stdarg.h>
5803dc407927Smrg#include <assert.h>
5804dc407927Smrg#include <string.h>
5805dc407927Smrg#include <ctype.h>
5806dc407927Smrg#include <errno.h>
5807dc407927Smrg#include <fcntl.h>
5808dc407927Smrg#include <sys/stat.h>
58093eed67faSmbalmer
58101a9c160aSmrg#define STREQ(s1, s2) (strcmp ((s1), (s2)) == 0)
58111a9c160aSmrg
5812dd0822caSmrg/* declarations of non-ANSI functions */
58131a9c160aSmrg#if defined __MINGW32__
5814dd0822caSmrg# ifdef __STRICT_ANSI__
5815dd0822caSmrgint _putenv (const char *);
5816dd0822caSmrg# endif
58171a9c160aSmrg#elif defined __CYGWIN__
5818dd0822caSmrg# ifdef __STRICT_ANSI__
5819dd0822caSmrgchar *realpath (const char *, char *);
5820dd0822caSmrgint putenv (char *);
5821dd0822caSmrgint setenv (const char *, const char *, int);
5822dd0822caSmrg# endif
58231a9c160aSmrg/* #elif defined other_platform || defined ... */
5824dd0822caSmrg#endif
5825dd0822caSmrg
5826dd0822caSmrg/* portability defines, excluding path handling macros */
58271a9c160aSmrg#if defined _MSC_VER
5828dd0822caSmrg# define setmode _setmode
5829dd0822caSmrg# define stat    _stat
5830dd0822caSmrg# define chmod   _chmod
5831dd0822caSmrg# define getcwd  _getcwd
5832dd0822caSmrg# define putenv  _putenv
5833dd0822caSmrg# define S_IXUSR _S_IEXEC
58341a9c160aSmrg#elif defined __MINGW32__
5835dd0822caSmrg# define setmode _setmode
5836dd0822caSmrg# define stat    _stat
5837dd0822caSmrg# define chmod   _chmod
5838dd0822caSmrg# define getcwd  _getcwd
5839dd0822caSmrg# define putenv  _putenv
58401a9c160aSmrg#elif defined __CYGWIN__
5841dd0822caSmrg# define HAVE_SETENV
5842dd0822caSmrg# define FOPEN_WB "wb"
58431a9c160aSmrg/* #elif defined other platforms ... */
5844dd0822caSmrg#endif
5845dd0822caSmrg
58461a9c160aSmrg#if defined PATH_MAX
5847dc407927Smrg# define LT_PATHMAX PATH_MAX
58481a9c160aSmrg#elif defined MAXPATHLEN
5849dc407927Smrg# define LT_PATHMAX MAXPATHLEN
5850dc407927Smrg#else
5851dc407927Smrg# define LT_PATHMAX 1024
5852dc407927Smrg#endif
58533eed67faSmbalmer
5854dc407927Smrg#ifndef S_IXOTH
5855dc407927Smrg# define S_IXOTH 0
5856dc407927Smrg#endif
5857dc407927Smrg#ifndef S_IXGRP
5858dc407927Smrg# define S_IXGRP 0
5859dc407927Smrg#endif
58603eed67faSmbalmer
5861dd0822caSmrg/* path handling portability macros */
5862dc407927Smrg#ifndef DIR_SEPARATOR
5863dc407927Smrg# define DIR_SEPARATOR '/'
5864dc407927Smrg# define PATH_SEPARATOR ':'
5865dc407927Smrg#endif
58663eed67faSmbalmer
58671a9c160aSmrg#if defined _WIN32 || defined __MSDOS__ || defined __DJGPP__ || \
58681a9c160aSmrg  defined __OS2__
5869dc407927Smrg# define HAVE_DOS_BASED_FILE_SYSTEM
5870dc407927Smrg# define FOPEN_WB "wb"
5871dc407927Smrg# ifndef DIR_SEPARATOR_2
5872dc407927Smrg#  define DIR_SEPARATOR_2 '\\'
5873dc407927Smrg# endif
5874dc407927Smrg# ifndef PATH_SEPARATOR_2
5875dc407927Smrg#  define PATH_SEPARATOR_2 ';'
5876dc407927Smrg# endif
5877dc407927Smrg#endif
58783eed67faSmbalmer
5879dc407927Smrg#ifndef DIR_SEPARATOR_2
5880dc407927Smrg# define IS_DIR_SEPARATOR(ch) ((ch) == DIR_SEPARATOR)
5881dc407927Smrg#else /* DIR_SEPARATOR_2 */
5882dc407927Smrg# define IS_DIR_SEPARATOR(ch) \
5883dc407927Smrg	(((ch) == DIR_SEPARATOR) || ((ch) == DIR_SEPARATOR_2))
5884dc407927Smrg#endif /* DIR_SEPARATOR_2 */
58853eed67faSmbalmer
5886dc407927Smrg#ifndef PATH_SEPARATOR_2
5887dc407927Smrg# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR)
5888dc407927Smrg#else /* PATH_SEPARATOR_2 */
5889dc407927Smrg# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR_2)
5890dc407927Smrg#endif /* PATH_SEPARATOR_2 */
58913eed67faSmbalmer
5892dc407927Smrg#ifndef FOPEN_WB
5893dc407927Smrg# define FOPEN_WB "w"
5894dc407927Smrg#endif
5895dc407927Smrg#ifndef _O_BINARY
5896dc407927Smrg# define _O_BINARY 0
5897dc407927Smrg#endif
58983eed67faSmbalmer
5899dc407927Smrg#define XMALLOC(type, num)      ((type *) xmalloc ((num) * sizeof(type)))
5900dc407927Smrg#define XFREE(stale) do { \
59011a9c160aSmrg  if (stale) { free (stale); stale = 0; } \
5902dc407927Smrg} while (0)
59033eed67faSmbalmer
59041a9c160aSmrg#if defined LT_DEBUGWRAPPER
5905dd0822caSmrgstatic int lt_debug = 1;
5906dc407927Smrg#else
5907dd0822caSmrgstatic int lt_debug = 0;
5908dc407927Smrg#endif
59093eed67faSmbalmer
5910dd0822caSmrgconst char *program_name = "libtool-wrapper"; /* in case xstrdup fails */
59113eed67faSmbalmer
5912dc407927Smrgvoid *xmalloc (size_t num);
5913dc407927Smrgchar *xstrdup (const char *string);
5914dc407927Smrgconst char *base_name (const char *name);
5915dc407927Smrgchar *find_executable (const char *wrapper);
5916dc407927Smrgchar *chase_symlinks (const char *pathspec);
5917dc407927Smrgint make_executable (const char *path);
5918dc407927Smrgint check_executable (const char *path);
5919dc407927Smrgchar *strendzap (char *str, const char *pat);
5920dd0822caSmrgvoid lt_debugprintf (const char *file, int line, const char *fmt, ...);
5921dd0822caSmrgvoid lt_fatal (const char *file, int line, const char *message, ...);
5922dd0822caSmrgstatic const char *nonnull (const char *s);
5923dd0822caSmrgstatic const char *nonempty (const char *s);
5924dc407927Smrgvoid lt_setenv (const char *name, const char *value);
5925dc407927Smrgchar *lt_extend_str (const char *orig_value, const char *add, int to_end);
5926dc407927Smrgvoid lt_update_exe_path (const char *name, const char *value);
5927dc407927Smrgvoid lt_update_lib_path (const char *name, const char *value);
5928dd0822caSmrgchar **prepare_spawn (char **argv);
5929dd0822caSmrgvoid lt_dump_script (FILE *f);
5930dc407927SmrgEOF
5931dc407927Smrg
5932dc407927Smrg	    cat <<EOF
59331a9c160aSmrg#if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 5)
59341a9c160aSmrg# define externally_visible volatile
59351a9c160aSmrg#else
59361a9c160aSmrg# define externally_visible __attribute__((externally_visible)) volatile
59371a9c160aSmrg#endif
59381a9c160aSmrgexternally_visible const char * MAGIC_EXE = "$magic_exe";
5939dc407927Smrgconst char * LIB_PATH_VARNAME = "$shlibpath_var";
5940dc407927SmrgEOF
59413eed67faSmbalmer
59421a9c160aSmrg	    if test yes = "$shlibpath_overrides_runpath" && test -n "$shlibpath_var" && test -n "$temp_rpath"; then
5943dd0822caSmrg              func_to_host_path "$temp_rpath"
5944dc407927Smrg	      cat <<EOF
5945dd0822caSmrgconst char * LIB_PATH_VALUE   = "$func_to_host_path_result";
5946dc407927SmrgEOF
5947dc407927Smrg	    else
5948dc407927Smrg	      cat <<"EOF"
5949dc407927Smrgconst char * LIB_PATH_VALUE   = "";
5950dc407927SmrgEOF
59513eed67faSmbalmer	    fi
59523eed67faSmbalmer
5953dc407927Smrg	    if test -n "$dllsearchpath"; then
5954dd0822caSmrg              func_to_host_path "$dllsearchpath:"
5955dc407927Smrg	      cat <<EOF
5956dc407927Smrgconst char * EXE_PATH_VARNAME = "PATH";
5957dd0822caSmrgconst char * EXE_PATH_VALUE   = "$func_to_host_path_result";
59583eed67faSmbalmerEOF
59593eed67faSmbalmer	    else
5960dc407927Smrg	      cat <<"EOF"
5961dc407927Smrgconst char * EXE_PATH_VARNAME = "";
5962dc407927Smrgconst char * EXE_PATH_VALUE   = "";
5963dc407927SmrgEOF
59643eed67faSmbalmer	    fi
5965dc407927Smrg
59661a9c160aSmrg	    if test yes = "$fast_install"; then
5967dc407927Smrg	      cat <<EOF
5968dc407927Smrgconst char * TARGET_PROGRAM_NAME = "lt-$outputname"; /* hopefully, no .exe */
5969dc407927SmrgEOF
59703eed67faSmbalmer	    else
5971dc407927Smrg	      cat <<EOF
5972dc407927Smrgconst char * TARGET_PROGRAM_NAME = "$outputname"; /* hopefully, no .exe */
5973dc407927SmrgEOF
59743eed67faSmbalmer	    fi
59753eed67faSmbalmer
59763eed67faSmbalmer
5977dc407927Smrg	    cat <<"EOF"
59783eed67faSmbalmer
5979dc407927Smrg#define LTWRAPPER_OPTION_PREFIX         "--lt-"
59803eed67faSmbalmer
5981dc407927Smrgstatic const char *ltwrapper_option_prefix = LTWRAPPER_OPTION_PREFIX;
5982dc407927Smrgstatic const char *dumpscript_opt       = LTWRAPPER_OPTION_PREFIX "dump-script";
5983dd0822caSmrgstatic const char *debug_opt            = LTWRAPPER_OPTION_PREFIX "debug";
59843eed67faSmbalmer
5985dc407927Smrgint
5986dc407927Smrgmain (int argc, char *argv[])
5987dc407927Smrg{
5988dc407927Smrg  char **newargz;
5989dc407927Smrg  int  newargc;
5990dc407927Smrg  char *tmp_pathspec;
5991dc407927Smrg  char *actual_cwrapper_path;
5992dc407927Smrg  char *actual_cwrapper_name;
5993dc407927Smrg  char *target_name;
5994dc407927Smrg  char *lt_argv_zero;
59951a9c160aSmrg  int rval = 127;
59963eed67faSmbalmer
5997dc407927Smrg  int i;
59983eed67faSmbalmer
5999dc407927Smrg  program_name = (char *) xstrdup (base_name (argv[0]));
60001a9c160aSmrg  newargz = XMALLOC (char *, (size_t) argc + 1);
60013eed67faSmbalmer
6002dd0822caSmrg  /* very simple arg parsing; don't want to rely on getopt
6003dd0822caSmrg   * also, copy all non cwrapper options to newargz, except
6004dd0822caSmrg   * argz[0], which is handled differently
6005dd0822caSmrg   */
6006dd0822caSmrg  newargc=0;
6007dc407927Smrg  for (i = 1; i < argc; i++)
6008dc407927Smrg    {
60091a9c160aSmrg      if (STREQ (argv[i], dumpscript_opt))
6010dc407927Smrg	{
6011dc407927SmrgEOF
60121a9c160aSmrg	    case $host in
6013dc407927Smrg	      *mingw* | *cygwin* )
6014dc407927Smrg		# make stdout use "unix" line endings
6015dc407927Smrg		echo "          setmode(1,_O_BINARY);"
6016dc407927Smrg		;;
6017dc407927Smrg	      esac
60183eed67faSmbalmer
6019dc407927Smrg	    cat <<"EOF"
6020dd0822caSmrg	  lt_dump_script (stdout);
6021dc407927Smrg	  return 0;
6022dc407927Smrg	}
60231a9c160aSmrg      if (STREQ (argv[i], debug_opt))
6024dd0822caSmrg	{
6025dd0822caSmrg          lt_debug = 1;
6026dd0822caSmrg          continue;
6027dd0822caSmrg	}
60281a9c160aSmrg      if (STREQ (argv[i], ltwrapper_option_prefix))
6029dd0822caSmrg        {
6030dd0822caSmrg          /* however, if there is an option in the LTWRAPPER_OPTION_PREFIX
6031dd0822caSmrg             namespace, but it is not one of the ones we know about and
6032dd0822caSmrg             have already dealt with, above (inluding dump-script), then
6033dd0822caSmrg             report an error. Otherwise, targets might begin to believe
6034dd0822caSmrg             they are allowed to use options in the LTWRAPPER_OPTION_PREFIX
6035dd0822caSmrg             namespace. The first time any user complains about this, we'll
6036dd0822caSmrg             need to make LTWRAPPER_OPTION_PREFIX a configure-time option
6037dd0822caSmrg             or a configure.ac-settable value.
6038dd0822caSmrg           */
6039dd0822caSmrg          lt_fatal (__FILE__, __LINE__,
6040dd0822caSmrg		    "unrecognized %s option: '%s'",
6041dd0822caSmrg                    ltwrapper_option_prefix, argv[i]);
6042dd0822caSmrg        }
6043dd0822caSmrg      /* otherwise ... */
6044dd0822caSmrg      newargz[++newargc] = xstrdup (argv[i]);
6045dc407927Smrg    }
6046dd0822caSmrg  newargz[++newargc] = NULL;
6047dd0822caSmrg
6048dd0822caSmrgEOF
6049dd0822caSmrg	    cat <<EOF
6050dd0822caSmrg  /* The GNU banner must be the first non-error debug message */
60511a9c160aSmrg  lt_debugprintf (__FILE__, __LINE__, "libtool wrapper (GNU $PACKAGE) $VERSION\n");
6052dd0822caSmrgEOF
6053dd0822caSmrg	    cat <<"EOF"
6054dd0822caSmrg  lt_debugprintf (__FILE__, __LINE__, "(main) argv[0]: %s\n", argv[0]);
6055dd0822caSmrg  lt_debugprintf (__FILE__, __LINE__, "(main) program_name: %s\n", program_name);
60563eed67faSmbalmer
6057dc407927Smrg  tmp_pathspec = find_executable (argv[0]);
6058dc407927Smrg  if (tmp_pathspec == NULL)
6059dd0822caSmrg    lt_fatal (__FILE__, __LINE__, "couldn't find %s", argv[0]);
6060dd0822caSmrg  lt_debugprintf (__FILE__, __LINE__,
6061dd0822caSmrg                  "(main) found exe (before symlink chase) at: %s\n",
6062dd0822caSmrg		  tmp_pathspec);
6063dc407927Smrg
6064dc407927Smrg  actual_cwrapper_path = chase_symlinks (tmp_pathspec);
6065dd0822caSmrg  lt_debugprintf (__FILE__, __LINE__,
6066dd0822caSmrg                  "(main) found exe (after symlink chase) at: %s\n",
6067dd0822caSmrg		  actual_cwrapper_path);
6068dc407927Smrg  XFREE (tmp_pathspec);
6069dc407927Smrg
6070dd0822caSmrg  actual_cwrapper_name = xstrdup (base_name (actual_cwrapper_path));
6071dc407927Smrg  strendzap (actual_cwrapper_path, actual_cwrapper_name);
6072dc407927Smrg
6073dc407927Smrg  /* wrapper name transforms */
6074dc407927Smrg  strendzap (actual_cwrapper_name, ".exe");
6075dc407927Smrg  tmp_pathspec = lt_extend_str (actual_cwrapper_name, ".exe", 1);
6076dc407927Smrg  XFREE (actual_cwrapper_name);
6077dc407927Smrg  actual_cwrapper_name = tmp_pathspec;
6078dc407927Smrg  tmp_pathspec = 0;
6079dc407927Smrg
6080dc407927Smrg  /* target_name transforms -- use actual target program name; might have lt- prefix */
6081dc407927Smrg  target_name = xstrdup (base_name (TARGET_PROGRAM_NAME));
6082dc407927Smrg  strendzap (target_name, ".exe");
6083dc407927Smrg  tmp_pathspec = lt_extend_str (target_name, ".exe", 1);
6084dc407927Smrg  XFREE (target_name);
6085dc407927Smrg  target_name = tmp_pathspec;
6086dc407927Smrg  tmp_pathspec = 0;
6087dc407927Smrg
6088dd0822caSmrg  lt_debugprintf (__FILE__, __LINE__,
6089dd0822caSmrg		  "(main) libtool target name: %s\n",
6090dd0822caSmrg		  target_name);
6091dc407927SmrgEOF
60923eed67faSmbalmer
6093dc407927Smrg	    cat <<EOF
6094dc407927Smrg  newargz[0] =
6095dc407927Smrg    XMALLOC (char, (strlen (actual_cwrapper_path) +
6096dc407927Smrg		    strlen ("$objdir") + 1 + strlen (actual_cwrapper_name) + 1));
6097dc407927Smrg  strcpy (newargz[0], actual_cwrapper_path);
6098dc407927Smrg  strcat (newargz[0], "$objdir");
6099dc407927Smrg  strcat (newargz[0], "/");
6100dc407927SmrgEOF
61013eed67faSmbalmer
6102dc407927Smrg	    cat <<"EOF"
6103dc407927Smrg  /* stop here, and copy so we don't have to do this twice */
6104dc407927Smrg  tmp_pathspec = xstrdup (newargz[0]);
61053eed67faSmbalmer
6106dc407927Smrg  /* do NOT want the lt- prefix here, so use actual_cwrapper_name */
6107dc407927Smrg  strcat (newargz[0], actual_cwrapper_name);
61083eed67faSmbalmer
6109dc407927Smrg  /* DO want the lt- prefix here if it exists, so use target_name */
6110dc407927Smrg  lt_argv_zero = lt_extend_str (tmp_pathspec, target_name, 1);
6111dc407927Smrg  XFREE (tmp_pathspec);
6112dc407927Smrg  tmp_pathspec = NULL;
6113dc407927SmrgEOF
61143eed67faSmbalmer
6115dc407927Smrg	    case $host_os in
6116dc407927Smrg	      mingw*)
6117dc407927Smrg	    cat <<"EOF"
6118dc407927Smrg  {
6119dc407927Smrg    char* p;
6120dc407927Smrg    while ((p = strchr (newargz[0], '\\')) != NULL)
6121dc407927Smrg      {
6122dc407927Smrg	*p = '/';
6123dc407927Smrg      }
6124dc407927Smrg    while ((p = strchr (lt_argv_zero, '\\')) != NULL)
6125dc407927Smrg      {
6126dc407927Smrg	*p = '/';
6127dc407927Smrg      }
6128dc407927Smrg  }
6129dc407927SmrgEOF
6130dc407927Smrg	    ;;
6131dc407927Smrg	    esac
61323eed67faSmbalmer
6133dc407927Smrg	    cat <<"EOF"
6134dc407927Smrg  XFREE (target_name);
6135dc407927Smrg  XFREE (actual_cwrapper_path);
6136dc407927Smrg  XFREE (actual_cwrapper_name);
61373eed67faSmbalmer
6138dc407927Smrg  lt_setenv ("BIN_SH", "xpg4"); /* for Tru64 */
6139dc407927Smrg  lt_setenv ("DUALCASE", "1");  /* for MSK sh */
6140dd0822caSmrg  /* Update the DLL searchpath.  EXE_PATH_VALUE ($dllsearchpath) must
6141dd0822caSmrg     be prepended before (that is, appear after) LIB_PATH_VALUE ($temp_rpath)
6142dd0822caSmrg     because on Windows, both *_VARNAMEs are PATH but uninstalled
6143dd0822caSmrg     libraries must come first. */
6144dc407927Smrg  lt_update_exe_path (EXE_PATH_VARNAME, EXE_PATH_VALUE);
6145dd0822caSmrg  lt_update_lib_path (LIB_PATH_VARNAME, LIB_PATH_VALUE);
61463eed67faSmbalmer
6147dd0822caSmrg  lt_debugprintf (__FILE__, __LINE__, "(main) lt_argv_zero: %s\n",
6148dd0822caSmrg		  nonnull (lt_argv_zero));
6149dc407927Smrg  for (i = 0; i < newargc; i++)
6150dc407927Smrg    {
6151dd0822caSmrg      lt_debugprintf (__FILE__, __LINE__, "(main) newargz[%d]: %s\n",
6152dd0822caSmrg		      i, nonnull (newargz[i]));
6153dc407927Smrg    }
61543eed67faSmbalmer
6155dc407927SmrgEOF
61563eed67faSmbalmer
6157dc407927Smrg	    case $host_os in
6158dc407927Smrg	      mingw*)
6159dc407927Smrg		cat <<"EOF"
6160dc407927Smrg  /* execv doesn't actually work on mingw as expected on unix */
6161dd0822caSmrg  newargz = prepare_spawn (newargz);
61621a9c160aSmrg  rval = (int) _spawnv (_P_WAIT, lt_argv_zero, (const char * const *) newargz);
6163dc407927Smrg  if (rval == -1)
6164dc407927Smrg    {
6165dc407927Smrg      /* failed to start process */
6166dd0822caSmrg      lt_debugprintf (__FILE__, __LINE__,
6167dd0822caSmrg		      "(main) failed to launch target \"%s\": %s\n",
6168dd0822caSmrg		      lt_argv_zero, nonnull (strerror (errno)));
6169dc407927Smrg      return 127;
6170dc407927Smrg    }
6171dc407927Smrg  return rval;
6172dc407927SmrgEOF
6173dc407927Smrg		;;
6174dc407927Smrg	      *)
6175dc407927Smrg		cat <<"EOF"
6176dc407927Smrg  execv (lt_argv_zero, newargz);
6177dc407927Smrg  return rval; /* =127, but avoids unused variable warning */
6178dc407927SmrgEOF
6179dc407927Smrg		;;
6180dc407927Smrg	    esac
61813eed67faSmbalmer
6182dc407927Smrg	    cat <<"EOF"
6183dc407927Smrg}
61843eed67faSmbalmer
6185dc407927Smrgvoid *
6186dc407927Smrgxmalloc (size_t num)
6187dc407927Smrg{
6188dc407927Smrg  void *p = (void *) malloc (num);
6189dc407927Smrg  if (!p)
6190dd0822caSmrg    lt_fatal (__FILE__, __LINE__, "memory exhausted");
61913eed67faSmbalmer
6192dc407927Smrg  return p;
6193dc407927Smrg}
61943eed67faSmbalmer
6195dc407927Smrgchar *
6196dc407927Smrgxstrdup (const char *string)
6197dc407927Smrg{
6198dc407927Smrg  return string ? strcpy ((char *) xmalloc (strlen (string) + 1),
6199dc407927Smrg			  string) : NULL;
6200dc407927Smrg}
62013eed67faSmbalmer
6202dc407927Smrgconst char *
6203dc407927Smrgbase_name (const char *name)
6204dc407927Smrg{
6205dc407927Smrg  const char *base;
62063eed67faSmbalmer
62071a9c160aSmrg#if defined HAVE_DOS_BASED_FILE_SYSTEM
6208dc407927Smrg  /* Skip over the disk name in MSDOS pathnames. */
6209dc407927Smrg  if (isalpha ((unsigned char) name[0]) && name[1] == ':')
6210dc407927Smrg    name += 2;
6211dc407927Smrg#endif
62123eed67faSmbalmer
6213dc407927Smrg  for (base = name; *name; name++)
6214dc407927Smrg    if (IS_DIR_SEPARATOR (*name))
6215dc407927Smrg      base = name + 1;
6216dc407927Smrg  return base;
6217dc407927Smrg}
62183eed67faSmbalmer
6219dc407927Smrgint
6220dc407927Smrgcheck_executable (const char *path)
6221dc407927Smrg{
6222dc407927Smrg  struct stat st;
62233eed67faSmbalmer
6224dd0822caSmrg  lt_debugprintf (__FILE__, __LINE__, "(check_executable): %s\n",
6225dd0822caSmrg                  nonempty (path));
6226dc407927Smrg  if ((!path) || (!*path))
6227dc407927Smrg    return 0;
62283eed67faSmbalmer
6229dc407927Smrg  if ((stat (path, &st) >= 0)
6230dc407927Smrg      && (st.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)))
6231dc407927Smrg    return 1;
6232dc407927Smrg  else
6233dc407927Smrg    return 0;
6234dc407927Smrg}
62353eed67faSmbalmer
6236dc407927Smrgint
6237dc407927Smrgmake_executable (const char *path)
6238dc407927Smrg{
6239dc407927Smrg  int rval = 0;
6240dc407927Smrg  struct stat st;
62413eed67faSmbalmer
6242dd0822caSmrg  lt_debugprintf (__FILE__, __LINE__, "(make_executable): %s\n",
6243dd0822caSmrg                  nonempty (path));
6244dc407927Smrg  if ((!path) || (!*path))
6245dc407927Smrg    return 0;
62463eed67faSmbalmer
6247dc407927Smrg  if (stat (path, &st) >= 0)
6248dc407927Smrg    {
6249dc407927Smrg      rval = chmod (path, st.st_mode | S_IXOTH | S_IXGRP | S_IXUSR);
6250dc407927Smrg    }
6251dc407927Smrg  return rval;
6252dc407927Smrg}
62533eed67faSmbalmer
6254dc407927Smrg/* Searches for the full path of the wrapper.  Returns
6255dc407927Smrg   newly allocated full path name if found, NULL otherwise
6256dc407927Smrg   Does not chase symlinks, even on platforms that support them.
6257dc407927Smrg*/
6258dc407927Smrgchar *
6259dc407927Smrgfind_executable (const char *wrapper)
6260dc407927Smrg{
6261dc407927Smrg  int has_slash = 0;
6262dc407927Smrg  const char *p;
6263dc407927Smrg  const char *p_next;
6264dc407927Smrg  /* static buffer for getcwd */
6265dc407927Smrg  char tmp[LT_PATHMAX + 1];
62661a9c160aSmrg  size_t tmp_len;
6267dc407927Smrg  char *concat_name;
62683eed67faSmbalmer
6269dd0822caSmrg  lt_debugprintf (__FILE__, __LINE__, "(find_executable): %s\n",
6270dd0822caSmrg                  nonempty (wrapper));
62713eed67faSmbalmer
6272dc407927Smrg  if ((wrapper == NULL) || (*wrapper == '\0'))
6273dc407927Smrg    return NULL;
62743eed67faSmbalmer
6275dc407927Smrg  /* Absolute path? */
62761a9c160aSmrg#if defined HAVE_DOS_BASED_FILE_SYSTEM
6277dc407927Smrg  if (isalpha ((unsigned char) wrapper[0]) && wrapper[1] == ':')
6278dc407927Smrg    {
6279dc407927Smrg      concat_name = xstrdup (wrapper);
6280dc407927Smrg      if (check_executable (concat_name))
6281dc407927Smrg	return concat_name;
6282dc407927Smrg      XFREE (concat_name);
6283dc407927Smrg    }
6284dc407927Smrg  else
6285dc407927Smrg    {
6286dc407927Smrg#endif
6287dc407927Smrg      if (IS_DIR_SEPARATOR (wrapper[0]))
6288dc407927Smrg	{
6289dc407927Smrg	  concat_name = xstrdup (wrapper);
6290dc407927Smrg	  if (check_executable (concat_name))
6291dc407927Smrg	    return concat_name;
6292dc407927Smrg	  XFREE (concat_name);
6293dc407927Smrg	}
62941a9c160aSmrg#if defined HAVE_DOS_BASED_FILE_SYSTEM
6295dc407927Smrg    }
6296dc407927Smrg#endif
62973eed67faSmbalmer
6298dc407927Smrg  for (p = wrapper; *p; p++)
6299dc407927Smrg    if (*p == '/')
6300dc407927Smrg      {
6301dc407927Smrg	has_slash = 1;
6302dc407927Smrg	break;
6303dc407927Smrg      }
6304dc407927Smrg  if (!has_slash)
6305dc407927Smrg    {
6306dc407927Smrg      /* no slashes; search PATH */
6307dc407927Smrg      const char *path = getenv ("PATH");
6308dc407927Smrg      if (path != NULL)
6309dc407927Smrg	{
6310dc407927Smrg	  for (p = path; *p; p = p_next)
6311dc407927Smrg	    {
6312dc407927Smrg	      const char *q;
6313dc407927Smrg	      size_t p_len;
6314dc407927Smrg	      for (q = p; *q; q++)
6315dc407927Smrg		if (IS_PATH_SEPARATOR (*q))
6316dc407927Smrg		  break;
63171a9c160aSmrg	      p_len = (size_t) (q - p);
6318dc407927Smrg	      p_next = (*q == '\0' ? q : q + 1);
6319dc407927Smrg	      if (p_len == 0)
6320dc407927Smrg		{
6321dc407927Smrg		  /* empty path: current directory */
6322dc407927Smrg		  if (getcwd (tmp, LT_PATHMAX) == NULL)
6323dd0822caSmrg		    lt_fatal (__FILE__, __LINE__, "getcwd failed: %s",
6324dd0822caSmrg                              nonnull (strerror (errno)));
6325dc407927Smrg		  tmp_len = strlen (tmp);
6326dc407927Smrg		  concat_name =
6327dc407927Smrg		    XMALLOC (char, tmp_len + 1 + strlen (wrapper) + 1);
6328dc407927Smrg		  memcpy (concat_name, tmp, tmp_len);
6329dc407927Smrg		  concat_name[tmp_len] = '/';
6330dc407927Smrg		  strcpy (concat_name + tmp_len + 1, wrapper);
6331dc407927Smrg		}
6332dc407927Smrg	      else
6333dc407927Smrg		{
6334dc407927Smrg		  concat_name =
6335dc407927Smrg		    XMALLOC (char, p_len + 1 + strlen (wrapper) + 1);
6336dc407927Smrg		  memcpy (concat_name, p, p_len);
6337dc407927Smrg		  concat_name[p_len] = '/';
6338dc407927Smrg		  strcpy (concat_name + p_len + 1, wrapper);
6339dc407927Smrg		}
6340dc407927Smrg	      if (check_executable (concat_name))
6341dc407927Smrg		return concat_name;
6342dc407927Smrg	      XFREE (concat_name);
6343dc407927Smrg	    }
6344dc407927Smrg	}
6345dc407927Smrg      /* not found in PATH; assume curdir */
6346dc407927Smrg    }
6347dc407927Smrg  /* Relative path | not found in path: prepend cwd */
6348dc407927Smrg  if (getcwd (tmp, LT_PATHMAX) == NULL)
6349dd0822caSmrg    lt_fatal (__FILE__, __LINE__, "getcwd failed: %s",
6350dd0822caSmrg              nonnull (strerror (errno)));
6351dc407927Smrg  tmp_len = strlen (tmp);
6352dc407927Smrg  concat_name = XMALLOC (char, tmp_len + 1 + strlen (wrapper) + 1);
6353dc407927Smrg  memcpy (concat_name, tmp, tmp_len);
6354dc407927Smrg  concat_name[tmp_len] = '/';
6355dc407927Smrg  strcpy (concat_name + tmp_len + 1, wrapper);
63563eed67faSmbalmer
6357dc407927Smrg  if (check_executable (concat_name))
6358dc407927Smrg    return concat_name;
6359dc407927Smrg  XFREE (concat_name);
6360dc407927Smrg  return NULL;
6361dc407927Smrg}
63623eed67faSmbalmer
6363dc407927Smrgchar *
6364dc407927Smrgchase_symlinks (const char *pathspec)
6365dc407927Smrg{
6366dc407927Smrg#ifndef S_ISLNK
6367dc407927Smrg  return xstrdup (pathspec);
6368dc407927Smrg#else
6369dc407927Smrg  char buf[LT_PATHMAX];
6370dc407927Smrg  struct stat s;
6371dc407927Smrg  char *tmp_pathspec = xstrdup (pathspec);
6372dc407927Smrg  char *p;
6373dc407927Smrg  int has_symlinks = 0;
6374dc407927Smrg  while (strlen (tmp_pathspec) && !has_symlinks)
6375dc407927Smrg    {
6376dd0822caSmrg      lt_debugprintf (__FILE__, __LINE__,
6377dd0822caSmrg		      "checking path component for symlinks: %s\n",
6378dd0822caSmrg		      tmp_pathspec);
6379dc407927Smrg      if (lstat (tmp_pathspec, &s) == 0)
6380dc407927Smrg	{
6381dc407927Smrg	  if (S_ISLNK (s.st_mode) != 0)
6382dc407927Smrg	    {
6383dc407927Smrg	      has_symlinks = 1;
6384dc407927Smrg	      break;
6385dc407927Smrg	    }
63863eed67faSmbalmer
6387dc407927Smrg	  /* search backwards for last DIR_SEPARATOR */
6388dc407927Smrg	  p = tmp_pathspec + strlen (tmp_pathspec) - 1;
6389dc407927Smrg	  while ((p > tmp_pathspec) && (!IS_DIR_SEPARATOR (*p)))
6390dc407927Smrg	    p--;
6391dc407927Smrg	  if ((p == tmp_pathspec) && (!IS_DIR_SEPARATOR (*p)))
6392dc407927Smrg	    {
6393dc407927Smrg	      /* no more DIR_SEPARATORS left */
6394dc407927Smrg	      break;
6395dc407927Smrg	    }
6396dc407927Smrg	  *p = '\0';
6397dc407927Smrg	}
6398dc407927Smrg      else
6399dc407927Smrg	{
6400dd0822caSmrg	  lt_fatal (__FILE__, __LINE__,
6401dd0822caSmrg		    "error accessing file \"%s\": %s",
6402dd0822caSmrg		    tmp_pathspec, nonnull (strerror (errno)));
6403dc407927Smrg	}
6404dc407927Smrg    }
6405dc407927Smrg  XFREE (tmp_pathspec);
64063eed67faSmbalmer
6407dc407927Smrg  if (!has_symlinks)
6408dc407927Smrg    {
6409dc407927Smrg      return xstrdup (pathspec);
6410dc407927Smrg    }
64113eed67faSmbalmer
6412dc407927Smrg  tmp_pathspec = realpath (pathspec, buf);
6413dc407927Smrg  if (tmp_pathspec == 0)
6414dc407927Smrg    {
6415dd0822caSmrg      lt_fatal (__FILE__, __LINE__,
6416dd0822caSmrg		"could not follow symlinks for %s", pathspec);
6417dc407927Smrg    }
6418dc407927Smrg  return xstrdup (tmp_pathspec);
6419dc407927Smrg#endif
6420dc407927Smrg}
64213eed67faSmbalmer
6422dc407927Smrgchar *
6423dc407927Smrgstrendzap (char *str, const char *pat)
6424dc407927Smrg{
6425dc407927Smrg  size_t len, patlen;
64263eed67faSmbalmer
6427dc407927Smrg  assert (str != NULL);
6428dc407927Smrg  assert (pat != NULL);
64293eed67faSmbalmer
6430dc407927Smrg  len = strlen (str);
6431dc407927Smrg  patlen = strlen (pat);
64323eed67faSmbalmer
6433dc407927Smrg  if (patlen <= len)
6434dc407927Smrg    {
6435dc407927Smrg      str += len - patlen;
64361a9c160aSmrg      if (STREQ (str, pat))
6437dc407927Smrg	*str = '\0';
6438dc407927Smrg    }
6439dc407927Smrg  return str;
6440dc407927Smrg}
64413eed67faSmbalmer
6442dd0822caSmrgvoid
6443dd0822caSmrglt_debugprintf (const char *file, int line, const char *fmt, ...)
6444dd0822caSmrg{
6445dd0822caSmrg  va_list args;
6446dd0822caSmrg  if (lt_debug)
6447dd0822caSmrg    {
6448dd0822caSmrg      (void) fprintf (stderr, "%s:%s:%d: ", program_name, file, line);
6449dd0822caSmrg      va_start (args, fmt);
6450dd0822caSmrg      (void) vfprintf (stderr, fmt, args);
6451dd0822caSmrg      va_end (args);
6452dd0822caSmrg    }
6453dd0822caSmrg}
6454dd0822caSmrg
6455dc407927Smrgstatic void
6456dd0822caSmrglt_error_core (int exit_status, const char *file,
6457dd0822caSmrg	       int line, const char *mode,
6458dc407927Smrg	       const char *message, va_list ap)
6459dc407927Smrg{
6460dd0822caSmrg  fprintf (stderr, "%s:%s:%d: %s: ", program_name, file, line, mode);
6461dc407927Smrg  vfprintf (stderr, message, ap);
6462dc407927Smrg  fprintf (stderr, ".\n");
64633eed67faSmbalmer
6464dc407927Smrg  if (exit_status >= 0)
6465dc407927Smrg    exit (exit_status);
6466dc407927Smrg}
64673eed67faSmbalmer
6468dc407927Smrgvoid
6469dd0822caSmrglt_fatal (const char *file, int line, const char *message, ...)
6470dc407927Smrg{
6471dc407927Smrg  va_list ap;
6472dc407927Smrg  va_start (ap, message);
6473dd0822caSmrg  lt_error_core (EXIT_FAILURE, file, line, "FATAL", message, ap);
6474dc407927Smrg  va_end (ap);
6475dc407927Smrg}
64763eed67faSmbalmer
6477dd0822caSmrgstatic const char *
6478dd0822caSmrgnonnull (const char *s)
6479dd0822caSmrg{
6480dd0822caSmrg  return s ? s : "(null)";
6481dd0822caSmrg}
6482dd0822caSmrg
6483dd0822caSmrgstatic const char *
6484dd0822caSmrgnonempty (const char *s)
6485dd0822caSmrg{
6486dd0822caSmrg  return (s && !*s) ? "(empty)" : nonnull (s);
6487dd0822caSmrg}
6488dd0822caSmrg
6489dc407927Smrgvoid
6490dc407927Smrglt_setenv (const char *name, const char *value)
6491dc407927Smrg{
6492dd0822caSmrg  lt_debugprintf (__FILE__, __LINE__,
6493dd0822caSmrg		  "(lt_setenv) setting '%s' to '%s'\n",
6494dd0822caSmrg                  nonnull (name), nonnull (value));
6495dc407927Smrg  {
6496dc407927Smrg#ifdef HAVE_SETENV
6497dc407927Smrg    /* always make a copy, for consistency with !HAVE_SETENV */
6498dc407927Smrg    char *str = xstrdup (value);
6499dc407927Smrg    setenv (name, str, 1);
6500dc407927Smrg#else
65011a9c160aSmrg    size_t len = strlen (name) + 1 + strlen (value) + 1;
6502dc407927Smrg    char *str = XMALLOC (char, len);
6503dc407927Smrg    sprintf (str, "%s=%s", name, value);
6504dc407927Smrg    if (putenv (str) != EXIT_SUCCESS)
6505dc407927Smrg      {
6506dc407927Smrg        XFREE (str);
6507dc407927Smrg      }
6508dc407927Smrg#endif
6509dc407927Smrg  }
6510dc407927Smrg}
65113eed67faSmbalmer
6512dc407927Smrgchar *
6513dc407927Smrglt_extend_str (const char *orig_value, const char *add, int to_end)
6514dc407927Smrg{
6515dc407927Smrg  char *new_value;
6516dc407927Smrg  if (orig_value && *orig_value)
6517dc407927Smrg    {
65181a9c160aSmrg      size_t orig_value_len = strlen (orig_value);
65191a9c160aSmrg      size_t add_len = strlen (add);
6520dc407927Smrg      new_value = XMALLOC (char, add_len + orig_value_len + 1);
6521dc407927Smrg      if (to_end)
6522dc407927Smrg        {
6523dc407927Smrg          strcpy (new_value, orig_value);
6524dc407927Smrg          strcpy (new_value + orig_value_len, add);
6525dc407927Smrg        }
6526dc407927Smrg      else
6527dc407927Smrg        {
6528dc407927Smrg          strcpy (new_value, add);
6529dc407927Smrg          strcpy (new_value + add_len, orig_value);
6530dc407927Smrg        }
6531dc407927Smrg    }
6532dc407927Smrg  else
6533dc407927Smrg    {
6534dc407927Smrg      new_value = xstrdup (add);
6535dc407927Smrg    }
6536dc407927Smrg  return new_value;
6537dc407927Smrg}
65383eed67faSmbalmer
6539dc407927Smrgvoid
6540dc407927Smrglt_update_exe_path (const char *name, const char *value)
6541dc407927Smrg{
6542dd0822caSmrg  lt_debugprintf (__FILE__, __LINE__,
6543dd0822caSmrg		  "(lt_update_exe_path) modifying '%s' by prepending '%s'\n",
6544dd0822caSmrg                  nonnull (name), nonnull (value));
65453eed67faSmbalmer
6546dc407927Smrg  if (name && *name && value && *value)
6547dc407927Smrg    {
6548dc407927Smrg      char *new_value = lt_extend_str (getenv (name), value, 0);
6549dc407927Smrg      /* some systems can't cope with a ':'-terminated path #' */
65501a9c160aSmrg      size_t len = strlen (new_value);
65511a9c160aSmrg      while ((len > 0) && IS_PATH_SEPARATOR (new_value[len-1]))
6552dc407927Smrg        {
65531a9c160aSmrg          new_value[--len] = '\0';
6554dc407927Smrg        }
6555dc407927Smrg      lt_setenv (name, new_value);
6556dc407927Smrg      XFREE (new_value);
6557dc407927Smrg    }
6558dc407927Smrg}
65593eed67faSmbalmer
6560dc407927Smrgvoid
6561dc407927Smrglt_update_lib_path (const char *name, const char *value)
6562dc407927Smrg{
6563dd0822caSmrg  lt_debugprintf (__FILE__, __LINE__,
6564dd0822caSmrg		  "(lt_update_lib_path) modifying '%s' by prepending '%s'\n",
6565dd0822caSmrg                  nonnull (name), nonnull (value));
65663eed67faSmbalmer
6567dc407927Smrg  if (name && *name && value && *value)
6568dc407927Smrg    {
6569dc407927Smrg      char *new_value = lt_extend_str (getenv (name), value, 0);
6570dc407927Smrg      lt_setenv (name, new_value);
6571dc407927Smrg      XFREE (new_value);
6572dc407927Smrg    }
6573dc407927Smrg}
65743eed67faSmbalmer
6575dd0822caSmrgEOF
6576dd0822caSmrg	    case $host_os in
6577dd0822caSmrg	      mingw*)
6578dd0822caSmrg		cat <<"EOF"
6579dd0822caSmrg
6580dd0822caSmrg/* Prepares an argument vector before calling spawn().
6581dd0822caSmrg   Note that spawn() does not by itself call the command interpreter
6582dd0822caSmrg     (getenv ("COMSPEC") != NULL ? getenv ("COMSPEC") :
6583dd0822caSmrg      ({ OSVERSIONINFO v; v.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
6584dd0822caSmrg         GetVersionEx(&v);
6585dd0822caSmrg         v.dwPlatformId == VER_PLATFORM_WIN32_NT;
6586dd0822caSmrg      }) ? "cmd.exe" : "command.com").
6587dd0822caSmrg   Instead it simply concatenates the arguments, separated by ' ', and calls
6588dd0822caSmrg   CreateProcess().  We must quote the arguments since Win32 CreateProcess()
6589dd0822caSmrg   interprets characters like ' ', '\t', '\\', '"' (but not '<' and '>') in a
6590dd0822caSmrg   special way:
6591dd0822caSmrg   - Space and tab are interpreted as delimiters. They are not treated as
6592dd0822caSmrg     delimiters if they are surrounded by double quotes: "...".
6593dd0822caSmrg   - Unescaped double quotes are removed from the input. Their only effect is
6594dd0822caSmrg     that within double quotes, space and tab are treated like normal
6595dd0822caSmrg     characters.
6596dd0822caSmrg   - Backslashes not followed by double quotes are not special.
6597dd0822caSmrg   - But 2*n+1 backslashes followed by a double quote become
6598dd0822caSmrg     n backslashes followed by a double quote (n >= 0):
6599dd0822caSmrg       \" -> "
6600dd0822caSmrg       \\\" -> \"
6601dd0822caSmrg       \\\\\" -> \\"
6602dd0822caSmrg */
6603dd0822caSmrg#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"
6604dd0822caSmrg#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"
6605dd0822caSmrgchar **
6606dd0822caSmrgprepare_spawn (char **argv)
6607dd0822caSmrg{
6608dd0822caSmrg  size_t argc;
6609dd0822caSmrg  char **new_argv;
6610dd0822caSmrg  size_t i;
6611dd0822caSmrg
6612dd0822caSmrg  /* Count number of arguments.  */
6613dd0822caSmrg  for (argc = 0; argv[argc] != NULL; argc++)
6614dd0822caSmrg    ;
6615dd0822caSmrg
6616dd0822caSmrg  /* Allocate new argument vector.  */
6617dd0822caSmrg  new_argv = XMALLOC (char *, argc + 1);
6618dd0822caSmrg
6619dd0822caSmrg  /* Put quoted arguments into the new argument vector.  */
6620dd0822caSmrg  for (i = 0; i < argc; i++)
6621dd0822caSmrg    {
6622dd0822caSmrg      const char *string = argv[i];
6623dd0822caSmrg
6624dd0822caSmrg      if (string[0] == '\0')
6625dd0822caSmrg	new_argv[i] = xstrdup ("\"\"");
6626dd0822caSmrg      else if (strpbrk (string, SHELL_SPECIAL_CHARS) != NULL)
6627dd0822caSmrg	{
6628dd0822caSmrg	  int quote_around = (strpbrk (string, SHELL_SPACE_CHARS) != NULL);
6629dd0822caSmrg	  size_t length;
6630dd0822caSmrg	  unsigned int backslashes;
6631dd0822caSmrg	  const char *s;
6632dd0822caSmrg	  char *quoted_string;
6633dd0822caSmrg	  char *p;
6634dd0822caSmrg
6635dd0822caSmrg	  length = 0;
6636dd0822caSmrg	  backslashes = 0;
6637dd0822caSmrg	  if (quote_around)
6638dd0822caSmrg	    length++;
6639dd0822caSmrg	  for (s = string; *s != '\0'; s++)
6640dd0822caSmrg	    {
6641dd0822caSmrg	      char c = *s;
6642dd0822caSmrg	      if (c == '"')
6643dd0822caSmrg		length += backslashes + 1;
6644dd0822caSmrg	      length++;
6645dd0822caSmrg	      if (c == '\\')
6646dd0822caSmrg		backslashes++;
6647dd0822caSmrg	      else
6648dd0822caSmrg		backslashes = 0;
6649dd0822caSmrg	    }
6650dd0822caSmrg	  if (quote_around)
6651dd0822caSmrg	    length += backslashes + 1;
6652dd0822caSmrg
6653dd0822caSmrg	  quoted_string = XMALLOC (char, length + 1);
6654dd0822caSmrg
6655dd0822caSmrg	  p = quoted_string;
6656dd0822caSmrg	  backslashes = 0;
6657dd0822caSmrg	  if (quote_around)
6658dd0822caSmrg	    *p++ = '"';
6659dd0822caSmrg	  for (s = string; *s != '\0'; s++)
6660dd0822caSmrg	    {
6661dd0822caSmrg	      char c = *s;
6662dd0822caSmrg	      if (c == '"')
6663dd0822caSmrg		{
6664dd0822caSmrg		  unsigned int j;
6665dd0822caSmrg		  for (j = backslashes + 1; j > 0; j--)
6666dd0822caSmrg		    *p++ = '\\';
6667dd0822caSmrg		}
6668dd0822caSmrg	      *p++ = c;
6669dd0822caSmrg	      if (c == '\\')
6670dd0822caSmrg		backslashes++;
6671dd0822caSmrg	      else
6672dd0822caSmrg		backslashes = 0;
6673dd0822caSmrg	    }
6674dd0822caSmrg	  if (quote_around)
6675dd0822caSmrg	    {
6676dd0822caSmrg	      unsigned int j;
6677dd0822caSmrg	      for (j = backslashes; j > 0; j--)
6678dd0822caSmrg		*p++ = '\\';
6679dd0822caSmrg	      *p++ = '"';
6680dd0822caSmrg	    }
6681dd0822caSmrg	  *p = '\0';
6682dd0822caSmrg
6683dd0822caSmrg	  new_argv[i] = quoted_string;
6684dd0822caSmrg	}
6685dd0822caSmrg      else
6686dd0822caSmrg	new_argv[i] = (char *) string;
6687dd0822caSmrg    }
6688dd0822caSmrg  new_argv[argc] = NULL;
6689dd0822caSmrg
6690dd0822caSmrg  return new_argv;
6691dd0822caSmrg}
6692dd0822caSmrgEOF
6693dd0822caSmrg		;;
6694dd0822caSmrg	    esac
6695dd0822caSmrg
6696dd0822caSmrg            cat <<"EOF"
6697dd0822caSmrgvoid lt_dump_script (FILE* f)
6698dd0822caSmrg{
6699dd0822caSmrgEOF
6700dd0822caSmrg	    func_emit_wrapper yes |
670175cbef56Smrg	      $SED -n -e '
670275cbef56Smrgs/^\(.\{79\}\)\(..*\)/\1\
670375cbef56Smrg\2/
670475cbef56Smrgh
670575cbef56Smrgs/\([\\"]\)/\\\1/g
670675cbef56Smrgs/$/\\n/
670775cbef56Smrgs/\([^\n]*\).*/  fputs ("\1", f);/p
670875cbef56Smrgg
670975cbef56SmrgD'
6710dd0822caSmrg            cat <<"EOF"
6711dd0822caSmrg}
6712dc407927SmrgEOF
6713dc407927Smrg}
6714dc407927Smrg# end: func_emit_cwrapperexe_src
67153eed67faSmbalmer
6716dd0822caSmrg# func_win32_import_lib_p ARG
6717dd0822caSmrg# True if ARG is an import lib, as indicated by $file_magic_cmd
6718dd0822caSmrgfunc_win32_import_lib_p ()
6719dd0822caSmrg{
67201a9c160aSmrg    $debug_cmd
67211a9c160aSmrg
6722dd0822caSmrg    case `eval $file_magic_cmd \"\$1\" 2>/dev/null | $SED -e 10q` in
6723dd0822caSmrg    *import*) : ;;
6724dd0822caSmrg    *) false ;;
6725dd0822caSmrg    esac
6726dd0822caSmrg}
6727dd0822caSmrg
67281a9c160aSmrg# func_suncc_cstd_abi
67291a9c160aSmrg# !!ONLY CALL THIS FOR SUN CC AFTER $compile_command IS FULLY EXPANDED!!
67301a9c160aSmrg# Several compiler flags select an ABI that is incompatible with the
67311a9c160aSmrg# Cstd library. Avoid specifying it if any are in CXXFLAGS.
67321a9c160aSmrgfunc_suncc_cstd_abi ()
67331a9c160aSmrg{
67341a9c160aSmrg    $debug_cmd
67351a9c160aSmrg
67361a9c160aSmrg    case " $compile_command " in
67371a9c160aSmrg    *" -compat=g "*|*\ -std=c++[0-9][0-9]\ *|*" -library=stdcxx4 "*|*" -library=stlport4 "*)
67381a9c160aSmrg      suncc_use_cstd_abi=no
67391a9c160aSmrg      ;;
67401a9c160aSmrg    *)
67411a9c160aSmrg      suncc_use_cstd_abi=yes
67421a9c160aSmrg      ;;
67431a9c160aSmrg    esac
67441a9c160aSmrg}
67451a9c160aSmrg
6746dc407927Smrg# func_mode_link arg...
6747dc407927Smrgfunc_mode_link ()
6748dc407927Smrg{
67491a9c160aSmrg    $debug_cmd
67501a9c160aSmrg
6751dc407927Smrg    case $host in
6752dc407927Smrg    *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
6753dc407927Smrg      # It is impossible to link a dll without this setting, and
6754dc407927Smrg      # we shouldn't force the makefile maintainer to figure out
67551a9c160aSmrg      # what system we are compiling for in order to pass an extra
6756dc407927Smrg      # flag for every libtool invocation.
6757dc407927Smrg      # allow_undefined=no
67583eed67faSmbalmer
6759dc407927Smrg      # FIXME: Unfortunately, there are problems with the above when trying
67601a9c160aSmrg      # to make a dll that has undefined symbols, in which case not
6761dc407927Smrg      # even a static library is built.  For now, we need to specify
6762dc407927Smrg      # -no-undefined on the libtool link line when we can be certain
6763dc407927Smrg      # that all symbols are satisfied, otherwise we get a static library.
6764dc407927Smrg      allow_undefined=yes
6765dc407927Smrg      ;;
6766dc407927Smrg    *)
6767dc407927Smrg      allow_undefined=yes
6768dc407927Smrg      ;;
6769dc407927Smrg    esac
6770dc407927Smrg    libtool_args=$nonopt
6771dc407927Smrg    base_compile="$nonopt $@"
6772dc407927Smrg    compile_command=$nonopt
6773dc407927Smrg    finalize_command=$nonopt
67743eed67faSmbalmer
6775dc407927Smrg    compile_rpath=
6776dc407927Smrg    finalize_rpath=
6777dc407927Smrg    compile_shlibpath=
6778dc407927Smrg    finalize_shlibpath=
6779dc407927Smrg    convenience=
6780dc407927Smrg    old_convenience=
6781dc407927Smrg    deplibs=
6782dc407927Smrg    old_deplibs=
6783dc407927Smrg    compiler_flags=
6784dc407927Smrg    linker_flags=
6785dc407927Smrg    dllsearchpath=
6786dc407927Smrg    lib_search_path=`pwd`
6787dc407927Smrg    inst_prefix_dir=
6788dc407927Smrg    new_inherited_linker_flags=
67893eed67faSmbalmer
6790dc407927Smrg    avoid_version=no
6791dd0822caSmrg    bindir=
6792dc407927Smrg    dlfiles=
6793dc407927Smrg    dlprefiles=
6794dc407927Smrg    dlself=no
6795dc407927Smrg    export_dynamic=no
6796dc407927Smrg    export_symbols=
6797dc407927Smrg    export_symbols_regex=
6798dc407927Smrg    generated=
6799dc407927Smrg    libobjs=
6800dc407927Smrg    ltlibs=
6801dc407927Smrg    module=no
6802dc407927Smrg    no_install=no
6803dc407927Smrg    objs=
68041a9c160aSmrg    os2dllname=
6805dc407927Smrg    non_pic_objects=
6806dc407927Smrg    precious_files_regex=
6807dc407927Smrg    prefer_static_libs=no
68081a9c160aSmrg    preload=false
6809dc407927Smrg    prev=
6810dc407927Smrg    prevarg=
6811dc407927Smrg    release=
6812dc407927Smrg    rpath=
6813dc407927Smrg    xrpath=
6814dc407927Smrg    perm_rpath=
6815dc407927Smrg    temp_rpath=
6816dc407927Smrg    thread_safe=no
6817dc407927Smrg    vinfo=
6818dc407927Smrg    vinfo_number=no
6819dc407927Smrg    weak_libs=
68201a9c160aSmrg    single_module=$wl-single_module
6821dc407927Smrg    func_infer_tag $base_compile
68223eed67faSmbalmer
6823dc407927Smrg    # We need to know -static, to get the right output filenames.
6824dc407927Smrg    for arg
6825dc407927Smrg    do
6826dc407927Smrg      case $arg in
6827dc407927Smrg      -shared)
68281a9c160aSmrg	test yes != "$build_libtool_libs" \
68291a9c160aSmrg	  && func_fatal_configuration "cannot build a shared library"
6830dc407927Smrg	build_old_libs=no
6831dc407927Smrg	break
6832dc407927Smrg	;;
6833dc407927Smrg      -all-static | -static | -static-libtool-libs)
6834dc407927Smrg	case $arg in
6835dc407927Smrg	-all-static)
68361a9c160aSmrg	  if test yes = "$build_libtool_libs" && test -z "$link_static_flag"; then
6837dc407927Smrg	    func_warning "complete static linking is impossible in this configuration"
6838dc407927Smrg	  fi
6839dc407927Smrg	  if test -n "$link_static_flag"; then
6840dc407927Smrg	    dlopen_self=$dlopen_self_static
6841dc407927Smrg	  fi
6842dc407927Smrg	  prefer_static_libs=yes
6843dc407927Smrg	  ;;
6844dc407927Smrg	-static)
6845dc407927Smrg	  if test -z "$pic_flag" && test -n "$link_static_flag"; then
6846dc407927Smrg	    dlopen_self=$dlopen_self_static
6847dc407927Smrg	  fi
6848dc407927Smrg	  prefer_static_libs=built
6849dc407927Smrg	  ;;
6850dc407927Smrg	-static-libtool-libs)
6851dc407927Smrg	  if test -z "$pic_flag" && test -n "$link_static_flag"; then
6852dc407927Smrg	    dlopen_self=$dlopen_self_static
6853dc407927Smrg	  fi
6854dc407927Smrg	  prefer_static_libs=yes
6855dc407927Smrg	  ;;
6856dc407927Smrg	esac
6857dc407927Smrg	build_libtool_libs=no
6858dc407927Smrg	build_old_libs=yes
6859dc407927Smrg	break
6860dc407927Smrg	;;
6861dc407927Smrg      esac
6862dc407927Smrg    done
68633eed67faSmbalmer
6864dc407927Smrg    # See if our shared archives depend on static archives.
6865dc407927Smrg    test -n "$old_archive_from_new_cmds" && build_old_libs=yes
68663eed67faSmbalmer
6867dc407927Smrg    # Go through the arguments, transforming them on the way.
6868dc407927Smrg    while test "$#" -gt 0; do
68691a9c160aSmrg      arg=$1
6870dc407927Smrg      shift
6871621f50c3Smrg      func_quote_arg pretty,unquoted "$arg"
6872621f50c3Smrg      qarg=$func_quote_arg_unquoted_result
6873621f50c3Smrg      func_append libtool_args " $func_quote_arg_result"
68743eed67faSmbalmer
6875dc407927Smrg      # If the previous option needs an argument, assign it.
6876dc407927Smrg      if test -n "$prev"; then
6877dc407927Smrg	case $prev in
6878dc407927Smrg	output)
6879dc407927Smrg	  func_append compile_command " @OUTPUT@"
6880dc407927Smrg	  func_append finalize_command " @OUTPUT@"
6881dc407927Smrg	  ;;
6882dc407927Smrg	esac
68833eed67faSmbalmer
6884dc407927Smrg	case $prev in
6885dd0822caSmrg	bindir)
68861a9c160aSmrg	  bindir=$arg
6887dd0822caSmrg	  prev=
6888dd0822caSmrg	  continue
6889dd0822caSmrg	  ;;
6890dc407927Smrg	dlfiles|dlprefiles)
68911a9c160aSmrg	  $preload || {
6892dc407927Smrg	    # Add the symbol object into the linking commands.
6893dc407927Smrg	    func_append compile_command " @SYMFILE@"
6894dc407927Smrg	    func_append finalize_command " @SYMFILE@"
68951a9c160aSmrg	    preload=:
68961a9c160aSmrg	  }
6897dc407927Smrg	  case $arg in
6898dc407927Smrg	  *.la | *.lo) ;;  # We handle these cases below.
6899dc407927Smrg	  force)
69001a9c160aSmrg	    if test no = "$dlself"; then
6901dc407927Smrg	      dlself=needless
6902dc407927Smrg	      export_dynamic=yes
6903dc407927Smrg	    fi
6904dc407927Smrg	    prev=
6905dc407927Smrg	    continue
6906dc407927Smrg	    ;;
6907dc407927Smrg	  self)
69081a9c160aSmrg	    if test dlprefiles = "$prev"; then
6909dc407927Smrg	      dlself=yes
69101a9c160aSmrg	    elif test dlfiles = "$prev" && test yes != "$dlopen_self"; then
6911dc407927Smrg	      dlself=yes
6912dc407927Smrg	    else
6913dc407927Smrg	      dlself=needless
6914dc407927Smrg	      export_dynamic=yes
6915dc407927Smrg	    fi
6916dc407927Smrg	    prev=
6917dc407927Smrg	    continue
6918dc407927Smrg	    ;;
6919dc407927Smrg	  *)
69201a9c160aSmrg	    if test dlfiles = "$prev"; then
6921dd0822caSmrg	      func_append dlfiles " $arg"
6922dc407927Smrg	    else
6923dd0822caSmrg	      func_append dlprefiles " $arg"
6924dc407927Smrg	    fi
6925dc407927Smrg	    prev=
6926dc407927Smrg	    continue
6927dc407927Smrg	    ;;
6928dc407927Smrg	  esac
6929dc407927Smrg	  ;;
6930dc407927Smrg	expsyms)
69311a9c160aSmrg	  export_symbols=$arg
6932dc407927Smrg	  test -f "$arg" \
69331a9c160aSmrg	    || func_fatal_error "symbol file '$arg' does not exist"
6934dc407927Smrg	  prev=
6935dc407927Smrg	  continue
6936dc407927Smrg	  ;;
6937dc407927Smrg	expsyms_regex)
69381a9c160aSmrg	  export_symbols_regex=$arg
6939dc407927Smrg	  prev=
6940dc407927Smrg	  continue
6941dc407927Smrg	  ;;
6942dc407927Smrg	framework)
69433eed67faSmbalmer	  case $host in
6944dc407927Smrg	    *-*-darwin*)
6945dc407927Smrg	      case "$deplibs " in
6946dc407927Smrg		*" $qarg.ltframework "*) ;;
6947dd0822caSmrg		*) func_append deplibs " $qarg.ltframework" # this is fixed later
6948dc407927Smrg		   ;;
6949dc407927Smrg	      esac
6950dc407927Smrg	      ;;
69513eed67faSmbalmer	  esac
6952dc407927Smrg	  prev=
6953dc407927Smrg	  continue
69543eed67faSmbalmer	  ;;
6955dc407927Smrg	inst_prefix)
69561a9c160aSmrg	  inst_prefix_dir=$arg
69571a9c160aSmrg	  prev=
69581a9c160aSmrg	  continue
69591a9c160aSmrg	  ;;
69601a9c160aSmrg	mllvm)
69611a9c160aSmrg	  # Clang does not use LLVM to link, so we can simply discard any
69621a9c160aSmrg	  # '-mllvm $arg' options when doing the link step.
6963dc407927Smrg	  prev=
6964dc407927Smrg	  continue
69653eed67faSmbalmer	  ;;
6966dc407927Smrg	objectlist)
6967dc407927Smrg	  if test -f "$arg"; then
6968dc407927Smrg	    save_arg=$arg
6969dc407927Smrg	    moreargs=
6970dc407927Smrg	    for fil in `cat "$save_arg"`
6971dc407927Smrg	    do
6972dd0822caSmrg#	      func_append moreargs " $fil"
6973dc407927Smrg	      arg=$fil
6974dc407927Smrg	      # A libtool-controlled object.
69753eed67faSmbalmer
6976dc407927Smrg	      # Check to see that this really is a libtool object.
6977dc407927Smrg	      if func_lalib_unsafe_p "$arg"; then
6978dc407927Smrg		pic_object=
6979dc407927Smrg		non_pic_object=
69803eed67faSmbalmer
6981dc407927Smrg		# Read the .lo file
6982dc407927Smrg		func_source "$arg"
69833eed67faSmbalmer
6984dc407927Smrg		if test -z "$pic_object" ||
6985dc407927Smrg		   test -z "$non_pic_object" ||
69861a9c160aSmrg		   test none = "$pic_object" &&
69871a9c160aSmrg		   test none = "$non_pic_object"; then
69881a9c160aSmrg		  func_fatal_error "cannot find name of object for '$arg'"
6989dc407927Smrg		fi
69903eed67faSmbalmer
6991dc407927Smrg		# Extract subdirectory from the argument.
6992dc407927Smrg		func_dirname "$arg" "/" ""
69931a9c160aSmrg		xdir=$func_dirname_result
69943eed67faSmbalmer
69951a9c160aSmrg		if test none != "$pic_object"; then
6996dc407927Smrg		  # Prepend the subdirectory the object is found in.
69971a9c160aSmrg		  pic_object=$xdir$pic_object
69983eed67faSmbalmer
69991a9c160aSmrg		  if test dlfiles = "$prev"; then
70001a9c160aSmrg		    if test yes = "$build_libtool_libs" && test yes = "$dlopen_support"; then
7001dd0822caSmrg		      func_append dlfiles " $pic_object"
7002dc407927Smrg		      prev=
7003dc407927Smrg		      continue
7004dc407927Smrg		    else
7005dc407927Smrg		      # If libtool objects are unsupported, then we need to preload.
7006dc407927Smrg		      prev=dlprefiles
7007dc407927Smrg		    fi
7008dc407927Smrg		  fi
70093eed67faSmbalmer
7010dc407927Smrg		  # CHECK ME:  I think I busted this.  -Ossama
70111a9c160aSmrg		  if test dlprefiles = "$prev"; then
7012dc407927Smrg		    # Preload the old-style object.
7013dd0822caSmrg		    func_append dlprefiles " $pic_object"
7014dc407927Smrg		    prev=
7015dc407927Smrg		  fi
70163eed67faSmbalmer
7017dc407927Smrg		  # A PIC object.
7018dc407927Smrg		  func_append libobjs " $pic_object"
70191a9c160aSmrg		  arg=$pic_object
7020dc407927Smrg		fi
70213eed67faSmbalmer
7022dc407927Smrg		# Non-PIC object.
70231a9c160aSmrg		if test none != "$non_pic_object"; then
7024dc407927Smrg		  # Prepend the subdirectory the object is found in.
70251a9c160aSmrg		  non_pic_object=$xdir$non_pic_object
7026dc407927Smrg
7027dc407927Smrg		  # A standard non-PIC object
7028dc407927Smrg		  func_append non_pic_objects " $non_pic_object"
70291a9c160aSmrg		  if test -z "$pic_object" || test none = "$pic_object"; then
70301a9c160aSmrg		    arg=$non_pic_object
7031dc407927Smrg		  fi
7032dc407927Smrg		else
7033dc407927Smrg		  # If the PIC object exists, use it instead.
7034dc407927Smrg		  # $xdir was prepended to $pic_object above.
70351a9c160aSmrg		  non_pic_object=$pic_object
7036dc407927Smrg		  func_append non_pic_objects " $non_pic_object"
7037dc407927Smrg		fi
7038dc407927Smrg	      else
7039dc407927Smrg		# Only an error if not doing a dry-run.
7040dc407927Smrg		if $opt_dry_run; then
7041dc407927Smrg		  # Extract subdirectory from the argument.
7042dc407927Smrg		  func_dirname "$arg" "/" ""
70431a9c160aSmrg		  xdir=$func_dirname_result
7044dc407927Smrg
7045dc407927Smrg		  func_lo2o "$arg"
7046dc407927Smrg		  pic_object=$xdir$objdir/$func_lo2o_result
7047dc407927Smrg		  non_pic_object=$xdir$func_lo2o_result
7048dc407927Smrg		  func_append libobjs " $pic_object"
7049dc407927Smrg		  func_append non_pic_objects " $non_pic_object"
7050dc407927Smrg	        else
70511a9c160aSmrg		  func_fatal_error "'$arg' is not a valid libtool object"
7052dc407927Smrg		fi
7053dc407927Smrg	      fi
7054dc407927Smrg	    done
70553eed67faSmbalmer	  else
70561a9c160aSmrg	    func_fatal_error "link input file '$arg' does not exist"
70573eed67faSmbalmer	  fi
7058dc407927Smrg	  arg=$save_arg
7059dc407927Smrg	  prev=
7060dc407927Smrg	  continue
7061dc407927Smrg	  ;;
70621a9c160aSmrg	os2dllname)
70631a9c160aSmrg	  os2dllname=$arg
70641a9c160aSmrg	  prev=
70651a9c160aSmrg	  continue
70661a9c160aSmrg	  ;;
7067dc407927Smrg	precious_regex)
70681a9c160aSmrg	  precious_files_regex=$arg
7069dc407927Smrg	  prev=
7070dc407927Smrg	  continue
7071dc407927Smrg	  ;;
7072dc407927Smrg	release)
70731a9c160aSmrg	  release=-$arg
7074dc407927Smrg	  prev=
7075dc407927Smrg	  continue
7076dc407927Smrg	  ;;
7077dc407927Smrg	rpath | xrpath)
7078dc407927Smrg	  # We need an absolute path.
7079dc407927Smrg	  case $arg in
7080dc407927Smrg	  [\\/]* | [A-Za-z]:[\\/]*) ;;
7081dc407927Smrg	  *)
7082dc407927Smrg	    func_fatal_error "only absolute run-paths are allowed"
7083dc407927Smrg	    ;;
7084dc407927Smrg	  esac
70851a9c160aSmrg	  if test rpath = "$prev"; then
7086dc407927Smrg	    case "$rpath " in
7087dc407927Smrg	    *" $arg "*) ;;
7088dd0822caSmrg	    *) func_append rpath " $arg" ;;
7089dc407927Smrg	    esac
70903eed67faSmbalmer	  else
7091dc407927Smrg	    case "$xrpath " in
7092dc407927Smrg	    *" $arg "*) ;;
7093dd0822caSmrg	    *) func_append xrpath " $arg" ;;
7094dc407927Smrg	    esac
70953eed67faSmbalmer	  fi
7096dc407927Smrg	  prev=
7097dc407927Smrg	  continue
7098dc407927Smrg	  ;;
7099dc407927Smrg	shrext)
71001a9c160aSmrg	  shrext_cmds=$arg
7101dc407927Smrg	  prev=
7102dc407927Smrg	  continue
7103dc407927Smrg	  ;;
7104dc407927Smrg	weak)
7105dd0822caSmrg	  func_append weak_libs " $arg"
7106dc407927Smrg	  prev=
7107dc407927Smrg	  continue
7108dc407927Smrg	  ;;
7109621f50c3Smrg	xassembler)
7110621f50c3Smrg	  func_append compiler_flags " -Xassembler $qarg"
7111621f50c3Smrg	  prev=
7112621f50c3Smrg	  func_append compile_command " -Xassembler $qarg"
7113621f50c3Smrg	  func_append finalize_command " -Xassembler $qarg"
7114621f50c3Smrg	  continue
7115621f50c3Smrg	  ;;
7116dc407927Smrg	xcclinker)
7117dd0822caSmrg	  func_append linker_flags " $qarg"
7118dd0822caSmrg	  func_append compiler_flags " $qarg"
7119dc407927Smrg	  prev=
7120dc407927Smrg	  func_append compile_command " $qarg"
7121dc407927Smrg	  func_append finalize_command " $qarg"
7122dc407927Smrg	  continue
7123dc407927Smrg	  ;;
7124dc407927Smrg	xcompiler)
7125dd0822caSmrg	  func_append compiler_flags " $qarg"
7126dc407927Smrg	  prev=
7127dc407927Smrg	  func_append compile_command " $qarg"
7128dc407927Smrg	  func_append finalize_command " $qarg"
7129dc407927Smrg	  continue
7130dc407927Smrg	  ;;
7131dc407927Smrg	xlinker)
7132dd0822caSmrg	  func_append linker_flags " $qarg"
7133dd0822caSmrg	  func_append compiler_flags " $wl$qarg"
7134dc407927Smrg	  prev=
7135dc407927Smrg	  func_append compile_command " $wl$qarg"
7136dc407927Smrg	  func_append finalize_command " $wl$qarg"
7137dc407927Smrg	  continue
7138dc407927Smrg	  ;;
7139dc407927Smrg	*)
7140dc407927Smrg	  eval "$prev=\"\$arg\""
7141dc407927Smrg	  prev=
7142dc407927Smrg	  continue
7143dc407927Smrg	  ;;
71443eed67faSmbalmer	esac
7145dc407927Smrg      fi # test -n "$prev"
71463eed67faSmbalmer
71471a9c160aSmrg      prevarg=$arg
71483eed67faSmbalmer
7149dc407927Smrg      case $arg in
7150dc407927Smrg      -all-static)
7151dc407927Smrg	if test -n "$link_static_flag"; then
7152dc407927Smrg	  # See comment for -static flag below, for more details.
7153dc407927Smrg	  func_append compile_command " $link_static_flag"
7154dc407927Smrg	  func_append finalize_command " $link_static_flag"
7155dc407927Smrg	fi
7156dc407927Smrg	continue
7157dc407927Smrg	;;
71583eed67faSmbalmer
7159dc407927Smrg      -allow-undefined)
7160dc407927Smrg	# FIXME: remove this flag sometime in the future.
71611a9c160aSmrg	func_fatal_error "'-allow-undefined' must not be used because it is the default"
7162dc407927Smrg	;;
71633eed67faSmbalmer
7164dc407927Smrg      -avoid-version)
7165dc407927Smrg	avoid_version=yes
7166dc407927Smrg	continue
7167dc407927Smrg	;;
71683eed67faSmbalmer
7169dd0822caSmrg      -bindir)
7170dd0822caSmrg	prev=bindir
7171dd0822caSmrg	continue
7172dd0822caSmrg	;;
7173dd0822caSmrg
7174dc407927Smrg      -dlopen)
7175dc407927Smrg	prev=dlfiles
7176dc407927Smrg	continue
7177dc407927Smrg	;;
71783eed67faSmbalmer
7179dc407927Smrg      -dlpreopen)
7180dc407927Smrg	prev=dlprefiles
7181dc407927Smrg	continue
7182dc407927Smrg	;;
71833eed67faSmbalmer
7184dc407927Smrg      -export-dynamic)
7185dc407927Smrg	export_dynamic=yes
7186dc407927Smrg	continue
7187dc407927Smrg	;;
71883eed67faSmbalmer
7189dc407927Smrg      -export-symbols | -export-symbols-regex)
7190dc407927Smrg	if test -n "$export_symbols" || test -n "$export_symbols_regex"; then
7191dc407927Smrg	  func_fatal_error "more than one -exported-symbols argument is not allowed"
7192dc407927Smrg	fi
71931a9c160aSmrg	if test X-export-symbols = "X$arg"; then
7194dc407927Smrg	  prev=expsyms
7195dc407927Smrg	else
7196dc407927Smrg	  prev=expsyms_regex
7197dc407927Smrg	fi
7198dc407927Smrg	continue
7199dc407927Smrg	;;
72003eed67faSmbalmer
7201dc407927Smrg      -framework)
7202dc407927Smrg	prev=framework
7203dc407927Smrg	continue
7204dc407927Smrg	;;
72053eed67faSmbalmer
7206dc407927Smrg      -inst-prefix-dir)
7207dc407927Smrg	prev=inst_prefix
7208dc407927Smrg	continue
7209dc407927Smrg	;;
72103eed67faSmbalmer
7211dc407927Smrg      # The native IRIX linker understands -LANG:*, -LIST:* and -LNO:*
7212dc407927Smrg      # so, if we see these flags be careful not to treat them like -L
7213dc407927Smrg      -L[A-Z][A-Z]*:*)
7214dc407927Smrg	case $with_gcc/$host in
7215dc407927Smrg	no/*-*-irix* | /*-*-irix*)
7216dc407927Smrg	  func_append compile_command " $arg"
7217dc407927Smrg	  func_append finalize_command " $arg"
7218dc407927Smrg	  ;;
7219dc407927Smrg	esac
7220dc407927Smrg	continue
7221dc407927Smrg	;;
72223eed67faSmbalmer
7223dc407927Smrg      -L*)
7224dd0822caSmrg	func_stripname "-L" '' "$arg"
7225dd0822caSmrg	if test -z "$func_stripname_result"; then
7226dc407927Smrg	  if test "$#" -gt 0; then
72271a9c160aSmrg	    func_fatal_error "require no space between '-L' and '$1'"
7228dc407927Smrg	  else
72291a9c160aSmrg	    func_fatal_error "need path for '-L' option"
7230dc407927Smrg	  fi
7231dc407927Smrg	fi
7232dd0822caSmrg	func_resolve_sysroot "$func_stripname_result"
7233dd0822caSmrg	dir=$func_resolve_sysroot_result
7234dc407927Smrg	# We need an absolute path.
7235dc407927Smrg	case $dir in
7236dc407927Smrg	[\\/]* | [A-Za-z]:[\\/]*) ;;
7237dc407927Smrg	*)
7238dc407927Smrg	  absdir=`cd "$dir" && pwd`
7239dc407927Smrg	  test -z "$absdir" && \
72401a9c160aSmrg	    func_fatal_error "cannot determine absolute directory name of '$dir'"
72411a9c160aSmrg	  dir=$absdir
7242dc407927Smrg	  ;;
7243dc407927Smrg	esac
7244dc407927Smrg	case "$deplibs " in
7245dd0822caSmrg	*" -L$dir "* | *" $arg "*)
7246dd0822caSmrg	  # Will only happen for absolute or sysroot arguments
7247dd0822caSmrg	  ;;
7248dc407927Smrg	*)
7249dd0822caSmrg	  # Preserve sysroot, but never include relative directories
7250dd0822caSmrg	  case $dir in
7251dd0822caSmrg	    [\\/]* | [A-Za-z]:[\\/]* | =*) func_append deplibs " $arg" ;;
7252dd0822caSmrg	    *) func_append deplibs " -L$dir" ;;
7253dd0822caSmrg	  esac
7254dd0822caSmrg	  func_append lib_search_path " $dir"
7255dc407927Smrg	  ;;
7256dc407927Smrg	esac
7257dc407927Smrg	case $host in
7258dc407927Smrg	*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
7259dd0822caSmrg	  testbindir=`$ECHO "$dir" | $SED 's*/lib$*/bin*'`
7260dc407927Smrg	  case :$dllsearchpath: in
7261dc407927Smrg	  *":$dir:"*) ;;
7262dc407927Smrg	  ::) dllsearchpath=$dir;;
7263dd0822caSmrg	  *) func_append dllsearchpath ":$dir";;
7264dc407927Smrg	  esac
7265dc407927Smrg	  case :$dllsearchpath: in
7266dc407927Smrg	  *":$testbindir:"*) ;;
7267dc407927Smrg	  ::) dllsearchpath=$testbindir;;
7268dd0822caSmrg	  *) func_append dllsearchpath ":$testbindir";;
7269dc407927Smrg	  esac
7270dc407927Smrg	  ;;
7271dc407927Smrg	esac
7272dc407927Smrg	continue
7273dc407927Smrg	;;
72743eed67faSmbalmer
7275dc407927Smrg      -l*)
72761a9c160aSmrg	if test X-lc = "X$arg" || test X-lm = "X$arg"; then
7277dc407927Smrg	  case $host in
7278dd0822caSmrg	  *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-beos* | *-cegcc* | *-*-haiku*)
7279dc407927Smrg	    # These systems don't actually have a C or math library (as such)
7280dc407927Smrg	    continue
7281dc407927Smrg	    ;;
7282dc407927Smrg	  *-*-os2*)
7283dc407927Smrg	    # These systems don't actually have a C library (as such)
72841a9c160aSmrg	    test X-lc = "X$arg" && continue
7285dc407927Smrg	    ;;
7286621f50c3Smrg	  *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-bitrig* | *-*-midnightbsd*)
7287dc407927Smrg	    # Do not include libc due to us having libc/libc_r.
72881a9c160aSmrg	    test X-lc = "X$arg" && continue
7289dc407927Smrg	    ;;
7290dc407927Smrg	  *-*-rhapsody* | *-*-darwin1.[012])
7291dc407927Smrg	    # Rhapsody C and math libraries are in the System framework
7292dd0822caSmrg	    func_append deplibs " System.ltframework"
7293dc407927Smrg	    continue
7294dc407927Smrg	    ;;
7295dc407927Smrg	  *-*-sco3.2v5* | *-*-sco5v6*)
7296dc407927Smrg	    # Causes problems with __ctype
72971a9c160aSmrg	    test X-lc = "X$arg" && continue
7298dc407927Smrg	    ;;
7299dc407927Smrg	  *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*)
7300dc407927Smrg	    # Compiler inserts libc in the correct place for threads to work
73011a9c160aSmrg	    test X-lc = "X$arg" && continue
7302dc407927Smrg	    ;;
7303dc407927Smrg	  esac
73041a9c160aSmrg	elif test X-lc_r = "X$arg"; then
7305dc407927Smrg	 case $host in
7306621f50c3Smrg	 *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-bitrig* | *-*-midnightbsd*)
7307dc407927Smrg	   # Do not include libc_r directly, use -pthread flag.
7308dc407927Smrg	   continue
7309dc407927Smrg	   ;;
7310dc407927Smrg	 esac
7311dc407927Smrg	fi
7312dd0822caSmrg	func_append deplibs " $arg"
7313dc407927Smrg	continue
7314dc407927Smrg	;;
73153eed67faSmbalmer
73161a9c160aSmrg      -mllvm)
73171a9c160aSmrg	prev=mllvm
73181a9c160aSmrg	continue
73191a9c160aSmrg	;;
73201a9c160aSmrg
7321dc407927Smrg      -module)
7322dc407927Smrg	module=yes
7323dc407927Smrg	continue
7324dc407927Smrg	;;
73253eed67faSmbalmer
7326dc407927Smrg      # Tru64 UNIX uses -model [arg] to determine the layout of C++
7327dc407927Smrg      # classes, name mangling, and exception handling.
7328dc407927Smrg      # Darwin uses the -arch flag to determine output architecture.
7329dd0822caSmrg      -model|-arch|-isysroot|--sysroot)
7330dd0822caSmrg	func_append compiler_flags " $arg"
7331dc407927Smrg	func_append compile_command " $arg"
7332dc407927Smrg	func_append finalize_command " $arg"
7333dc407927Smrg	prev=xcompiler
7334dc407927Smrg	continue
7335dc407927Smrg	;;
7336621f50c3Smrg     # Solaris ld rejects as of 11.4. Refer to Oracle bug 22985199.
7337621f50c3Smrg     -pthread)
7338621f50c3Smrg	case $host in
7339621f50c3Smrg	  *solaris2*) ;;
7340621f50c3Smrg	  *)
7341621f50c3Smrg	    case "$new_inherited_linker_flags " in
7342621f50c3Smrg	        *" $arg "*) ;;
7343621f50c3Smrg	        * ) func_append new_inherited_linker_flags " $arg" ;;
7344621f50c3Smrg	    esac
7345621f50c3Smrg	  ;;
7346621f50c3Smrg	esac
7347621f50c3Smrg	continue
7348621f50c3Smrg	;;
7349621f50c3Smrg      -mt|-mthreads|-kthread|-Kthread|-pthreads|--thread-safe \
735075cbef56Smrg      |-threads|-fopenmp|-openmp|-mp|-xopenmp|-omp|-qsmp=*)
7351dd0822caSmrg	func_append compiler_flags " $arg"
7352dc407927Smrg	func_append compile_command " $arg"
7353dc407927Smrg	func_append finalize_command " $arg"
7354dc407927Smrg	case "$new_inherited_linker_flags " in
7355dc407927Smrg	    *" $arg "*) ;;
7356dd0822caSmrg	    * ) func_append new_inherited_linker_flags " $arg" ;;
7357dc407927Smrg	esac
7358dc407927Smrg	continue
7359dc407927Smrg	;;
73603eed67faSmbalmer
7361dc407927Smrg      -multi_module)
73621a9c160aSmrg	single_module=$wl-multi_module
7363dc407927Smrg	continue
7364dc407927Smrg	;;
73653eed67faSmbalmer
7366dc407927Smrg      -no-fast-install)
7367dc407927Smrg	fast_install=no
7368dc407927Smrg	continue
7369dc407927Smrg	;;
73703eed67faSmbalmer
7371dc407927Smrg      -no-install)
7372dc407927Smrg	case $host in
7373dc407927Smrg	*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-darwin* | *-cegcc*)
7374dc407927Smrg	  # The PATH hackery in wrapper scripts is required on Windows
7375dc407927Smrg	  # and Darwin in order for the loader to find any dlls it needs.
73761a9c160aSmrg	  func_warning "'-no-install' is ignored for $host"
73771a9c160aSmrg	  func_warning "assuming '-no-fast-install' instead"
7378dc407927Smrg	  fast_install=no
7379dc407927Smrg	  ;;
7380dc407927Smrg	*) no_install=yes ;;
7381dc407927Smrg	esac
7382dc407927Smrg	continue
7383dc407927Smrg	;;
73843eed67faSmbalmer
7385dc407927Smrg      -no-undefined)
7386dc407927Smrg	allow_undefined=no
7387dc407927Smrg	continue
7388dc407927Smrg	;;
73893eed67faSmbalmer
7390dc407927Smrg      -objectlist)
7391dc407927Smrg	prev=objectlist
7392dc407927Smrg	continue
7393dc407927Smrg	;;
73943eed67faSmbalmer
73951a9c160aSmrg      -os2dllname)
73961a9c160aSmrg	prev=os2dllname
73971a9c160aSmrg	continue
73981a9c160aSmrg	;;
73991a9c160aSmrg
7400dc407927Smrg      -o) prev=output ;;
74013eed67faSmbalmer
7402dc407927Smrg      -precious-files-regex)
7403dc407927Smrg	prev=precious_regex
7404dc407927Smrg	continue
7405dc407927Smrg	;;
74063eed67faSmbalmer
7407dc407927Smrg      -release)
7408dc407927Smrg	prev=release
7409dc407927Smrg	continue
7410dc407927Smrg	;;
74113eed67faSmbalmer
7412dc407927Smrg      -rpath)
7413dc407927Smrg	prev=rpath
7414dc407927Smrg	continue
7415dc407927Smrg	;;
74163eed67faSmbalmer
7417dc407927Smrg      -R)
7418dc407927Smrg	prev=xrpath
7419dc407927Smrg	continue
7420dc407927Smrg	;;
74213eed67faSmbalmer
7422dc407927Smrg      -R*)
7423dc407927Smrg	func_stripname '-R' '' "$arg"
7424dc407927Smrg	dir=$func_stripname_result
7425dc407927Smrg	# We need an absolute path.
7426dc407927Smrg	case $dir in
7427dc407927Smrg	[\\/]* | [A-Za-z]:[\\/]*) ;;
7428dd0822caSmrg	=*)
7429dd0822caSmrg	  func_stripname '=' '' "$dir"
7430dd0822caSmrg	  dir=$lt_sysroot$func_stripname_result
7431dd0822caSmrg	  ;;
7432dc407927Smrg	*)
7433dc407927Smrg	  func_fatal_error "only absolute run-paths are allowed"
7434dc407927Smrg	  ;;
7435dc407927Smrg	esac
7436dc407927Smrg	case "$xrpath " in
7437dc407927Smrg	*" $dir "*) ;;
7438dd0822caSmrg	*) func_append xrpath " $dir" ;;
7439dc407927Smrg	esac
7440dc407927Smrg	continue
7441dc407927Smrg	;;
74423eed67faSmbalmer
7443dc407927Smrg      -shared)
7444dc407927Smrg	# The effects of -shared are defined in a previous loop.
7445dc407927Smrg	continue
7446dc407927Smrg	;;
74473eed67faSmbalmer
7448dc407927Smrg      -shrext)
7449dc407927Smrg	prev=shrext
7450dc407927Smrg	continue
7451dc407927Smrg	;;
74523eed67faSmbalmer
7453dc407927Smrg      -static | -static-libtool-libs)
7454dc407927Smrg	# The effects of -static are defined in a previous loop.
7455dc407927Smrg	# We used to do the same as -all-static on platforms that
7456dc407927Smrg	# didn't have a PIC flag, but the assumption that the effects
7457dc407927Smrg	# would be equivalent was wrong.  It would break on at least
7458dc407927Smrg	# Digital Unix and AIX.
7459dc407927Smrg	continue
7460dc407927Smrg	;;
74613eed67faSmbalmer
7462dc407927Smrg      -thread-safe)
7463dc407927Smrg	thread_safe=yes
7464dc407927Smrg	continue
7465dc407927Smrg	;;
74663eed67faSmbalmer
7467dc407927Smrg      -version-info)
7468dc407927Smrg	prev=vinfo
7469dc407927Smrg	continue
7470dc407927Smrg	;;
74713eed67faSmbalmer
7472dc407927Smrg      -version-number)
7473dc407927Smrg	prev=vinfo
7474dc407927Smrg	vinfo_number=yes
7475dc407927Smrg	continue
7476dc407927Smrg	;;
74773eed67faSmbalmer
7478dc407927Smrg      -weak)
7479dc407927Smrg        prev=weak
7480dc407927Smrg	continue
7481dc407927Smrg	;;
74823eed67faSmbalmer
7483dc407927Smrg      -Wc,*)
7484dc407927Smrg	func_stripname '-Wc,' '' "$arg"
7485dc407927Smrg	args=$func_stripname_result
7486dc407927Smrg	arg=
74871a9c160aSmrg	save_ifs=$IFS; IFS=,
7488dc407927Smrg	for flag in $args; do
74891a9c160aSmrg	  IFS=$save_ifs
7490621f50c3Smrg          func_quote_arg pretty "$flag"
7491621f50c3Smrg	  func_append arg " $func_quote_arg_result"
7492621f50c3Smrg	  func_append compiler_flags " $func_quote_arg_result"
7493dc407927Smrg	done
74941a9c160aSmrg	IFS=$save_ifs
7495dc407927Smrg	func_stripname ' ' '' "$arg"
7496dc407927Smrg	arg=$func_stripname_result
7497dc407927Smrg	;;
74983eed67faSmbalmer
7499dc407927Smrg      -Wl,*)
7500dc407927Smrg	func_stripname '-Wl,' '' "$arg"
7501dc407927Smrg	args=$func_stripname_result
7502dc407927Smrg	arg=
75031a9c160aSmrg	save_ifs=$IFS; IFS=,
7504dc407927Smrg	for flag in $args; do
75051a9c160aSmrg	  IFS=$save_ifs
7506621f50c3Smrg          func_quote_arg pretty "$flag"
7507621f50c3Smrg	  func_append arg " $wl$func_quote_arg_result"
7508621f50c3Smrg	  func_append compiler_flags " $wl$func_quote_arg_result"
7509621f50c3Smrg	  func_append linker_flags " $func_quote_arg_result"
7510dc407927Smrg	done
75111a9c160aSmrg	IFS=$save_ifs
7512dc407927Smrg	func_stripname ' ' '' "$arg"
7513dc407927Smrg	arg=$func_stripname_result
7514dc407927Smrg	;;
75153eed67faSmbalmer
7516621f50c3Smrg      -Xassembler)
7517621f50c3Smrg        prev=xassembler
7518621f50c3Smrg        continue
7519621f50c3Smrg        ;;
7520621f50c3Smrg
7521dc407927Smrg      -Xcompiler)
7522dc407927Smrg	prev=xcompiler
7523dc407927Smrg	continue
7524dc407927Smrg	;;
75253eed67faSmbalmer
7526dc407927Smrg      -Xlinker)
7527dc407927Smrg	prev=xlinker
7528dc407927Smrg	continue
7529dc407927Smrg	;;
75303eed67faSmbalmer
7531dc407927Smrg      -XCClinker)
7532dc407927Smrg	prev=xcclinker
7533dc407927Smrg	continue
7534dc407927Smrg	;;
75353eed67faSmbalmer
7536dc407927Smrg      # -msg_* for osf cc
7537dc407927Smrg      -msg_*)
7538621f50c3Smrg	func_quote_arg pretty "$arg"
7539621f50c3Smrg	arg=$func_quote_arg_result
7540dc407927Smrg	;;
75413eed67faSmbalmer
7542dd0822caSmrg      # Flags to be passed through unchanged, with rationale:
7543dd0822caSmrg      # -64, -mips[0-9]      enable 64-bit mode for the SGI compiler
7544dd0822caSmrg      # -r[0-9][0-9]*        specify processor for the SGI compiler
7545dd0822caSmrg      # -xarch=*, -xtarget=* enable 64-bit mode for the Sun compiler
7546dd0822caSmrg      # +DA*, +DD*           enable 64-bit mode for the HP compiler
7547dd0822caSmrg      # -q*                  compiler args for the IBM compiler
7548dd0822caSmrg      # -m*, -t[45]*, -txscale* architecture-specific flags for GCC
7549dd0822caSmrg      # -F/path              path to uninstalled frameworks, gcc on darwin
7550dd0822caSmrg      # -p, -pg, --coverage, -fprofile-*  profiling flags for GCC
75511a9c160aSmrg      # -fstack-protector*   stack protector flags for GCC
7552dd0822caSmrg      # @file                GCC response files
7553dd0822caSmrg      # -tp=*                Portland pgcc target processor selection
7554dd0822caSmrg      # --sysroot=*          for sysroot support
75551a9c160aSmrg      # -O*, -g*, -flto*, -fwhopr*, -fuse-linker-plugin GCC link-time optimization
75561a9c160aSmrg      # -specs=*             GCC specs files
75571a9c160aSmrg      # -stdlib=*            select c++ std lib with clang
75581a9c160aSmrg      # -fsanitize=*         Clang/GCC memory and address sanitizer
75591a9c160aSmrg      # -fuse-ld=*           Linker select flags for GCC
7560621f50c3Smrg      # -Wa,*                Pass flags directly to the assembler
7561dc407927Smrg      -64|-mips[0-9]|-r[0-9][0-9]*|-xarch=*|-xtarget=*|+DA*|+DD*|-q*|-m*| \
7562dd0822caSmrg      -t[45]*|-txscale*|-p|-pg|--coverage|-fprofile-*|-F*|@*|-tp=*|--sysroot=*| \
75631a9c160aSmrg      -O*|-g*|-flto*|-fwhopr*|-fuse-linker-plugin|-fstack-protector*|-stdlib=*| \
7564621f50c3Smrg      -specs=*|-fsanitize=*|-fuse-ld=*|-Wa,*)
7565621f50c3Smrg        func_quote_arg pretty "$arg"
7566621f50c3Smrg	arg=$func_quote_arg_result
7567dc407927Smrg        func_append compile_command " $arg"
7568dc407927Smrg        func_append finalize_command " $arg"
7569dd0822caSmrg        func_append compiler_flags " $arg"
7570dc407927Smrg        continue
7571dc407927Smrg        ;;
75723eed67faSmbalmer
75731a9c160aSmrg      -Z*)
75741a9c160aSmrg        if test os2 = "`expr $host : '.*\(os2\)'`"; then
75751a9c160aSmrg          # OS/2 uses -Zxxx to specify OS/2-specific options
75761a9c160aSmrg	  compiler_flags="$compiler_flags $arg"
75771a9c160aSmrg	  func_append compile_command " $arg"
75781a9c160aSmrg	  func_append finalize_command " $arg"
75791a9c160aSmrg	  case $arg in
75801a9c160aSmrg	  -Zlinker | -Zstack)
75811a9c160aSmrg	    prev=xcompiler
75821a9c160aSmrg	    ;;
75831a9c160aSmrg	  esac
75841a9c160aSmrg	  continue
75851a9c160aSmrg        else
75861a9c160aSmrg	  # Otherwise treat like 'Some other compiler flag' below
7587621f50c3Smrg	  func_quote_arg pretty "$arg"
7588621f50c3Smrg	  arg=$func_quote_arg_result
75891a9c160aSmrg        fi
75901a9c160aSmrg	;;
75911a9c160aSmrg
7592dc407927Smrg      # Some other compiler flag.
7593dc407927Smrg      -* | +*)
7594621f50c3Smrg        func_quote_arg pretty "$arg"
7595621f50c3Smrg	arg=$func_quote_arg_result
7596dc407927Smrg	;;
75973eed67faSmbalmer
7598dc407927Smrg      *.$objext)
7599dc407927Smrg	# A standard object.
7600dd0822caSmrg	func_append objs " $arg"
7601dc407927Smrg	;;
76023eed67faSmbalmer
7603dc407927Smrg      *.lo)
7604dc407927Smrg	# A libtool-controlled object.
76053eed67faSmbalmer
7606dc407927Smrg	# Check to see that this really is a libtool object.
7607dc407927Smrg	if func_lalib_unsafe_p "$arg"; then
7608dc407927Smrg	  pic_object=
7609dc407927Smrg	  non_pic_object=
76103eed67faSmbalmer
7611dc407927Smrg	  # Read the .lo file
7612dc407927Smrg	  func_source "$arg"
76133eed67faSmbalmer
7614dc407927Smrg	  if test -z "$pic_object" ||
7615dc407927Smrg	     test -z "$non_pic_object" ||
76161a9c160aSmrg	     test none = "$pic_object" &&
76171a9c160aSmrg	     test none = "$non_pic_object"; then
76181a9c160aSmrg	    func_fatal_error "cannot find name of object for '$arg'"
7619dc407927Smrg	  fi
76203eed67faSmbalmer
7621dc407927Smrg	  # Extract subdirectory from the argument.
7622dc407927Smrg	  func_dirname "$arg" "/" ""
76231a9c160aSmrg	  xdir=$func_dirname_result
76243eed67faSmbalmer
76251a9c160aSmrg	  test none = "$pic_object" || {
7626dc407927Smrg	    # Prepend the subdirectory the object is found in.
76271a9c160aSmrg	    pic_object=$xdir$pic_object
76283eed67faSmbalmer
76291a9c160aSmrg	    if test dlfiles = "$prev"; then
76301a9c160aSmrg	      if test yes = "$build_libtool_libs" && test yes = "$dlopen_support"; then
7631dd0822caSmrg		func_append dlfiles " $pic_object"
7632dc407927Smrg		prev=
7633dc407927Smrg		continue
7634dc407927Smrg	      else
7635dc407927Smrg		# If libtool objects are unsupported, then we need to preload.
7636dc407927Smrg		prev=dlprefiles
7637dc407927Smrg	      fi
7638dc407927Smrg	    fi
76393eed67faSmbalmer
7640dc407927Smrg	    # CHECK ME:  I think I busted this.  -Ossama
76411a9c160aSmrg	    if test dlprefiles = "$prev"; then
7642dc407927Smrg	      # Preload the old-style object.
7643dd0822caSmrg	      func_append dlprefiles " $pic_object"
7644dc407927Smrg	      prev=
7645dc407927Smrg	    fi
76463eed67faSmbalmer
7647dc407927Smrg	    # A PIC object.
7648dc407927Smrg	    func_append libobjs " $pic_object"
76491a9c160aSmrg	    arg=$pic_object
76501a9c160aSmrg	  }
76513eed67faSmbalmer
7652dc407927Smrg	  # Non-PIC object.
76531a9c160aSmrg	  if test none != "$non_pic_object"; then
7654dc407927Smrg	    # Prepend the subdirectory the object is found in.
76551a9c160aSmrg	    non_pic_object=$xdir$non_pic_object
76563eed67faSmbalmer
7657dc407927Smrg	    # A standard non-PIC object
7658dc407927Smrg	    func_append non_pic_objects " $non_pic_object"
76591a9c160aSmrg	    if test -z "$pic_object" || test none = "$pic_object"; then
76601a9c160aSmrg	      arg=$non_pic_object
7661dc407927Smrg	    fi
7662dc407927Smrg	  else
7663dc407927Smrg	    # If the PIC object exists, use it instead.
7664dc407927Smrg	    # $xdir was prepended to $pic_object above.
76651a9c160aSmrg	    non_pic_object=$pic_object
7666dc407927Smrg	    func_append non_pic_objects " $non_pic_object"
7667dc407927Smrg	  fi
7668dc407927Smrg	else
7669dc407927Smrg	  # Only an error if not doing a dry-run.
7670dc407927Smrg	  if $opt_dry_run; then
7671dc407927Smrg	    # Extract subdirectory from the argument.
7672dc407927Smrg	    func_dirname "$arg" "/" ""
76731a9c160aSmrg	    xdir=$func_dirname_result
7674dc407927Smrg
7675dc407927Smrg	    func_lo2o "$arg"
7676dc407927Smrg	    pic_object=$xdir$objdir/$func_lo2o_result
7677dc407927Smrg	    non_pic_object=$xdir$func_lo2o_result
7678dc407927Smrg	    func_append libobjs " $pic_object"
7679dc407927Smrg	    func_append non_pic_objects " $non_pic_object"
7680dc407927Smrg	  else
76811a9c160aSmrg	    func_fatal_error "'$arg' is not a valid libtool object"
7682dc407927Smrg	  fi
7683dc407927Smrg	fi
7684dc407927Smrg	;;
7685dc407927Smrg
7686dc407927Smrg      *.$libext)
7687dc407927Smrg	# An archive.
7688dd0822caSmrg	func_append deplibs " $arg"
7689dd0822caSmrg	func_append old_deplibs " $arg"
7690dc407927Smrg	continue
7691dc407927Smrg	;;
7692dc407927Smrg
7693dc407927Smrg      *.la)
7694dc407927Smrg	# A libtool-controlled library.
7695dc407927Smrg
7696dd0822caSmrg	func_resolve_sysroot "$arg"
76971a9c160aSmrg	if test dlfiles = "$prev"; then
7698dc407927Smrg	  # This library was specified with -dlopen.
7699dd0822caSmrg	  func_append dlfiles " $func_resolve_sysroot_result"
7700dc407927Smrg	  prev=
77011a9c160aSmrg	elif test dlprefiles = "$prev"; then
7702dc407927Smrg	  # The library was specified with -dlpreopen.
7703dd0822caSmrg	  func_append dlprefiles " $func_resolve_sysroot_result"
7704dc407927Smrg	  prev=
7705dc407927Smrg	else
7706dd0822caSmrg	  func_append deplibs " $func_resolve_sysroot_result"
7707dc407927Smrg	fi
7708dc407927Smrg	continue
7709dc407927Smrg	;;
7710dc407927Smrg
7711dc407927Smrg      # Some other compiler argument.
7712dc407927Smrg      *)
7713dc407927Smrg	# Unknown arguments in both finalize_command and compile_command need
7714dc407927Smrg	# to be aesthetically quoted because they are evaled later.
7715621f50c3Smrg	func_quote_arg pretty "$arg"
7716621f50c3Smrg	arg=$func_quote_arg_result
7717dc407927Smrg	;;
7718dc407927Smrg      esac # arg
7719dc407927Smrg
7720dc407927Smrg      # Now actually substitute the argument into the commands.
7721dc407927Smrg      if test -n "$arg"; then
7722dc407927Smrg	func_append compile_command " $arg"
7723dc407927Smrg	func_append finalize_command " $arg"
7724dc407927Smrg      fi
7725dc407927Smrg    done # argument parsing loop
7726dc407927Smrg
7727dc407927Smrg    test -n "$prev" && \
77281a9c160aSmrg      func_fatal_help "the '$prevarg' option requires an argument"
7729dc407927Smrg
77301a9c160aSmrg    if test yes = "$export_dynamic" && test -n "$export_dynamic_flag_spec"; then
7731dc407927Smrg      eval arg=\"$export_dynamic_flag_spec\"
7732dc407927Smrg      func_append compile_command " $arg"
7733dc407927Smrg      func_append finalize_command " $arg"
7734dc407927Smrg    fi
7735dc407927Smrg
7736dc407927Smrg    oldlibs=
7737dc407927Smrg    # calculate the name of the file, without its directory
7738dc407927Smrg    func_basename "$output"
77391a9c160aSmrg    outputname=$func_basename_result
77401a9c160aSmrg    libobjs_save=$libobjs
7741dc407927Smrg
7742dc407927Smrg    if test -n "$shlibpath_var"; then
7743dc407927Smrg      # get the directories listed in $shlibpath_var
77441a9c160aSmrg      eval shlib_search_path=\`\$ECHO \"\$$shlibpath_var\" \| \$SED \'s/:/ /g\'\`
7745dc407927Smrg    else
7746dc407927Smrg      shlib_search_path=
7747dc407927Smrg    fi
7748dc407927Smrg    eval sys_lib_search_path=\"$sys_lib_search_path_spec\"
7749dc407927Smrg    eval sys_lib_dlsearch_path=\"$sys_lib_dlsearch_path_spec\"
7750dc407927Smrg
77511a9c160aSmrg    # Definition is injected by LT_CONFIG during libtool generation.
77521a9c160aSmrg    func_munge_path_list sys_lib_dlsearch_path "$LT_SYS_LIBRARY_PATH"
77531a9c160aSmrg
7754dc407927Smrg    func_dirname "$output" "/" ""
77551a9c160aSmrg    output_objdir=$func_dirname_result$objdir
7756dd0822caSmrg    func_to_tool_file "$output_objdir/"
7757dd0822caSmrg    tool_output_objdir=$func_to_tool_file_result
7758dc407927Smrg    # Create the object directory.
7759dc407927Smrg    func_mkdir_p "$output_objdir"
7760dc407927Smrg
7761dc407927Smrg    # Determine the type of output
7762dc407927Smrg    case $output in
7763dc407927Smrg    "")
7764dc407927Smrg      func_fatal_help "you must specify an output file"
7765dc407927Smrg      ;;
7766dc407927Smrg    *.$libext) linkmode=oldlib ;;
7767dc407927Smrg    *.lo | *.$objext) linkmode=obj ;;
7768dc407927Smrg    *.la) linkmode=lib ;;
7769dc407927Smrg    *) linkmode=prog ;; # Anything else should be a program.
7770dc407927Smrg    esac
7771dc407927Smrg
7772dc407927Smrg    specialdeplibs=
7773dc407927Smrg
7774dc407927Smrg    libs=
7775dc407927Smrg    # Find all interdependent deplibs by searching for libraries
7776dc407927Smrg    # that are linked more than once (e.g. -la -lb -la)
7777dc407927Smrg    for deplib in $deplibs; do
77781a9c160aSmrg      if $opt_preserve_dup_deps; then
7779dc407927Smrg	case "$libs " in
7780dd0822caSmrg	*" $deplib "*) func_append specialdeplibs " $deplib" ;;
7781dc407927Smrg	esac
7782dc407927Smrg      fi
7783dd0822caSmrg      func_append libs " $deplib"
7784dc407927Smrg    done
7785dc407927Smrg
77861a9c160aSmrg    if test lib = "$linkmode"; then
7787dc407927Smrg      libs="$predeps $libs $compiler_lib_search_path $postdeps"
7788dc407927Smrg
7789dc407927Smrg      # Compute libraries that are listed more than once in $predeps
7790dc407927Smrg      # $postdeps and mark them as special (i.e., whose duplicates are
7791dc407927Smrg      # not to be eliminated).
7792dc407927Smrg      pre_post_deps=
7793dc407927Smrg      if $opt_duplicate_compiler_generated_deps; then
7794dc407927Smrg	for pre_post_dep in $predeps $postdeps; do
7795dc407927Smrg	  case "$pre_post_deps " in
7796dd0822caSmrg	  *" $pre_post_dep "*) func_append specialdeplibs " $pre_post_deps" ;;
7797dc407927Smrg	  esac
7798dd0822caSmrg	  func_append pre_post_deps " $pre_post_dep"
7799dc407927Smrg	done
7800dc407927Smrg      fi
7801dc407927Smrg      pre_post_deps=
7802dc407927Smrg    fi
7803dc407927Smrg
7804dc407927Smrg    deplibs=
7805dc407927Smrg    newdependency_libs=
7806dc407927Smrg    newlib_search_path=
7807dc407927Smrg    need_relink=no # whether we're linking any uninstalled libtool libraries
7808dc407927Smrg    notinst_deplibs= # not-installed libtool libraries
7809dc407927Smrg    notinst_path= # paths that contain not-installed libtool libraries
7810dc407927Smrg
7811dc407927Smrg    case $linkmode in
7812dc407927Smrg    lib)
7813dc407927Smrg	passes="conv dlpreopen link"
7814dc407927Smrg	for file in $dlfiles $dlprefiles; do
7815dc407927Smrg	  case $file in
7816dc407927Smrg	  *.la) ;;
7817dc407927Smrg	  *)
78181a9c160aSmrg	    func_fatal_help "libraries can '-dlopen' only libtool libraries: $file"
7819dc407927Smrg	    ;;
7820dc407927Smrg	  esac
7821dc407927Smrg	done
7822dc407927Smrg	;;
7823dc407927Smrg    prog)
7824dc407927Smrg	compile_deplibs=
7825dc407927Smrg	finalize_deplibs=
78261a9c160aSmrg	alldeplibs=false
7827dc407927Smrg	newdlfiles=
7828dc407927Smrg	newdlprefiles=
7829dc407927Smrg	passes="conv scan dlopen dlpreopen link"
7830dc407927Smrg	;;
7831dc407927Smrg    *)  passes="conv"
7832dc407927Smrg	;;
7833dc407927Smrg    esac
7834dc407927Smrg
7835dc407927Smrg    for pass in $passes; do
7836dc407927Smrg      # The preopen pass in lib mode reverses $deplibs; put it back here
7837dc407927Smrg      # so that -L comes before libs that need it for instance...
78381a9c160aSmrg      if test lib,link = "$linkmode,$pass"; then
7839dc407927Smrg	## FIXME: Find the place where the list is rebuilt in the wrong
7840dc407927Smrg	##        order, and fix it there properly
7841dc407927Smrg        tmp_deplibs=
7842dc407927Smrg	for deplib in $deplibs; do
7843dc407927Smrg	  tmp_deplibs="$deplib $tmp_deplibs"
7844dc407927Smrg	done
78451a9c160aSmrg	deplibs=$tmp_deplibs
7846dc407927Smrg      fi
7847dc407927Smrg
78481a9c160aSmrg      if test lib,link = "$linkmode,$pass" ||
78491a9c160aSmrg	 test prog,scan = "$linkmode,$pass"; then
78501a9c160aSmrg	libs=$deplibs
7851dc407927Smrg	deplibs=
7852dc407927Smrg      fi
78531a9c160aSmrg      if test prog = "$linkmode"; then
7854dc407927Smrg	case $pass in
78551a9c160aSmrg	dlopen) libs=$dlfiles ;;
78561a9c160aSmrg	dlpreopen) libs=$dlprefiles ;;
7857dc407927Smrg	link) libs="$deplibs %DEPLIBS% $dependency_libs" ;;
7858dc407927Smrg	esac
7859dc407927Smrg      fi
78601a9c160aSmrg      if test lib,dlpreopen = "$linkmode,$pass"; then
7861dc407927Smrg	# Collect and forward deplibs of preopened libtool libs
7862dc407927Smrg	for lib in $dlprefiles; do
7863dc407927Smrg	  # Ignore non-libtool-libs
7864dc407927Smrg	  dependency_libs=
7865dd0822caSmrg	  func_resolve_sysroot "$lib"
7866dc407927Smrg	  case $lib in
7867dd0822caSmrg	  *.la)	func_source "$func_resolve_sysroot_result" ;;
7868dc407927Smrg	  esac
7869dc407927Smrg
7870dc407927Smrg	  # Collect preopened libtool deplibs, except any this library
7871dc407927Smrg	  # has declared as weak libs
7872dc407927Smrg	  for deplib in $dependency_libs; do
7873dd0822caSmrg	    func_basename "$deplib"
7874dd0822caSmrg            deplib_base=$func_basename_result
7875dc407927Smrg	    case " $weak_libs " in
7876dc407927Smrg	    *" $deplib_base "*) ;;
7877dd0822caSmrg	    *) func_append deplibs " $deplib" ;;
7878dc407927Smrg	    esac
7879dc407927Smrg	  done
7880dc407927Smrg	done
78811a9c160aSmrg	libs=$dlprefiles
7882dc407927Smrg      fi
78831a9c160aSmrg      if test dlopen = "$pass"; then
7884dc407927Smrg	# Collect dlpreopened libraries
78851a9c160aSmrg	save_deplibs=$deplibs
7886dc407927Smrg	deplibs=
7887dc407927Smrg      fi
7888dc407927Smrg
7889dc407927Smrg      for deplib in $libs; do
7890dc407927Smrg	lib=
78911a9c160aSmrg	found=false
7892dc407927Smrg	case $deplib in
789375cbef56Smrg	-mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe \
789475cbef56Smrg        |-threads|-fopenmp|-openmp|-mp|-xopenmp|-omp|-qsmp=*)
78951a9c160aSmrg	  if test prog,link = "$linkmode,$pass"; then
7896dc407927Smrg	    compile_deplibs="$deplib $compile_deplibs"
7897dc407927Smrg	    finalize_deplibs="$deplib $finalize_deplibs"
7898dc407927Smrg	  else
7899dd0822caSmrg	    func_append compiler_flags " $deplib"
79001a9c160aSmrg	    if test lib = "$linkmode"; then
7901dc407927Smrg		case "$new_inherited_linker_flags " in
7902dc407927Smrg		    *" $deplib "*) ;;
7903dd0822caSmrg		    * ) func_append new_inherited_linker_flags " $deplib" ;;
7904dc407927Smrg		esac
7905dc407927Smrg	    fi
7906dc407927Smrg	  fi
7907dc407927Smrg	  continue
7908dc407927Smrg	  ;;
7909dc407927Smrg	-l*)
79101a9c160aSmrg	  if test lib != "$linkmode" && test prog != "$linkmode"; then
79111a9c160aSmrg	    func_warning "'-l' is ignored for archives/objects"
7912dc407927Smrg	    continue
7913dc407927Smrg	  fi
7914dc407927Smrg	  func_stripname '-l' '' "$deplib"
7915dc407927Smrg	  name=$func_stripname_result
79161a9c160aSmrg	  if test lib = "$linkmode"; then
7917dc407927Smrg	    searchdirs="$newlib_search_path $lib_search_path $compiler_lib_search_dirs $sys_lib_search_path $shlib_search_path"
7918dc407927Smrg	  else
7919dc407927Smrg	    searchdirs="$newlib_search_path $lib_search_path $sys_lib_search_path $shlib_search_path"
7920dc407927Smrg	  fi
7921dc407927Smrg	  for searchdir in $searchdirs; do
7922dc407927Smrg	    for search_ext in .la $std_shrext .so .a; do
7923dc407927Smrg	      # Search the libtool library
79241a9c160aSmrg	      lib=$searchdir/lib$name$search_ext
7925dc407927Smrg	      if test -f "$lib"; then
79261a9c160aSmrg		if test .la = "$search_ext"; then
79271a9c160aSmrg		  found=:
7928dc407927Smrg		else
79291a9c160aSmrg		  found=false
7930dc407927Smrg		fi
7931dc407927Smrg		break 2
7932dc407927Smrg	      fi
7933dc407927Smrg	    done
7934dc407927Smrg	  done
79351a9c160aSmrg	  if $found; then
79361a9c160aSmrg	    # deplib is a libtool library
7937dc407927Smrg	    # If $allow_libtool_libs_with_static_runtimes && $deplib is a stdlib,
7938dc407927Smrg	    # We need to do some special things here, and not later.
79391a9c160aSmrg	    if test yes = "$allow_libtool_libs_with_static_runtimes"; then
7940dc407927Smrg	      case " $predeps $postdeps " in
7941dc407927Smrg	      *" $deplib "*)
7942dc407927Smrg		if func_lalib_p "$lib"; then
7943dc407927Smrg		  library_names=
7944dc407927Smrg		  old_library=
7945dc407927Smrg		  func_source "$lib"
7946dc407927Smrg		  for l in $old_library $library_names; do
79471a9c160aSmrg		    ll=$l
7948dc407927Smrg		  done
79491a9c160aSmrg		  if test "X$ll" = "X$old_library"; then # only static version available
79501a9c160aSmrg		    found=false
7951dc407927Smrg		    func_dirname "$lib" "" "."
79521a9c160aSmrg		    ladir=$func_dirname_result
7953dc407927Smrg		    lib=$ladir/$old_library
79541a9c160aSmrg		    if test prog,link = "$linkmode,$pass"; then
7955dc407927Smrg		      compile_deplibs="$deplib $compile_deplibs"
7956dc407927Smrg		      finalize_deplibs="$deplib $finalize_deplibs"
7957dc407927Smrg		    else
7958dc407927Smrg		      deplibs="$deplib $deplibs"
79591a9c160aSmrg		      test lib = "$linkmode" && newdependency_libs="$deplib $newdependency_libs"
7960dc407927Smrg		    fi
7961dc407927Smrg		    continue
7962dc407927Smrg		  fi
7963dc407927Smrg		fi
7964dc407927Smrg		;;
7965dc407927Smrg	      *) ;;
7966dc407927Smrg	      esac
7967dc407927Smrg	    fi
79681a9c160aSmrg	  else
79691a9c160aSmrg	    # deplib doesn't seem to be a libtool library
79701a9c160aSmrg	    if test prog,link = "$linkmode,$pass"; then
79711a9c160aSmrg	      compile_deplibs="$deplib $compile_deplibs"
79721a9c160aSmrg	      finalize_deplibs="$deplib $finalize_deplibs"
79731a9c160aSmrg	    else
79741a9c160aSmrg	      deplibs="$deplib $deplibs"
79751a9c160aSmrg	      test lib = "$linkmode" && newdependency_libs="$deplib $newdependency_libs"
79761a9c160aSmrg	    fi
79771a9c160aSmrg	    continue
7978dc407927Smrg	  fi
7979dc407927Smrg	  ;; # -l
7980dc407927Smrg	*.ltframework)
79811a9c160aSmrg	  if test prog,link = "$linkmode,$pass"; then
7982dc407927Smrg	    compile_deplibs="$deplib $compile_deplibs"
7983dc407927Smrg	    finalize_deplibs="$deplib $finalize_deplibs"
7984dc407927Smrg	  else
7985dc407927Smrg	    deplibs="$deplib $deplibs"
79861a9c160aSmrg	    if test lib = "$linkmode"; then
7987dc407927Smrg		case "$new_inherited_linker_flags " in
7988dc407927Smrg		    *" $deplib "*) ;;
7989dd0822caSmrg		    * ) func_append new_inherited_linker_flags " $deplib" ;;
7990dc407927Smrg		esac
7991dc407927Smrg	    fi
7992dc407927Smrg	  fi
7993dc407927Smrg	  continue
7994dc407927Smrg	  ;;
7995dc407927Smrg	-L*)
7996dc407927Smrg	  case $linkmode in
7997dc407927Smrg	  lib)
7998dc407927Smrg	    deplibs="$deplib $deplibs"
79991a9c160aSmrg	    test conv = "$pass" && continue
8000dc407927Smrg	    newdependency_libs="$deplib $newdependency_libs"
8001dc407927Smrg	    func_stripname '-L' '' "$deplib"
8002dd0822caSmrg	    func_resolve_sysroot "$func_stripname_result"
8003dd0822caSmrg	    func_append newlib_search_path " $func_resolve_sysroot_result"
8004dc407927Smrg	    ;;
8005dc407927Smrg	  prog)
80061a9c160aSmrg	    if test conv = "$pass"; then
8007dc407927Smrg	      deplibs="$deplib $deplibs"
8008dc407927Smrg	      continue
8009dc407927Smrg	    fi
80101a9c160aSmrg	    if test scan = "$pass"; then
8011dc407927Smrg	      deplibs="$deplib $deplibs"
8012dc407927Smrg	    else
8013dc407927Smrg	      compile_deplibs="$deplib $compile_deplibs"
8014dc407927Smrg	      finalize_deplibs="$deplib $finalize_deplibs"
8015dc407927Smrg	    fi
8016dc407927Smrg	    func_stripname '-L' '' "$deplib"
8017dd0822caSmrg	    func_resolve_sysroot "$func_stripname_result"
8018dd0822caSmrg	    func_append newlib_search_path " $func_resolve_sysroot_result"
8019dc407927Smrg	    ;;
8020dc407927Smrg	  *)
80211a9c160aSmrg	    func_warning "'-L' is ignored for archives/objects"
8022dc407927Smrg	    ;;
8023dc407927Smrg	  esac # linkmode
8024dc407927Smrg	  continue
8025dc407927Smrg	  ;; # -L
8026dc407927Smrg	-R*)
80271a9c160aSmrg	  if test link = "$pass"; then
8028dc407927Smrg	    func_stripname '-R' '' "$deplib"
8029dd0822caSmrg	    func_resolve_sysroot "$func_stripname_result"
8030dd0822caSmrg	    dir=$func_resolve_sysroot_result
8031dc407927Smrg	    # Make sure the xrpath contains only unique directories.
8032dc407927Smrg	    case "$xrpath " in
8033dc407927Smrg	    *" $dir "*) ;;
8034dd0822caSmrg	    *) func_append xrpath " $dir" ;;
8035dc407927Smrg	    esac
8036dc407927Smrg	  fi
8037dc407927Smrg	  deplibs="$deplib $deplibs"
8038dc407927Smrg	  continue
8039dc407927Smrg	  ;;
8040dd0822caSmrg	*.la)
8041dd0822caSmrg	  func_resolve_sysroot "$deplib"
8042dd0822caSmrg	  lib=$func_resolve_sysroot_result
8043dd0822caSmrg	  ;;
8044dc407927Smrg	*.$libext)
80451a9c160aSmrg	  if test conv = "$pass"; then
8046dc407927Smrg	    deplibs="$deplib $deplibs"
8047dc407927Smrg	    continue
8048dc407927Smrg	  fi
8049dc407927Smrg	  case $linkmode in
8050dc407927Smrg	  lib)
8051dc407927Smrg	    # Linking convenience modules into shared libraries is allowed,
8052dc407927Smrg	    # but linking other static libraries is non-portable.
8053dc407927Smrg	    case " $dlpreconveniencelibs " in
8054dc407927Smrg	    *" $deplib "*) ;;
8055dc407927Smrg	    *)
80561a9c160aSmrg	      valid_a_lib=false
8057dc407927Smrg	      case $deplibs_check_method in
8058dc407927Smrg		match_pattern*)
8059dc407927Smrg		  set dummy $deplibs_check_method; shift
8060dc407927Smrg		  match_pattern_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
8061dd0822caSmrg		  if eval "\$ECHO \"$deplib\"" 2>/dev/null | $SED 10q \
8062dc407927Smrg		    | $EGREP "$match_pattern_regex" > /dev/null; then
80631a9c160aSmrg		    valid_a_lib=:
8064dc407927Smrg		  fi
8065dc407927Smrg		;;
8066dc407927Smrg		pass_all)
80671a9c160aSmrg		  valid_a_lib=:
8068dc407927Smrg		;;
8069dc407927Smrg	      esac
80701a9c160aSmrg	      if $valid_a_lib; then
80711a9c160aSmrg		echo
80721a9c160aSmrg		$ECHO "*** Warning: Linking the shared library $output against the"
80731a9c160aSmrg		$ECHO "*** static library $deplib is not portable!"
80741a9c160aSmrg		deplibs="$deplib $deplibs"
80751a9c160aSmrg	      else
8076dd0822caSmrg		echo
8077dc407927Smrg		$ECHO "*** Warning: Trying to link with static lib archive $deplib."
8078dd0822caSmrg		echo "*** I have the capability to make that library automatically link in when"
8079dd0822caSmrg		echo "*** you link to this library.  But I can only do this if you have a"
8080dd0822caSmrg		echo "*** shared version of the library, which you do not appear to have"
8081dd0822caSmrg		echo "*** because the file extensions .$libext of this argument makes me believe"
8082dd0822caSmrg		echo "*** that it is just a static archive that I should not use here."
8083dc407927Smrg	      fi
8084dc407927Smrg	      ;;
8085dc407927Smrg	    esac
8086dc407927Smrg	    continue
8087dc407927Smrg	    ;;
8088dc407927Smrg	  prog)
80891a9c160aSmrg	    if test link != "$pass"; then
8090dc407927Smrg	      deplibs="$deplib $deplibs"
8091dc407927Smrg	    else
8092dc407927Smrg	      compile_deplibs="$deplib $compile_deplibs"
8093dc407927Smrg	      finalize_deplibs="$deplib $finalize_deplibs"
8094dc407927Smrg	    fi
8095dc407927Smrg	    continue
8096dc407927Smrg	    ;;
8097dc407927Smrg	  esac # linkmode
8098dc407927Smrg	  ;; # *.$libext
8099dc407927Smrg	*.lo | *.$objext)
81001a9c160aSmrg	  if test conv = "$pass"; then
8101dc407927Smrg	    deplibs="$deplib $deplibs"
81021a9c160aSmrg	  elif test prog = "$linkmode"; then
81031a9c160aSmrg	    if test dlpreopen = "$pass" || test yes != "$dlopen_support" || test no = "$build_libtool_libs"; then
8104dc407927Smrg	      # If there is no dlopen support or we're linking statically,
8105dc407927Smrg	      # we need to preload.
8106dd0822caSmrg	      func_append newdlprefiles " $deplib"
8107dc407927Smrg	      compile_deplibs="$deplib $compile_deplibs"
8108dc407927Smrg	      finalize_deplibs="$deplib $finalize_deplibs"
8109dc407927Smrg	    else
8110dd0822caSmrg	      func_append newdlfiles " $deplib"
8111dc407927Smrg	    fi
8112dc407927Smrg	  fi
8113dc407927Smrg	  continue
8114dc407927Smrg	  ;;
8115dc407927Smrg	%DEPLIBS%)
81161a9c160aSmrg	  alldeplibs=:
8117dc407927Smrg	  continue
8118dc407927Smrg	  ;;
8119dc407927Smrg	esac # case $deplib
8120dc407927Smrg
81211a9c160aSmrg	$found || test -f "$lib" \
81221a9c160aSmrg	  || func_fatal_error "cannot find the library '$lib' or unhandled argument '$deplib'"
8123dc407927Smrg
8124dc407927Smrg	# Check to see that this really is a libtool archive.
8125dc407927Smrg	func_lalib_unsafe_p "$lib" \
81261a9c160aSmrg	  || func_fatal_error "'$lib' is not a valid libtool archive"
8127dc407927Smrg
8128dc407927Smrg	func_dirname "$lib" "" "."
81291a9c160aSmrg	ladir=$func_dirname_result
8130dc407927Smrg
8131dc407927Smrg	dlname=
8132dc407927Smrg	dlopen=
8133dc407927Smrg	dlpreopen=
8134dc407927Smrg	libdir=
8135dc407927Smrg	library_names=
8136dc407927Smrg	old_library=
8137dc407927Smrg	inherited_linker_flags=
8138dc407927Smrg	# If the library was installed with an old release of libtool,
8139dc407927Smrg	# it will not redefine variables installed, or shouldnotlink
8140dc407927Smrg	installed=yes
8141dc407927Smrg	shouldnotlink=no
8142dc407927Smrg	avoidtemprpath=
8143dc407927Smrg
8144dc407927Smrg
8145dc407927Smrg	# Read the .la file
8146dc407927Smrg	func_source "$lib"
8147dc407927Smrg
8148dc407927Smrg	# Convert "-framework foo" to "foo.ltframework"
8149dc407927Smrg	if test -n "$inherited_linker_flags"; then
8150dd0822caSmrg	  tmp_inherited_linker_flags=`$ECHO "$inherited_linker_flags" | $SED 's/-framework \([^ $]*\)/\1.ltframework/g'`
8151dc407927Smrg	  for tmp_inherited_linker_flag in $tmp_inherited_linker_flags; do
8152dc407927Smrg	    case " $new_inherited_linker_flags " in
8153dc407927Smrg	      *" $tmp_inherited_linker_flag "*) ;;
8154dd0822caSmrg	      *) func_append new_inherited_linker_flags " $tmp_inherited_linker_flag";;
8155dc407927Smrg	    esac
8156dc407927Smrg	  done
8157dc407927Smrg	fi
8158dd0822caSmrg	dependency_libs=`$ECHO " $dependency_libs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
81591a9c160aSmrg	if test lib,link = "$linkmode,$pass" ||
81601a9c160aSmrg	   test prog,scan = "$linkmode,$pass" ||
81611a9c160aSmrg	   { test prog != "$linkmode" && test lib != "$linkmode"; }; then
8162dd0822caSmrg	  test -n "$dlopen" && func_append dlfiles " $dlopen"
8163dd0822caSmrg	  test -n "$dlpreopen" && func_append dlprefiles " $dlpreopen"
8164dc407927Smrg	fi
8165dc407927Smrg
81661a9c160aSmrg	if test conv = "$pass"; then
8167dc407927Smrg	  # Only check for convenience libraries
8168dc407927Smrg	  deplibs="$lib $deplibs"
8169dc407927Smrg	  if test -z "$libdir"; then
8170dc407927Smrg	    if test -z "$old_library"; then
81711a9c160aSmrg	      func_fatal_error "cannot find name of link library for '$lib'"
8172dc407927Smrg	    fi
8173dc407927Smrg	    # It is a libtool convenience library, so add in its objects.
8174dd0822caSmrg	    func_append convenience " $ladir/$objdir/$old_library"
8175dd0822caSmrg	    func_append old_convenience " $ladir/$objdir/$old_library"
81761a9c160aSmrg	  elif test prog != "$linkmode" && test lib != "$linkmode"; then
81771a9c160aSmrg	    func_fatal_error "'$lib' is not a convenience library"
8178dc407927Smrg	  fi
8179dc407927Smrg	  tmp_libs=
8180dc407927Smrg	  for deplib in $dependency_libs; do
8181dc407927Smrg	    deplibs="$deplib $deplibs"
81821a9c160aSmrg	    if $opt_preserve_dup_deps; then
8183dc407927Smrg	      case "$tmp_libs " in
8184dd0822caSmrg	      *" $deplib "*) func_append specialdeplibs " $deplib" ;;
8185dc407927Smrg	      esac
8186dc407927Smrg	    fi
8187dd0822caSmrg	    func_append tmp_libs " $deplib"
8188dc407927Smrg	  done
8189dc407927Smrg	  continue
8190dc407927Smrg	fi # $pass = conv
8191dc407927Smrg
8192dc407927Smrg
8193dc407927Smrg	# Get the name of the library we link against.
8194dc407927Smrg	linklib=
8195dd0822caSmrg	if test -n "$old_library" &&
81961a9c160aSmrg	   { test yes = "$prefer_static_libs" ||
81971a9c160aSmrg	     test built,no = "$prefer_static_libs,$installed"; }; then
8198dd0822caSmrg	  linklib=$old_library
8199dd0822caSmrg	else
8200dd0822caSmrg	  for l in $old_library $library_names; do
82011a9c160aSmrg	    linklib=$l
8202dd0822caSmrg	  done
8203dd0822caSmrg	fi
8204dc407927Smrg	if test -z "$linklib"; then
82051a9c160aSmrg	  func_fatal_error "cannot find name of link library for '$lib'"
8206dc407927Smrg	fi
8207dc407927Smrg
8208dc407927Smrg	# This library was specified with -dlopen.
82091a9c160aSmrg	if test dlopen = "$pass"; then
82101a9c160aSmrg	  test -z "$libdir" \
82111a9c160aSmrg	    && func_fatal_error "cannot -dlopen a convenience library: '$lib'"
8212dc407927Smrg	  if test -z "$dlname" ||
82131a9c160aSmrg	     test yes != "$dlopen_support" ||
82141a9c160aSmrg	     test no = "$build_libtool_libs"
82151a9c160aSmrg	  then
8216dc407927Smrg	    # If there is no dlname, no dlopen support or we're linking
8217dc407927Smrg	    # statically, we need to preload.  We also need to preload any
8218dc407927Smrg	    # dependent libraries so libltdl's deplib preloader doesn't
8219dc407927Smrg	    # bomb out in the load deplibs phase.
8220dd0822caSmrg	    func_append dlprefiles " $lib $dependency_libs"
8221dc407927Smrg	  else
8222dd0822caSmrg	    func_append newdlfiles " $lib"
8223dc407927Smrg	  fi
8224dc407927Smrg	  continue
8225dc407927Smrg	fi # $pass = dlopen
8226dc407927Smrg
8227dc407927Smrg	# We need an absolute path.
8228dc407927Smrg	case $ladir in
82291a9c160aSmrg	[\\/]* | [A-Za-z]:[\\/]*) abs_ladir=$ladir ;;
8230dc407927Smrg	*)
8231dc407927Smrg	  abs_ladir=`cd "$ladir" && pwd`
8232dc407927Smrg	  if test -z "$abs_ladir"; then
82331a9c160aSmrg	    func_warning "cannot determine absolute directory name of '$ladir'"
8234dc407927Smrg	    func_warning "passing it literally to the linker, although it might fail"
82351a9c160aSmrg	    abs_ladir=$ladir
8236dc407927Smrg	  fi
8237dc407927Smrg	  ;;
8238dc407927Smrg	esac
8239dc407927Smrg	func_basename "$lib"
82401a9c160aSmrg	laname=$func_basename_result
8241dc407927Smrg
8242dc407927Smrg	# Find the relevant object directory and library name.
82431a9c160aSmrg	if test yes = "$installed"; then
8244dd0822caSmrg	  if test ! -f "$lt_sysroot$libdir/$linklib" && test -f "$abs_ladir/$linklib"; then
82451a9c160aSmrg	    func_warning "library '$lib' was moved."
82461a9c160aSmrg	    dir=$ladir
82471a9c160aSmrg	    absdir=$abs_ladir
82481a9c160aSmrg	    libdir=$abs_ladir
8249dc407927Smrg	  else
82501a9c160aSmrg	    dir=$lt_sysroot$libdir
82511a9c160aSmrg	    absdir=$lt_sysroot$libdir
8252dc407927Smrg	  fi
82531a9c160aSmrg	  test yes = "$hardcode_automatic" && avoidtemprpath=yes
8254dc407927Smrg	else
8255dc407927Smrg	  if test ! -f "$ladir/$objdir/$linklib" && test -f "$abs_ladir/$linklib"; then
82561a9c160aSmrg	    dir=$ladir
82571a9c160aSmrg	    absdir=$abs_ladir
8258dc407927Smrg	    # Remove this search path later
8259dd0822caSmrg	    func_append notinst_path " $abs_ladir"
8260dc407927Smrg	  else
82611a9c160aSmrg	    dir=$ladir/$objdir
82621a9c160aSmrg	    absdir=$abs_ladir/$objdir
8263dc407927Smrg	    # Remove this search path later
8264dd0822caSmrg	    func_append notinst_path " $abs_ladir"
8265dc407927Smrg	  fi
8266dc407927Smrg	fi # $installed = yes
8267dc407927Smrg	func_stripname 'lib' '.la' "$laname"
8268dc407927Smrg	name=$func_stripname_result
8269dc407927Smrg
8270dc407927Smrg	# This library was specified with -dlpreopen.
82711a9c160aSmrg	if test dlpreopen = "$pass"; then
82721a9c160aSmrg	  if test -z "$libdir" && test prog = "$linkmode"; then
82731a9c160aSmrg	    func_fatal_error "only libraries may -dlpreopen a convenience library: '$lib'"
8274dc407927Smrg	  fi
82751a9c160aSmrg	  case $host in
8276dd0822caSmrg	    # special handling for platforms with PE-DLLs.
8277dd0822caSmrg	    *cygwin* | *mingw* | *cegcc* )
8278dd0822caSmrg	      # Linker will automatically link against shared library if both
8279dd0822caSmrg	      # static and shared are present.  Therefore, ensure we extract
8280dd0822caSmrg	      # symbols from the import library if a shared library is present
8281dd0822caSmrg	      # (otherwise, the dlopen module name will be incorrect).  We do
8282dd0822caSmrg	      # this by putting the import library name into $newdlprefiles.
8283dd0822caSmrg	      # We recover the dlopen module name by 'saving' the la file
8284dd0822caSmrg	      # name in a special purpose variable, and (later) extracting the
8285dd0822caSmrg	      # dlname from the la file.
8286dd0822caSmrg	      if test -n "$dlname"; then
8287dd0822caSmrg	        func_tr_sh "$dir/$linklib"
8288dd0822caSmrg	        eval "libfile_$func_tr_sh_result=\$abs_ladir/\$laname"
8289dd0822caSmrg	        func_append newdlprefiles " $dir/$linklib"
8290dd0822caSmrg	      else
8291dd0822caSmrg	        func_append newdlprefiles " $dir/$old_library"
8292dd0822caSmrg	        # Keep a list of preopened convenience libraries to check
8293dd0822caSmrg	        # that they are being used correctly in the link pass.
8294dd0822caSmrg	        test -z "$libdir" && \
8295dd0822caSmrg	          func_append dlpreconveniencelibs " $dir/$old_library"
8296dd0822caSmrg	      fi
8297dd0822caSmrg	    ;;
8298dd0822caSmrg	    * )
8299dd0822caSmrg	      # Prefer using a static library (so that no silly _DYNAMIC symbols
8300dd0822caSmrg	      # are required to link).
8301dd0822caSmrg	      if test -n "$old_library"; then
8302dd0822caSmrg	        func_append newdlprefiles " $dir/$old_library"
8303dd0822caSmrg	        # Keep a list of preopened convenience libraries to check
8304dd0822caSmrg	        # that they are being used correctly in the link pass.
8305dd0822caSmrg	        test -z "$libdir" && \
8306dd0822caSmrg	          func_append dlpreconveniencelibs " $dir/$old_library"
8307dd0822caSmrg	      # Otherwise, use the dlname, so that lt_dlopen finds it.
8308dd0822caSmrg	      elif test -n "$dlname"; then
8309dd0822caSmrg	        func_append newdlprefiles " $dir/$dlname"
8310dd0822caSmrg	      else
8311dd0822caSmrg	        func_append newdlprefiles " $dir/$linklib"
8312dd0822caSmrg	      fi
8313dd0822caSmrg	    ;;
8314dd0822caSmrg	  esac
8315dc407927Smrg	fi # $pass = dlpreopen
8316dc407927Smrg
8317dc407927Smrg	if test -z "$libdir"; then
8318dc407927Smrg	  # Link the convenience library
83191a9c160aSmrg	  if test lib = "$linkmode"; then
8320dc407927Smrg	    deplibs="$dir/$old_library $deplibs"
83211a9c160aSmrg	  elif test prog,link = "$linkmode,$pass"; then
8322dc407927Smrg	    compile_deplibs="$dir/$old_library $compile_deplibs"
8323dc407927Smrg	    finalize_deplibs="$dir/$old_library $finalize_deplibs"
8324dc407927Smrg	  else
8325dc407927Smrg	    deplibs="$lib $deplibs" # used for prog,scan pass
8326dc407927Smrg	  fi
8327dc407927Smrg	  continue
8328dc407927Smrg	fi
8329dc407927Smrg
8330dc407927Smrg
83311a9c160aSmrg	if test prog = "$linkmode" && test link != "$pass"; then
8332dd0822caSmrg	  func_append newlib_search_path " $ladir"
8333dc407927Smrg	  deplibs="$lib $deplibs"
8334dc407927Smrg
83351a9c160aSmrg	  linkalldeplibs=false
83361a9c160aSmrg	  if test no != "$link_all_deplibs" || test -z "$library_names" ||
83371a9c160aSmrg	     test no = "$build_libtool_libs"; then
83381a9c160aSmrg	    linkalldeplibs=:
8339dc407927Smrg	  fi
8340dc407927Smrg
8341dc407927Smrg	  tmp_libs=
8342dc407927Smrg	  for deplib in $dependency_libs; do
8343dc407927Smrg	    case $deplib in
8344dc407927Smrg	    -L*) func_stripname '-L' '' "$deplib"
8345dd0822caSmrg	         func_resolve_sysroot "$func_stripname_result"
8346dd0822caSmrg	         func_append newlib_search_path " $func_resolve_sysroot_result"
8347dc407927Smrg		 ;;
8348dc407927Smrg	    esac
8349dc407927Smrg	    # Need to link against all dependency_libs?
83501a9c160aSmrg	    if $linkalldeplibs; then
8351dc407927Smrg	      deplibs="$deplib $deplibs"
8352dc407927Smrg	    else
8353dc407927Smrg	      # Need to hardcode shared library paths
8354dc407927Smrg	      # or/and link against static libraries
8355dc407927Smrg	      newdependency_libs="$deplib $newdependency_libs"
8356dc407927Smrg	    fi
83571a9c160aSmrg	    if $opt_preserve_dup_deps; then
8358dc407927Smrg	      case "$tmp_libs " in
8359dd0822caSmrg	      *" $deplib "*) func_append specialdeplibs " $deplib" ;;
8360dc407927Smrg	      esac
8361dc407927Smrg	    fi
8362dd0822caSmrg	    func_append tmp_libs " $deplib"
8363dc407927Smrg	  done # for deplib
8364dc407927Smrg	  continue
8365dc407927Smrg	fi # $linkmode = prog...
8366dc407927Smrg
83671a9c160aSmrg	if test prog,link = "$linkmode,$pass"; then
8368dc407927Smrg	  if test -n "$library_names" &&
83691a9c160aSmrg	     { { test no = "$prefer_static_libs" ||
83701a9c160aSmrg	         test built,yes = "$prefer_static_libs,$installed"; } ||
8371dc407927Smrg	       test -z "$old_library"; }; then
8372dc407927Smrg	    # We need to hardcode the library path
83731a9c160aSmrg	    if test -n "$shlibpath_var" && test -z "$avoidtemprpath"; then
8374dc407927Smrg	      # Make sure the rpath contains only unique directories.
83751a9c160aSmrg	      case $temp_rpath: in
8376dc407927Smrg	      *"$absdir:"*) ;;
8377dd0822caSmrg	      *) func_append temp_rpath "$absdir:" ;;
8378dc407927Smrg	      esac
8379dc407927Smrg	    fi
8380dc407927Smrg
8381dc407927Smrg	    # Hardcode the library path.
8382dc407927Smrg	    # Skip directories that are in the system default run-time
8383dc407927Smrg	    # search path.
8384dc407927Smrg	    case " $sys_lib_dlsearch_path " in
8385dc407927Smrg	    *" $absdir "*) ;;
8386dc407927Smrg	    *)
8387dc407927Smrg	      case "$compile_rpath " in
8388dc407927Smrg	      *" $absdir "*) ;;
8389dd0822caSmrg	      *) func_append compile_rpath " $absdir" ;;
8390dc407927Smrg	      esac
8391dc407927Smrg	      ;;
8392dc407927Smrg	    esac
8393dc407927Smrg	    case " $sys_lib_dlsearch_path " in
8394dc407927Smrg	    *" $libdir "*) ;;
8395dc407927Smrg	    *)
8396dc407927Smrg	      case "$finalize_rpath " in
8397dc407927Smrg	      *" $libdir "*) ;;
8398dd0822caSmrg	      *) func_append finalize_rpath " $libdir" ;;
8399dc407927Smrg	      esac
8400dc407927Smrg	      ;;
8401dc407927Smrg	    esac
8402dc407927Smrg	  fi # $linkmode,$pass = prog,link...
8403dc407927Smrg
84041a9c160aSmrg	  if $alldeplibs &&
84051a9c160aSmrg	     { test pass_all = "$deplibs_check_method" ||
84061a9c160aSmrg	       { test yes = "$build_libtool_libs" &&
8407dc407927Smrg		 test -n "$library_names"; }; }; then
8408dc407927Smrg	    # We only need to search for static libraries
8409dc407927Smrg	    continue
8410dc407927Smrg	  fi
8411dc407927Smrg	fi
8412dc407927Smrg
8413dc407927Smrg	link_static=no # Whether the deplib will be linked statically
8414dc407927Smrg	use_static_libs=$prefer_static_libs
84151a9c160aSmrg	if test built = "$use_static_libs" && test yes = "$installed"; then
8416dc407927Smrg	  use_static_libs=no
8417dc407927Smrg	fi
8418dc407927Smrg	if test -n "$library_names" &&
84191a9c160aSmrg	   { test no = "$use_static_libs" || test -z "$old_library"; }; then
8420dc407927Smrg	  case $host in
84211a9c160aSmrg	  *cygwin* | *mingw* | *cegcc* | *os2*)
8422dc407927Smrg	      # No point in relinking DLLs because paths are not encoded
8423dd0822caSmrg	      func_append notinst_deplibs " $lib"
8424dc407927Smrg	      need_relink=no
8425dc407927Smrg	    ;;
8426dc407927Smrg	  *)
84271a9c160aSmrg	    if test no = "$installed"; then
8428dd0822caSmrg	      func_append notinst_deplibs " $lib"
8429dc407927Smrg	      need_relink=yes
8430dc407927Smrg	    fi
8431dc407927Smrg	    ;;
8432dc407927Smrg	  esac
8433dc407927Smrg	  # This is a shared library
8434dc407927Smrg
8435dc407927Smrg	  # Warn about portability, can't link against -module's on some
8436dc407927Smrg	  # systems (darwin).  Don't bleat about dlopened modules though!
84371a9c160aSmrg	  dlopenmodule=
8438dc407927Smrg	  for dlpremoduletest in $dlprefiles; do
8439dc407927Smrg	    if test "X$dlpremoduletest" = "X$lib"; then
84401a9c160aSmrg	      dlopenmodule=$dlpremoduletest
8441dc407927Smrg	      break
8442dc407927Smrg	    fi
8443dc407927Smrg	  done
84441a9c160aSmrg	  if test -z "$dlopenmodule" && test yes = "$shouldnotlink" && test link = "$pass"; then
8445dd0822caSmrg	    echo
84461a9c160aSmrg	    if test prog = "$linkmode"; then
8447dc407927Smrg	      $ECHO "*** Warning: Linking the executable $output against the loadable module"
8448dc407927Smrg	    else
8449dc407927Smrg	      $ECHO "*** Warning: Linking the shared library $output against the loadable module"
8450dc407927Smrg	    fi
8451dc407927Smrg	    $ECHO "*** $linklib is not portable!"
8452dc407927Smrg	  fi
84531a9c160aSmrg	  if test lib = "$linkmode" &&
84541a9c160aSmrg	     test yes = "$hardcode_into_libs"; then
8455dc407927Smrg	    # Hardcode the library path.
8456dc407927Smrg	    # Skip directories that are in the system default run-time
8457dc407927Smrg	    # search path.
8458dc407927Smrg	    case " $sys_lib_dlsearch_path " in
8459dc407927Smrg	    *" $absdir "*) ;;
8460dc407927Smrg	    *)
8461dc407927Smrg	      case "$compile_rpath " in
8462dc407927Smrg	      *" $absdir "*) ;;
8463dd0822caSmrg	      *) func_append compile_rpath " $absdir" ;;
8464dc407927Smrg	      esac
8465dc407927Smrg	      ;;
8466dc407927Smrg	    esac
8467dc407927Smrg	    case " $sys_lib_dlsearch_path " in
8468dc407927Smrg	    *" $libdir "*) ;;
8469dc407927Smrg	    *)
8470dc407927Smrg	      case "$finalize_rpath " in
8471dc407927Smrg	      *" $libdir "*) ;;
8472dd0822caSmrg	      *) func_append finalize_rpath " $libdir" ;;
8473dc407927Smrg	      esac
8474dc407927Smrg	      ;;
8475dc407927Smrg	    esac
8476dc407927Smrg	  fi
8477dc407927Smrg
8478dc407927Smrg	  if test -n "$old_archive_from_expsyms_cmds"; then
8479dc407927Smrg	    # figure out the soname
8480dc407927Smrg	    set dummy $library_names
8481dc407927Smrg	    shift
84821a9c160aSmrg	    realname=$1
8483dc407927Smrg	    shift
8484dc407927Smrg	    libname=`eval "\\$ECHO \"$libname_spec\""`
8485dc407927Smrg	    # use dlname if we got it. it's perfectly good, no?
8486dc407927Smrg	    if test -n "$dlname"; then
84871a9c160aSmrg	      soname=$dlname
8488dc407927Smrg	    elif test -n "$soname_spec"; then
8489dc407927Smrg	      # bleh windows
8490dc407927Smrg	      case $host in
84911a9c160aSmrg	      *cygwin* | mingw* | *cegcc* | *os2*)
8492dc407927Smrg	        func_arith $current - $age
8493dc407927Smrg		major=$func_arith_result
84941a9c160aSmrg		versuffix=-$major
8495dc407927Smrg		;;
8496dc407927Smrg	      esac
8497dc407927Smrg	      eval soname=\"$soname_spec\"
8498dc407927Smrg	    else
84991a9c160aSmrg	      soname=$realname
8500dc407927Smrg	    fi
8501dc407927Smrg
8502dc407927Smrg	    # Make a new name for the extract_expsyms_cmds to use
85031a9c160aSmrg	    soroot=$soname
8504dc407927Smrg	    func_basename "$soroot"
85051a9c160aSmrg	    soname=$func_basename_result
8506dc407927Smrg	    func_stripname 'lib' '.dll' "$soname"
8507dc407927Smrg	    newlib=libimp-$func_stripname_result.a
8508dc407927Smrg
8509dc407927Smrg	    # If the library has no export list, then create one now
8510dc407927Smrg	    if test -f "$output_objdir/$soname-def"; then :
8511dc407927Smrg	    else
85121a9c160aSmrg	      func_verbose "extracting exported symbol list from '$soname'"
8513dc407927Smrg	      func_execute_cmds "$extract_expsyms_cmds" 'exit $?'
8514dc407927Smrg	    fi
8515dc407927Smrg
8516dc407927Smrg	    # Create $newlib
8517dc407927Smrg	    if test -f "$output_objdir/$newlib"; then :; else
85181a9c160aSmrg	      func_verbose "generating import library for '$soname'"
8519dc407927Smrg	      func_execute_cmds "$old_archive_from_expsyms_cmds" 'exit $?'
8520dc407927Smrg	    fi
8521dc407927Smrg	    # make sure the library variables are pointing to the new library
8522dc407927Smrg	    dir=$output_objdir
8523dc407927Smrg	    linklib=$newlib
8524dc407927Smrg	  fi # test -n "$old_archive_from_expsyms_cmds"
8525dc407927Smrg
85261a9c160aSmrg	  if test prog = "$linkmode" || test relink != "$opt_mode"; then
8527dc407927Smrg	    add_shlibpath=
8528dc407927Smrg	    add_dir=
8529dc407927Smrg	    add=
8530dc407927Smrg	    lib_linked=yes
8531dc407927Smrg	    case $hardcode_action in
8532dc407927Smrg	    immediate | unsupported)
85331a9c160aSmrg	      if test no = "$hardcode_direct"; then
85341a9c160aSmrg		add=$dir/$linklib
8535dc407927Smrg		case $host in
85361a9c160aSmrg		  *-*-sco3.2v5.0.[024]*) add_dir=-L$dir ;;
85371a9c160aSmrg		  *-*-sysv4*uw2*) add_dir=-L$dir ;;
8538dc407927Smrg		  *-*-sysv5OpenUNIX* | *-*-sysv5UnixWare7.[01].[10]* | \
85391a9c160aSmrg		    *-*-unixware7*) add_dir=-L$dir ;;
8540dc407927Smrg		  *-*-darwin* )
85411a9c160aSmrg		    # if the lib is a (non-dlopened) module then we cannot
8542dc407927Smrg		    # link against it, someone is ignoring the earlier warnings
8543dc407927Smrg		    if /usr/bin/file -L $add 2> /dev/null |
85441a9c160aSmrg			 $GREP ": [^:]* bundle" >/dev/null; then
8545dc407927Smrg		      if test "X$dlopenmodule" != "X$lib"; then
8546dc407927Smrg			$ECHO "*** Warning: lib $linklib is a module, not a shared library"
85471a9c160aSmrg			if test -z "$old_library"; then
8548dd0822caSmrg			  echo
8549dd0822caSmrg			  echo "*** And there doesn't seem to be a static archive available"
8550dd0822caSmrg			  echo "*** The link will probably fail, sorry"
8551dc407927Smrg			else
85521a9c160aSmrg			  add=$dir/$old_library
8553dc407927Smrg			fi
8554dc407927Smrg		      elif test -n "$old_library"; then
85551a9c160aSmrg			add=$dir/$old_library
8556dc407927Smrg		      fi
8557dc407927Smrg		    fi
8558dc407927Smrg		esac
85591a9c160aSmrg	      elif test no = "$hardcode_minus_L"; then
8560dc407927Smrg		case $host in
85611a9c160aSmrg		*-*-sunos*) add_shlibpath=$dir ;;
8562dc407927Smrg		esac
85631a9c160aSmrg		add_dir=-L$dir
85641a9c160aSmrg		add=-l$name
85651a9c160aSmrg	      elif test no = "$hardcode_shlibpath_var"; then
85661a9c160aSmrg		add_shlibpath=$dir
85671a9c160aSmrg		add=-l$name
8568dc407927Smrg	      else
8569dc407927Smrg		lib_linked=no
8570dc407927Smrg	      fi
8571dc407927Smrg	      ;;
8572dc407927Smrg	    relink)
85731a9c160aSmrg	      if test yes = "$hardcode_direct" &&
85741a9c160aSmrg	         test no = "$hardcode_direct_absolute"; then
85751a9c160aSmrg		add=$dir/$linklib
85761a9c160aSmrg	      elif test yes = "$hardcode_minus_L"; then
85771a9c160aSmrg		add_dir=-L$absdir
8578dc407927Smrg		# Try looking first in the location we're being installed to.
8579dc407927Smrg		if test -n "$inst_prefix_dir"; then
8580dc407927Smrg		  case $libdir in
8581dc407927Smrg		    [\\/]*)
8582dd0822caSmrg		      func_append add_dir " -L$inst_prefix_dir$libdir"
8583dc407927Smrg		      ;;
8584dc407927Smrg		  esac
8585dc407927Smrg		fi
85861a9c160aSmrg		add=-l$name
85871a9c160aSmrg	      elif test yes = "$hardcode_shlibpath_var"; then
85881a9c160aSmrg		add_shlibpath=$dir
85891a9c160aSmrg		add=-l$name
8590dc407927Smrg	      else
8591dc407927Smrg		lib_linked=no
8592dc407927Smrg	      fi
8593dc407927Smrg	      ;;
8594dc407927Smrg	    *) lib_linked=no ;;
8595dc407927Smrg	    esac
8596dc407927Smrg
85971a9c160aSmrg	    if test yes != "$lib_linked"; then
8598dc407927Smrg	      func_fatal_configuration "unsupported hardcode properties"
8599dc407927Smrg	    fi
8600dc407927Smrg
8601dc407927Smrg	    if test -n "$add_shlibpath"; then
8602dc407927Smrg	      case :$compile_shlibpath: in
8603dc407927Smrg	      *":$add_shlibpath:"*) ;;
8604dd0822caSmrg	      *) func_append compile_shlibpath "$add_shlibpath:" ;;
8605dc407927Smrg	      esac
8606dc407927Smrg	    fi
86071a9c160aSmrg	    if test prog = "$linkmode"; then
8608dc407927Smrg	      test -n "$add_dir" && compile_deplibs="$add_dir $compile_deplibs"
8609dc407927Smrg	      test -n "$add" && compile_deplibs="$add $compile_deplibs"
8610dc407927Smrg	    else
8611dc407927Smrg	      test -n "$add_dir" && deplibs="$add_dir $deplibs"
8612dc407927Smrg	      test -n "$add" && deplibs="$add $deplibs"
86131a9c160aSmrg	      if test yes != "$hardcode_direct" &&
86141a9c160aSmrg		 test yes != "$hardcode_minus_L" &&
86151a9c160aSmrg		 test yes = "$hardcode_shlibpath_var"; then
8616dc407927Smrg		case :$finalize_shlibpath: in
8617dc407927Smrg		*":$libdir:"*) ;;
8618dd0822caSmrg		*) func_append finalize_shlibpath "$libdir:" ;;
8619dc407927Smrg		esac
8620dc407927Smrg	      fi
8621dc407927Smrg	    fi
8622dc407927Smrg	  fi
8623dc407927Smrg
86241a9c160aSmrg	  if test prog = "$linkmode" || test relink = "$opt_mode"; then
8625dc407927Smrg	    add_shlibpath=
8626dc407927Smrg	    add_dir=
8627dc407927Smrg	    add=
8628dc407927Smrg	    # Finalize command for both is simple: just hardcode it.
86291a9c160aSmrg	    if test yes = "$hardcode_direct" &&
86301a9c160aSmrg	       test no = "$hardcode_direct_absolute"; then
86311a9c160aSmrg	      add=$libdir/$linklib
86321a9c160aSmrg	    elif test yes = "$hardcode_minus_L"; then
86331a9c160aSmrg	      add_dir=-L$libdir
86341a9c160aSmrg	      add=-l$name
86351a9c160aSmrg	    elif test yes = "$hardcode_shlibpath_var"; then
8636dc407927Smrg	      case :$finalize_shlibpath: in
8637dc407927Smrg	      *":$libdir:"*) ;;
8638dd0822caSmrg	      *) func_append finalize_shlibpath "$libdir:" ;;
8639dc407927Smrg	      esac
86401a9c160aSmrg	      add=-l$name
86411a9c160aSmrg	    elif test yes = "$hardcode_automatic"; then
8642dc407927Smrg	      if test -n "$inst_prefix_dir" &&
86431a9c160aSmrg		 test -f "$inst_prefix_dir$libdir/$linklib"; then
86441a9c160aSmrg		add=$inst_prefix_dir$libdir/$linklib
8645dc407927Smrg	      else
86461a9c160aSmrg		add=$libdir/$linklib
8647dc407927Smrg	      fi
8648dc407927Smrg	    else
8649dc407927Smrg	      # We cannot seem to hardcode it, guess we'll fake it.
86501a9c160aSmrg	      add_dir=-L$libdir
8651dc407927Smrg	      # Try looking first in the location we're being installed to.
8652dc407927Smrg	      if test -n "$inst_prefix_dir"; then
8653dc407927Smrg		case $libdir in
8654dc407927Smrg		  [\\/]*)
8655dd0822caSmrg		    func_append add_dir " -L$inst_prefix_dir$libdir"
8656dc407927Smrg		    ;;
8657dc407927Smrg		esac
8658dc407927Smrg	      fi
86591a9c160aSmrg	      add=-l$name
8660dc407927Smrg	    fi
8661dc407927Smrg
86621a9c160aSmrg	    if test prog = "$linkmode"; then
8663dc407927Smrg	      test -n "$add_dir" && finalize_deplibs="$add_dir $finalize_deplibs"
8664dc407927Smrg	      test -n "$add" && finalize_deplibs="$add $finalize_deplibs"
8665dc407927Smrg	    else
8666dc407927Smrg	      test -n "$add_dir" && deplibs="$add_dir $deplibs"
8667dc407927Smrg	      test -n "$add" && deplibs="$add $deplibs"
8668dc407927Smrg	    fi
8669dc407927Smrg	  fi
86701a9c160aSmrg	elif test prog = "$linkmode"; then
8671dc407927Smrg	  # Here we assume that one of hardcode_direct or hardcode_minus_L
8672dc407927Smrg	  # is not unsupported.  This is valid on all known static and
8673dc407927Smrg	  # shared platforms.
86741a9c160aSmrg	  if test unsupported != "$hardcode_direct"; then
86751a9c160aSmrg	    test -n "$old_library" && linklib=$old_library
8676dc407927Smrg	    compile_deplibs="$dir/$linklib $compile_deplibs"
8677dc407927Smrg	    finalize_deplibs="$dir/$linklib $finalize_deplibs"
8678dc407927Smrg	  else
8679dc407927Smrg	    compile_deplibs="-l$name -L$dir $compile_deplibs"
8680dc407927Smrg	    finalize_deplibs="-l$name -L$dir $finalize_deplibs"
8681dc407927Smrg	  fi
86821a9c160aSmrg	elif test yes = "$build_libtool_libs"; then
8683dc407927Smrg	  # Not a shared library
86841a9c160aSmrg	  if test pass_all != "$deplibs_check_method"; then
8685dc407927Smrg	    # We're trying link a shared library against a static one
8686dc407927Smrg	    # but the system doesn't support it.
8687dc407927Smrg
8688dc407927Smrg	    # Just print a warning and add the library to dependency_libs so
8689dc407927Smrg	    # that the program can be linked against the static library.
8690dd0822caSmrg	    echo
86911a9c160aSmrg	    $ECHO "*** Warning: This system cannot link to static lib archive $lib."
8692dd0822caSmrg	    echo "*** I have the capability to make that library automatically link in when"
8693dd0822caSmrg	    echo "*** you link to this library.  But I can only do this if you have a"
8694dd0822caSmrg	    echo "*** shared version of the library, which you do not appear to have."
86951a9c160aSmrg	    if test yes = "$module"; then
8696dd0822caSmrg	      echo "*** But as you try to build a module library, libtool will still create "
8697dd0822caSmrg	      echo "*** a static module, that should work as long as the dlopening application"
8698dd0822caSmrg	      echo "*** is linked with the -dlopen flag to resolve symbols at runtime."
8699dc407927Smrg	      if test -z "$global_symbol_pipe"; then
8700dd0822caSmrg		echo
8701dd0822caSmrg		echo "*** However, this would only work if libtool was able to extract symbol"
87021a9c160aSmrg		echo "*** lists from a program, using 'nm' or equivalent, but libtool could"
8703dd0822caSmrg		echo "*** not find such a program.  So, this module is probably useless."
87041a9c160aSmrg		echo "*** 'nm' from GNU binutils and a full rebuild may help."
8705dc407927Smrg	      fi
87061a9c160aSmrg	      if test no = "$build_old_libs"; then
8707dc407927Smrg		build_libtool_libs=module
8708dc407927Smrg		build_old_libs=yes
8709dc407927Smrg	      else
8710dc407927Smrg		build_libtool_libs=no
8711dc407927Smrg	      fi
8712dc407927Smrg	    fi
8713dc407927Smrg	  else
8714dc407927Smrg	    deplibs="$dir/$old_library $deplibs"
8715dc407927Smrg	    link_static=yes
8716dc407927Smrg	  fi
8717dc407927Smrg	fi # link shared/static library?
8718dc407927Smrg
87191a9c160aSmrg	if test lib = "$linkmode"; then
8720dc407927Smrg	  if test -n "$dependency_libs" &&
87211a9c160aSmrg	     { test yes != "$hardcode_into_libs" ||
87221a9c160aSmrg	       test yes = "$build_old_libs" ||
87231a9c160aSmrg	       test yes = "$link_static"; }; then
8724dc407927Smrg	    # Extract -R from dependency_libs
8725dc407927Smrg	    temp_deplibs=
8726dc407927Smrg	    for libdir in $dependency_libs; do
8727dc407927Smrg	      case $libdir in
8728dc407927Smrg	      -R*) func_stripname '-R' '' "$libdir"
8729dc407927Smrg	           temp_xrpath=$func_stripname_result
8730dc407927Smrg		   case " $xrpath " in
8731dc407927Smrg		   *" $temp_xrpath "*) ;;
8732dd0822caSmrg		   *) func_append xrpath " $temp_xrpath";;
8733dc407927Smrg		   esac;;
8734dd0822caSmrg	      *) func_append temp_deplibs " $libdir";;
8735dc407927Smrg	      esac
8736dc407927Smrg	    done
87371a9c160aSmrg	    dependency_libs=$temp_deplibs
8738dc407927Smrg	  fi
8739dc407927Smrg
8740dd0822caSmrg	  func_append newlib_search_path " $absdir"
8741dc407927Smrg	  # Link against this library
87421a9c160aSmrg	  test no = "$link_static" && newdependency_libs="$abs_ladir/$laname $newdependency_libs"
8743dc407927Smrg	  # ... and its dependency_libs
8744dc407927Smrg	  tmp_libs=
8745dc407927Smrg	  for deplib in $dependency_libs; do
8746dc407927Smrg	    newdependency_libs="$deplib $newdependency_libs"
8747dd0822caSmrg	    case $deplib in
8748dd0822caSmrg              -L*) func_stripname '-L' '' "$deplib"
8749dd0822caSmrg                   func_resolve_sysroot "$func_stripname_result";;
8750dd0822caSmrg              *) func_resolve_sysroot "$deplib" ;;
8751dd0822caSmrg            esac
87521a9c160aSmrg	    if $opt_preserve_dup_deps; then
8753dc407927Smrg	      case "$tmp_libs " in
8754dd0822caSmrg	      *" $func_resolve_sysroot_result "*)
8755dd0822caSmrg                func_append specialdeplibs " $func_resolve_sysroot_result" ;;
8756dc407927Smrg	      esac
8757dc407927Smrg	    fi
8758dd0822caSmrg	    func_append tmp_libs " $func_resolve_sysroot_result"
8759dc407927Smrg	  done
8760dc407927Smrg
87611a9c160aSmrg	  if test no != "$link_all_deplibs"; then
8762dc407927Smrg	    # Add the search paths of all dependency libraries
8763dc407927Smrg	    for deplib in $dependency_libs; do
8764dd0822caSmrg	      path=
8765dc407927Smrg	      case $deplib in
87661a9c160aSmrg	      -L*) path=$deplib ;;
8767dc407927Smrg	      *.la)
8768dd0822caSmrg	        func_resolve_sysroot "$deplib"
8769dd0822caSmrg	        deplib=$func_resolve_sysroot_result
8770dc407927Smrg	        func_dirname "$deplib" "" "."
8771dd0822caSmrg		dir=$func_dirname_result
8772dc407927Smrg		# We need an absolute path.
8773dc407927Smrg		case $dir in
87741a9c160aSmrg		[\\/]* | [A-Za-z]:[\\/]*) absdir=$dir ;;
8775dc407927Smrg		*)
8776dc407927Smrg		  absdir=`cd "$dir" && pwd`
8777dc407927Smrg		  if test -z "$absdir"; then
87781a9c160aSmrg		    func_warning "cannot determine absolute directory name of '$dir'"
87791a9c160aSmrg		    absdir=$dir
8780dc407927Smrg		  fi
8781dc407927Smrg		  ;;
8782dc407927Smrg		esac
8783dc407927Smrg		if $GREP "^installed=no" $deplib > /dev/null; then
8784dc407927Smrg		case $host in
8785dc407927Smrg		*-*-darwin*)
8786dc407927Smrg		  depdepl=
87871a9c160aSmrg		  eval deplibrary_names=`$SED -n -e 's/^library_names=\(.*\)$/\1/p' $deplib`
87881a9c160aSmrg		  if test -n "$deplibrary_names"; then
87891a9c160aSmrg		    for tmp in $deplibrary_names; do
8790dc407927Smrg		      depdepl=$tmp
8791dc407927Smrg		    done
87921a9c160aSmrg		    if test -f "$absdir/$objdir/$depdepl"; then
87931a9c160aSmrg		      depdepl=$absdir/$objdir/$depdepl
87941a9c160aSmrg		      darwin_install_name=`$OTOOL -L $depdepl | awk '{if (NR == 2) {print $1;exit}}'`
8795dc407927Smrg                      if test -z "$darwin_install_name"; then
87961a9c160aSmrg                          darwin_install_name=`$OTOOL64 -L $depdepl  | awk '{if (NR == 2) {print $1;exit}}'`
8797dc407927Smrg                      fi
87981a9c160aSmrg		      func_append compiler_flags " $wl-dylib_file $wl$darwin_install_name:$depdepl"
87991a9c160aSmrg		      func_append linker_flags " -dylib_file $darwin_install_name:$depdepl"
8800dc407927Smrg		      path=
8801dc407927Smrg		    fi
8802dc407927Smrg		  fi
8803dc407927Smrg		  ;;
8804dc407927Smrg		*)
88051a9c160aSmrg		  path=-L$absdir/$objdir
8806dc407927Smrg		  ;;
8807dc407927Smrg		esac
8808dc407927Smrg		else
88091a9c160aSmrg		  eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $deplib`
8810dc407927Smrg		  test -z "$libdir" && \
88111a9c160aSmrg		    func_fatal_error "'$deplib' is not a valid libtool archive"
8812dc407927Smrg		  test "$absdir" != "$libdir" && \
88131a9c160aSmrg		    func_warning "'$deplib' seems to be moved"
8814dc407927Smrg
88151a9c160aSmrg		  path=-L$absdir
8816dc407927Smrg		fi
8817dc407927Smrg		;;
8818dc407927Smrg	      esac
8819dc407927Smrg	      case " $deplibs " in
8820dc407927Smrg	      *" $path "*) ;;
8821dc407927Smrg	      *) deplibs="$path $deplibs" ;;
8822dc407927Smrg	      esac
8823dc407927Smrg	    done
8824dc407927Smrg	  fi # link_all_deplibs != no
8825dc407927Smrg	fi # linkmode = lib
8826dc407927Smrg      done # for deplib in $libs
88271a9c160aSmrg      if test link = "$pass"; then
88281a9c160aSmrg	if test prog = "$linkmode"; then
8829dc407927Smrg	  compile_deplibs="$new_inherited_linker_flags $compile_deplibs"
8830dc407927Smrg	  finalize_deplibs="$new_inherited_linker_flags $finalize_deplibs"
8831dc407927Smrg	else
8832dd0822caSmrg	  compiler_flags="$compiler_flags "`$ECHO " $new_inherited_linker_flags" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
8833dc407927Smrg	fi
8834dc407927Smrg      fi
88351a9c160aSmrg      dependency_libs=$newdependency_libs
88361a9c160aSmrg      if test dlpreopen = "$pass"; then
8837dc407927Smrg	# Link the dlpreopened libraries before other libraries
8838dc407927Smrg	for deplib in $save_deplibs; do
8839dc407927Smrg	  deplibs="$deplib $deplibs"
8840dc407927Smrg	done
8841dc407927Smrg      fi
88421a9c160aSmrg      if test dlopen != "$pass"; then
88431a9c160aSmrg	test conv = "$pass" || {
8844dc407927Smrg	  # Make sure lib_search_path contains only unique directories.
8845dc407927Smrg	  lib_search_path=
8846dc407927Smrg	  for dir in $newlib_search_path; do
8847dc407927Smrg	    case "$lib_search_path " in
8848dc407927Smrg	    *" $dir "*) ;;
8849dd0822caSmrg	    *) func_append lib_search_path " $dir" ;;
8850dc407927Smrg	    esac
8851dc407927Smrg	  done
8852dc407927Smrg	  newlib_search_path=
88531a9c160aSmrg	}
8854dc407927Smrg
88551a9c160aSmrg	if test prog,link = "$linkmode,$pass"; then
8856dc407927Smrg	  vars="compile_deplibs finalize_deplibs"
88571a9c160aSmrg	else
88581a9c160aSmrg	  vars=deplibs
8859dc407927Smrg	fi
8860dc407927Smrg	for var in $vars dependency_libs; do
8861dc407927Smrg	  # Add libraries to $var in reverse order
8862dc407927Smrg	  eval tmp_libs=\"\$$var\"
8863dc407927Smrg	  new_libs=
8864dc407927Smrg	  for deplib in $tmp_libs; do
8865dc407927Smrg	    # FIXME: Pedantically, this is the right thing to do, so
8866dc407927Smrg	    #        that some nasty dependency loop isn't accidentally
8867dc407927Smrg	    #        broken:
8868dc407927Smrg	    #new_libs="$deplib $new_libs"
8869dc407927Smrg	    # Pragmatically, this seems to cause very few problems in
8870dc407927Smrg	    # practice:
8871dc407927Smrg	    case $deplib in
8872dc407927Smrg	    -L*) new_libs="$deplib $new_libs" ;;
8873dc407927Smrg	    -R*) ;;
8874dc407927Smrg	    *)
8875dc407927Smrg	      # And here is the reason: when a library appears more
8876dc407927Smrg	      # than once as an explicit dependence of a library, or
8877dc407927Smrg	      # is implicitly linked in more than once by the
8878dc407927Smrg	      # compiler, it is considered special, and multiple
8879dc407927Smrg	      # occurrences thereof are not removed.  Compare this
8880dc407927Smrg	      # with having the same library being listed as a
8881dc407927Smrg	      # dependency of multiple other libraries: in this case,
8882dc407927Smrg	      # we know (pedantically, we assume) the library does not
8883dc407927Smrg	      # need to be listed more than once, so we keep only the
8884dc407927Smrg	      # last copy.  This is not always right, but it is rare
8885dc407927Smrg	      # enough that we require users that really mean to play
8886dc407927Smrg	      # such unportable linking tricks to link the library
8887dc407927Smrg	      # using -Wl,-lname, so that libtool does not consider it
8888dc407927Smrg	      # for duplicate removal.
8889dc407927Smrg	      case " $specialdeplibs " in
8890dc407927Smrg	      *" $deplib "*) new_libs="$deplib $new_libs" ;;
8891dc407927Smrg	      *)
8892dc407927Smrg		case " $new_libs " in
8893dc407927Smrg		*" $deplib "*) ;;
8894dc407927Smrg		*) new_libs="$deplib $new_libs" ;;
8895dc407927Smrg		esac
8896dc407927Smrg		;;
8897dc407927Smrg	      esac
8898dc407927Smrg	      ;;
8899dc407927Smrg	    esac
8900dc407927Smrg	  done
8901dc407927Smrg	  tmp_libs=
8902dc407927Smrg	  for deplib in $new_libs; do
8903dc407927Smrg	    case $deplib in
8904dc407927Smrg	    -L*)
8905dc407927Smrg	      case " $tmp_libs " in
8906dc407927Smrg	      *" $deplib "*) ;;
8907dd0822caSmrg	      *) func_append tmp_libs " $deplib" ;;
8908dc407927Smrg	      esac
8909dc407927Smrg	      ;;
8910dd0822caSmrg	    *) func_append tmp_libs " $deplib" ;;
8911dc407927Smrg	    esac
8912dc407927Smrg	  done
8913dc407927Smrg	  eval $var=\"$tmp_libs\"
8914dc407927Smrg	done # for var
8915dc407927Smrg      fi
89161a9c160aSmrg
89171a9c160aSmrg      # Add Sun CC postdeps if required:
89181a9c160aSmrg      test CXX = "$tagname" && {
89191a9c160aSmrg        case $host_os in
89201a9c160aSmrg        linux*)
8921621f50c3Smrg          case `$CC -V 2>&1 | $SED 5q` in
89221a9c160aSmrg          *Sun\ C*) # Sun C++ 5.9
89231a9c160aSmrg            func_suncc_cstd_abi
89241a9c160aSmrg
89251a9c160aSmrg            if test no != "$suncc_use_cstd_abi"; then
89261a9c160aSmrg              func_append postdeps ' -library=Cstd -library=Crun'
89271a9c160aSmrg            fi
89281a9c160aSmrg            ;;
89291a9c160aSmrg          esac
89301a9c160aSmrg          ;;
89311a9c160aSmrg
89321a9c160aSmrg        solaris*)
89331a9c160aSmrg          func_cc_basename "$CC"
89341a9c160aSmrg          case $func_cc_basename_result in
89351a9c160aSmrg          CC* | sunCC*)
89361a9c160aSmrg            func_suncc_cstd_abi
89371a9c160aSmrg
89381a9c160aSmrg            if test no != "$suncc_use_cstd_abi"; then
89391a9c160aSmrg              func_append postdeps ' -library=Cstd -library=Crun'
89401a9c160aSmrg            fi
89411a9c160aSmrg            ;;
89421a9c160aSmrg          esac
89431a9c160aSmrg          ;;
89441a9c160aSmrg        esac
89451a9c160aSmrg      }
89461a9c160aSmrg
8947dc407927Smrg      # Last step: remove runtime libs from dependency_libs
8948dc407927Smrg      # (they stay in deplibs)
8949dc407927Smrg      tmp_libs=
89501a9c160aSmrg      for i in $dependency_libs; do
8951dc407927Smrg	case " $predeps $postdeps $compiler_lib_search_path " in
8952dc407927Smrg	*" $i "*)
89531a9c160aSmrg	  i=
8954dc407927Smrg	  ;;
8955dc407927Smrg	esac
89561a9c160aSmrg	if test -n "$i"; then
8957dd0822caSmrg	  func_append tmp_libs " $i"
8958dc407927Smrg	fi
8959dc407927Smrg      done
8960dc407927Smrg      dependency_libs=$tmp_libs
8961dc407927Smrg    done # for pass
89621a9c160aSmrg    if test prog = "$linkmode"; then
89631a9c160aSmrg      dlfiles=$newdlfiles
8964dc407927Smrg    fi
89651a9c160aSmrg    if test prog = "$linkmode" || test lib = "$linkmode"; then
89661a9c160aSmrg      dlprefiles=$newdlprefiles
8967dc407927Smrg    fi
8968dc407927Smrg
8969dc407927Smrg    case $linkmode in
8970dc407927Smrg    oldlib)
89711a9c160aSmrg      if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then
89721a9c160aSmrg	func_warning "'-dlopen' is ignored for archives"
8973dc407927Smrg      fi
8974dc407927Smrg
8975dc407927Smrg      case " $deplibs" in
8976dc407927Smrg      *\ -l* | *\ -L*)
89771a9c160aSmrg	func_warning "'-l' and '-L' are ignored for archives" ;;
8978dc407927Smrg      esac
8979dc407927Smrg
8980dc407927Smrg      test -n "$rpath" && \
89811a9c160aSmrg	func_warning "'-rpath' is ignored for archives"
8982dc407927Smrg
8983dc407927Smrg      test -n "$xrpath" && \
89841a9c160aSmrg	func_warning "'-R' is ignored for archives"
8985dc407927Smrg
8986dc407927Smrg      test -n "$vinfo" && \
89871a9c160aSmrg	func_warning "'-version-info/-version-number' is ignored for archives"
8988dc407927Smrg
8989dc407927Smrg      test -n "$release" && \
89901a9c160aSmrg	func_warning "'-release' is ignored for archives"
8991dc407927Smrg
8992dc407927Smrg      test -n "$export_symbols$export_symbols_regex" && \
89931a9c160aSmrg	func_warning "'-export-symbols' is ignored for archives"
8994dc407927Smrg
8995dc407927Smrg      # Now set the variables for building old libraries.
8996dc407927Smrg      build_libtool_libs=no
89971a9c160aSmrg      oldlibs=$output
8998dd0822caSmrg      func_append objs "$old_deplibs"
8999dc407927Smrg      ;;
9000dc407927Smrg
9001dc407927Smrg    lib)
90021a9c160aSmrg      # Make sure we only generate libraries of the form 'libNAME.la'.
9003dc407927Smrg      case $outputname in
9004dc407927Smrg      lib*)
9005dc407927Smrg	func_stripname 'lib' '.la' "$outputname"
9006dc407927Smrg	name=$func_stripname_result
9007dc407927Smrg	eval shared_ext=\"$shrext_cmds\"
9008dc407927Smrg	eval libname=\"$libname_spec\"
9009dc407927Smrg	;;
9010dc407927Smrg      *)
90111a9c160aSmrg	test no = "$module" \
90121a9c160aSmrg	  && func_fatal_help "libtool library '$output' must begin with 'lib'"
9013dc407927Smrg
90141a9c160aSmrg	if test no != "$need_lib_prefix"; then
9015dc407927Smrg	  # Add the "lib" prefix for modules if required
9016dc407927Smrg	  func_stripname '' '.la' "$outputname"
9017dc407927Smrg	  name=$func_stripname_result
9018dc407927Smrg	  eval shared_ext=\"$shrext_cmds\"
9019dc407927Smrg	  eval libname=\"$libname_spec\"
9020dc407927Smrg	else
9021dc407927Smrg	  func_stripname '' '.la' "$outputname"
9022dc407927Smrg	  libname=$func_stripname_result
9023dc407927Smrg	fi
9024dc407927Smrg	;;
9025dc407927Smrg      esac
9026dc407927Smrg
9027dc407927Smrg      if test -n "$objs"; then
90281a9c160aSmrg	if test pass_all != "$deplibs_check_method"; then
90291a9c160aSmrg	  func_fatal_error "cannot build libtool library '$output' from non-libtool objects on this host:$objs"
9030dc407927Smrg	else
9031dd0822caSmrg	  echo
9032dc407927Smrg	  $ECHO "*** Warning: Linking the shared library $output against the non-libtool"
9033dc407927Smrg	  $ECHO "*** objects $objs is not portable!"
9034dd0822caSmrg	  func_append libobjs " $objs"
9035dc407927Smrg	fi
9036dc407927Smrg      fi
9037dc407927Smrg
90381a9c160aSmrg      test no = "$dlself" \
90391a9c160aSmrg	|| func_warning "'-dlopen self' is ignored for libtool libraries"
9040dc407927Smrg
9041dc407927Smrg      set dummy $rpath
9042dc407927Smrg      shift
90431a9c160aSmrg      test 1 -lt "$#" \
90441a9c160aSmrg	&& func_warning "ignoring multiple '-rpath's for a libtool library"
9045dc407927Smrg
90461a9c160aSmrg      install_libdir=$1
9047dc407927Smrg
9048dc407927Smrg      oldlibs=
9049dc407927Smrg      if test -z "$rpath"; then
90501a9c160aSmrg	if test yes = "$build_libtool_libs"; then
9051dc407927Smrg	  # Building a libtool convenience library.
90521a9c160aSmrg	  # Some compilers have problems with a '.al' extension so
9053dc407927Smrg	  # convenience libraries should have the same extension an
9054dc407927Smrg	  # archive normally would.
9055dc407927Smrg	  oldlibs="$output_objdir/$libname.$libext $oldlibs"
9056dc407927Smrg	  build_libtool_libs=convenience
9057dc407927Smrg	  build_old_libs=yes
9058dc407927Smrg	fi
9059dc407927Smrg
9060dc407927Smrg	test -n "$vinfo" && \
90611a9c160aSmrg	  func_warning "'-version-info/-version-number' is ignored for convenience libraries"
9062dc407927Smrg
9063dc407927Smrg	test -n "$release" && \
90641a9c160aSmrg	  func_warning "'-release' is ignored for convenience libraries"
9065dc407927Smrg      else
9066dc407927Smrg
9067dc407927Smrg	# Parse the version information argument.
90681a9c160aSmrg	save_ifs=$IFS; IFS=:
9069dc407927Smrg	set dummy $vinfo 0 0 0
9070dc407927Smrg	shift
90711a9c160aSmrg	IFS=$save_ifs
9072dc407927Smrg
9073dc407927Smrg	test -n "$7" && \
90741a9c160aSmrg	  func_fatal_help "too many parameters to '-version-info'"
9075dc407927Smrg
9076dc407927Smrg	# convert absolute version numbers to libtool ages
9077dc407927Smrg	# this retains compatibility with .la files and attempts
9078dc407927Smrg	# to make the code below a bit more comprehensible
9079dc407927Smrg
9080dc407927Smrg	case $vinfo_number in
9081dc407927Smrg	yes)
90821a9c160aSmrg	  number_major=$1
90831a9c160aSmrg	  number_minor=$2
90841a9c160aSmrg	  number_revision=$3
9085dc407927Smrg	  #
9086dc407927Smrg	  # There are really only two kinds -- those that
9087dc407927Smrg	  # use the current revision as the major version
9088dc407927Smrg	  # and those that subtract age and use age as
9089dc407927Smrg	  # a minor version.  But, then there is irix
90901a9c160aSmrg	  # that has an extra 1 added just for fun
9091dc407927Smrg	  #
9092dc407927Smrg	  case $version_type in
909375cbef56Smrg	  # correct linux to gnu/linux during the next big refactor
9094621f50c3Smrg	  darwin|freebsd-elf|linux|midnightbsd-elf|osf|windows|none)
9095dc407927Smrg	    func_arith $number_major + $number_minor
9096dc407927Smrg	    current=$func_arith_result
90971a9c160aSmrg	    age=$number_minor
90981a9c160aSmrg	    revision=$number_revision
9099dc407927Smrg	    ;;
91001a9c160aSmrg	  freebsd-aout|qnx|sunos)
91011a9c160aSmrg	    current=$number_major
91021a9c160aSmrg	    revision=$number_minor
91031a9c160aSmrg	    age=0
9104dc407927Smrg	    ;;
9105dc407927Smrg	  irix|nonstopux)
9106dc407927Smrg	    func_arith $number_major + $number_minor
9107dc407927Smrg	    current=$func_arith_result
91081a9c160aSmrg	    age=$number_minor
91091a9c160aSmrg	    revision=$number_minor
9110dc407927Smrg	    lt_irix_increment=no
9111dc407927Smrg	    ;;
9112dc407927Smrg	  esac
9113dc407927Smrg	  ;;
9114dc407927Smrg	no)
91151a9c160aSmrg	  current=$1
91161a9c160aSmrg	  revision=$2
91171a9c160aSmrg	  age=$3
9118dc407927Smrg	  ;;
9119dc407927Smrg	esac
9120dc407927Smrg
9121dc407927Smrg	# Check that each of the things are valid numbers.
9122dc407927Smrg	case $current in
9123dc407927Smrg	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]) ;;
9124dc407927Smrg	*)
91251a9c160aSmrg	  func_error "CURRENT '$current' must be a nonnegative integer"
91261a9c160aSmrg	  func_fatal_error "'$vinfo' is not valid version information"
9127dc407927Smrg	  ;;
9128dc407927Smrg	esac
9129dc407927Smrg
9130dc407927Smrg	case $revision in
9131dc407927Smrg	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]) ;;
9132dc407927Smrg	*)
91331a9c160aSmrg	  func_error "REVISION '$revision' must be a nonnegative integer"
91341a9c160aSmrg	  func_fatal_error "'$vinfo' is not valid version information"
9135dc407927Smrg	  ;;
9136dc407927Smrg	esac
9137dc407927Smrg
9138dc407927Smrg	case $age in
9139dc407927Smrg	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]) ;;
9140dc407927Smrg	*)
91411a9c160aSmrg	  func_error "AGE '$age' must be a nonnegative integer"
91421a9c160aSmrg	  func_fatal_error "'$vinfo' is not valid version information"
9143dc407927Smrg	  ;;
9144dc407927Smrg	esac
9145dc407927Smrg
9146dc407927Smrg	if test "$age" -gt "$current"; then
91471a9c160aSmrg	  func_error "AGE '$age' is greater than the current interface number '$current'"
91481a9c160aSmrg	  func_fatal_error "'$vinfo' is not valid version information"
9149dc407927Smrg	fi
9150dc407927Smrg
9151dc407927Smrg	# Calculate the version variables.
9152dc407927Smrg	major=
9153dc407927Smrg	versuffix=
9154dc407927Smrg	verstring=
9155dc407927Smrg	case $version_type in
9156dc407927Smrg	none) ;;
9157dc407927Smrg
9158dc407927Smrg	darwin)
9159dc407927Smrg	  # Like Linux, but with the current version available in
9160dc407927Smrg	  # verstring for coding it into the library header
9161dc407927Smrg	  func_arith $current - $age
9162dc407927Smrg	  major=.$func_arith_result
91631a9c160aSmrg	  versuffix=$major.$age.$revision
9164dc407927Smrg	  # Darwin ld doesn't like 0 for these options...
9165dc407927Smrg	  func_arith $current + 1
9166dc407927Smrg	  minor_current=$func_arith_result
91671a9c160aSmrg	  xlcverstring="$wl-compatibility_version $wl$minor_current $wl-current_version $wl$minor_current.$revision"
9168dc407927Smrg	  verstring="-compatibility_version $minor_current -current_version $minor_current.$revision"
91691a9c160aSmrg          # On Darwin other compilers
91701a9c160aSmrg          case $CC in
91711a9c160aSmrg              nagfor*)
91721a9c160aSmrg                  verstring="$wl-compatibility_version $wl$minor_current $wl-current_version $wl$minor_current.$revision"
91731a9c160aSmrg                  ;;
91741a9c160aSmrg              *)
91751a9c160aSmrg                  verstring="-compatibility_version $minor_current -current_version $minor_current.$revision"
91761a9c160aSmrg                  ;;
91771a9c160aSmrg          esac
9178dc407927Smrg	  ;;
9179dc407927Smrg
9180dc407927Smrg	freebsd-aout)
91811a9c160aSmrg	  major=.$current
91821a9c160aSmrg	  versuffix=.$current.$revision
9183dc407927Smrg	  ;;
9184dc407927Smrg
9185621f50c3Smrg	freebsd-elf | midnightbsd-elf)
91861a9c160aSmrg	  func_arith $current - $age
91871a9c160aSmrg	  major=.$func_arith_result
91881a9c160aSmrg	  versuffix=$major.$age.$revision
9189dc407927Smrg	  ;;
9190dc407927Smrg
9191dc407927Smrg	irix | nonstopux)
91921a9c160aSmrg	  if test no = "$lt_irix_increment"; then
9193dc407927Smrg	    func_arith $current - $age
9194dc407927Smrg	  else
9195dc407927Smrg	    func_arith $current - $age + 1
9196dc407927Smrg	  fi
9197dc407927Smrg	  major=$func_arith_result
9198dc407927Smrg
9199dc407927Smrg	  case $version_type in
9200dc407927Smrg	    nonstopux) verstring_prefix=nonstopux ;;
9201dc407927Smrg	    *)         verstring_prefix=sgi ;;
9202dc407927Smrg	  esac
92031a9c160aSmrg	  verstring=$verstring_prefix$major.$revision
9204dc407927Smrg
9205dc407927Smrg	  # Add in all the interfaces that we are compatible with.
9206dc407927Smrg	  loop=$revision
92071a9c160aSmrg	  while test 0 -ne "$loop"; do
9208dc407927Smrg	    func_arith $revision - $loop
9209dc407927Smrg	    iface=$func_arith_result
9210dc407927Smrg	    func_arith $loop - 1
9211dc407927Smrg	    loop=$func_arith_result
92121a9c160aSmrg	    verstring=$verstring_prefix$major.$iface:$verstring
9213dc407927Smrg	  done
9214dc407927Smrg
92151a9c160aSmrg	  # Before this point, $major must not contain '.'.
9216dc407927Smrg	  major=.$major
92171a9c160aSmrg	  versuffix=$major.$revision
9218dc407927Smrg	  ;;
9219dc407927Smrg
922075cbef56Smrg	linux) # correct to gnu/linux during the next big refactor
9221dc407927Smrg	  func_arith $current - $age
9222dc407927Smrg	  major=.$func_arith_result
92231a9c160aSmrg	  versuffix=$major.$age.$revision
9224dc407927Smrg	  ;;
9225dc407927Smrg
9226dc407927Smrg	osf)
9227dc407927Smrg	  func_arith $current - $age
9228dc407927Smrg	  major=.$func_arith_result
92291a9c160aSmrg	  versuffix=.$current.$age.$revision
92301a9c160aSmrg	  verstring=$current.$age.$revision
9231dc407927Smrg
9232dc407927Smrg	  # Add in all the interfaces that we are compatible with.
9233dc407927Smrg	  loop=$age
92341a9c160aSmrg	  while test 0 -ne "$loop"; do
9235dc407927Smrg	    func_arith $current - $loop
9236dc407927Smrg	    iface=$func_arith_result
9237dc407927Smrg	    func_arith $loop - 1
9238dc407927Smrg	    loop=$func_arith_result
92391a9c160aSmrg	    verstring=$verstring:$iface.0
9240dc407927Smrg	  done
9241dc407927Smrg
9242dc407927Smrg	  # Make executables depend on our current version.
92431a9c160aSmrg	  func_append verstring ":$current.0"
9244dc407927Smrg	  ;;
9245dc407927Smrg
9246dc407927Smrg	qnx)
92471a9c160aSmrg	  major=.$current
92481a9c160aSmrg	  versuffix=.$current
92491a9c160aSmrg	  ;;
92501a9c160aSmrg
92511a9c160aSmrg	sco)
92521a9c160aSmrg	  major=.$current
92531a9c160aSmrg	  versuffix=.$current
9254dc407927Smrg	  ;;
9255dc407927Smrg
9256dc407927Smrg	sunos)
92571a9c160aSmrg	  major=.$current
92581a9c160aSmrg	  versuffix=.$current.$revision
9259dc407927Smrg	  ;;
9260dc407927Smrg
9261dc407927Smrg	windows)
9262dc407927Smrg	  # Use '-' rather than '.', since we only want one
92631a9c160aSmrg	  # extension on DOS 8.3 file systems.
9264dc407927Smrg	  func_arith $current - $age
9265dc407927Smrg	  major=$func_arith_result
92661a9c160aSmrg	  versuffix=-$major
9267dc407927Smrg	  ;;
9268dc407927Smrg
9269dc407927Smrg	*)
92701a9c160aSmrg	  func_fatal_configuration "unknown library version type '$version_type'"
9271dc407927Smrg	  ;;
9272dc407927Smrg	esac
9273dc407927Smrg
9274dc407927Smrg	# Clear the version info if we defaulted, and they specified a release.
9275dc407927Smrg	if test -z "$vinfo" && test -n "$release"; then
9276dc407927Smrg	  major=
9277dc407927Smrg	  case $version_type in
9278dc407927Smrg	  darwin)
9279dc407927Smrg	    # we can't check for "0.0" in archive_cmds due to quoting
9280dc407927Smrg	    # problems, so we reset it completely
9281dc407927Smrg	    verstring=
9282dc407927Smrg	    ;;
9283dc407927Smrg	  *)
92841a9c160aSmrg	    verstring=0.0
9285dc407927Smrg	    ;;
9286dc407927Smrg	  esac
92871a9c160aSmrg	  if test no = "$need_version"; then
9288dc407927Smrg	    versuffix=
9289dc407927Smrg	  else
92901a9c160aSmrg	    versuffix=.0.0
9291dc407927Smrg	  fi
9292dc407927Smrg	fi
9293dc407927Smrg
9294dc407927Smrg	# Remove version info from name if versioning should be avoided
92951a9c160aSmrg	if test yes,no = "$avoid_version,$need_version"; then
9296dc407927Smrg	  major=
9297dc407927Smrg	  versuffix=
92981a9c160aSmrg	  verstring=
9299dc407927Smrg	fi
9300dc407927Smrg
9301dc407927Smrg	# Check to see if the archive will have undefined symbols.
93021a9c160aSmrg	if test yes = "$allow_undefined"; then
93031a9c160aSmrg	  if test unsupported = "$allow_undefined_flag"; then
93041a9c160aSmrg	    if test yes = "$build_old_libs"; then
93051a9c160aSmrg	      func_warning "undefined symbols not allowed in $host shared libraries; building static only"
93061a9c160aSmrg	      build_libtool_libs=no
93071a9c160aSmrg	    else
93081a9c160aSmrg	      func_fatal_error "can't build $host shared library unless -no-undefined is specified"
93091a9c160aSmrg	    fi
9310dc407927Smrg	  fi
9311dc407927Smrg	else
9312dc407927Smrg	  # Don't allow undefined symbols.
93131a9c160aSmrg	  allow_undefined_flag=$no_undefined_flag
9314dc407927Smrg	fi
9315dc407927Smrg
9316dc407927Smrg      fi
9317dc407927Smrg
93181a9c160aSmrg      func_generate_dlsyms "$libname" "$libname" :
9319dd0822caSmrg      func_append libobjs " $symfileobj"
93201a9c160aSmrg      test " " = "$libobjs" && libobjs=
9321dc407927Smrg
93221a9c160aSmrg      if test relink != "$opt_mode"; then
9323dc407927Smrg	# Remove our outputs, but don't remove object files since they
9324dc407927Smrg	# may have been created when compiling PIC objects.
9325dc407927Smrg	removelist=
9326dc407927Smrg	tempremovelist=`$ECHO "$output_objdir/*"`
9327dc407927Smrg	for p in $tempremovelist; do
9328dc407927Smrg	  case $p in
9329dc407927Smrg	    *.$objext | *.gcno)
9330dc407927Smrg	       ;;
93311a9c160aSmrg	    $output_objdir/$outputname | $output_objdir/$libname.* | $output_objdir/$libname$release.*)
93321a9c160aSmrg	       if test -n "$precious_files_regex"; then
9333dc407927Smrg		 if $ECHO "$p" | $EGREP -e "$precious_files_regex" >/dev/null 2>&1
9334dc407927Smrg		 then
9335dc407927Smrg		   continue
9336dc407927Smrg		 fi
9337dc407927Smrg	       fi
9338dd0822caSmrg	       func_append removelist " $p"
9339dc407927Smrg	       ;;
9340dc407927Smrg	    *) ;;
9341dc407927Smrg	  esac
9342dc407927Smrg	done
9343dc407927Smrg	test -n "$removelist" && \
9344dc407927Smrg	  func_show_eval "${RM}r \$removelist"
9345dc407927Smrg      fi
9346dc407927Smrg
9347dc407927Smrg      # Now set the variables for building old libraries.
93481a9c160aSmrg      if test yes = "$build_old_libs" && test convenience != "$build_libtool_libs"; then
9349dd0822caSmrg	func_append oldlibs " $output_objdir/$libname.$libext"
9350dc407927Smrg
9351dc407927Smrg	# Transform .lo files to .o files.
93521a9c160aSmrg	oldobjs="$objs "`$ECHO "$libobjs" | $SP2NL | $SED "/\.$libext$/d; $lo2o" | $NL2SP`
9353dc407927Smrg      fi
9354dc407927Smrg
9355dc407927Smrg      # Eliminate all temporary directories.
9356dc407927Smrg      #for path in $notinst_path; do
9357dd0822caSmrg      #	lib_search_path=`$ECHO "$lib_search_path " | $SED "s% $path % %g"`
9358dd0822caSmrg      #	deplibs=`$ECHO "$deplibs " | $SED "s% -L$path % %g"`
9359dd0822caSmrg      #	dependency_libs=`$ECHO "$dependency_libs " | $SED "s% -L$path % %g"`
9360dc407927Smrg      #done
9361dc407927Smrg
9362dc407927Smrg      if test -n "$xrpath"; then
9363dc407927Smrg	# If the user specified any rpath flags, then add them.
9364dc407927Smrg	temp_xrpath=
9365dc407927Smrg	for libdir in $xrpath; do
9366dd0822caSmrg	  func_replace_sysroot "$libdir"
9367dd0822caSmrg	  func_append temp_xrpath " -R$func_replace_sysroot_result"
9368dc407927Smrg	  case "$finalize_rpath " in
9369dc407927Smrg	  *" $libdir "*) ;;
9370dd0822caSmrg	  *) func_append finalize_rpath " $libdir" ;;
9371dc407927Smrg	  esac
9372dc407927Smrg	done
93731a9c160aSmrg	if test yes != "$hardcode_into_libs" || test yes = "$build_old_libs"; then
9374dc407927Smrg	  dependency_libs="$temp_xrpath $dependency_libs"
9375dc407927Smrg	fi
9376dc407927Smrg      fi
9377dc407927Smrg
9378dc407927Smrg      # Make sure dlfiles contains only unique files that won't be dlpreopened
93791a9c160aSmrg      old_dlfiles=$dlfiles
9380dc407927Smrg      dlfiles=
9381dc407927Smrg      for lib in $old_dlfiles; do
9382dc407927Smrg	case " $dlprefiles $dlfiles " in
9383dc407927Smrg	*" $lib "*) ;;
9384dd0822caSmrg	*) func_append dlfiles " $lib" ;;
9385dc407927Smrg	esac
9386dc407927Smrg      done
9387dc407927Smrg
9388dc407927Smrg      # Make sure dlprefiles contains only unique files
93891a9c160aSmrg      old_dlprefiles=$dlprefiles
9390dc407927Smrg      dlprefiles=
9391dc407927Smrg      for lib in $old_dlprefiles; do
9392dc407927Smrg	case "$dlprefiles " in
9393dc407927Smrg	*" $lib "*) ;;
9394dd0822caSmrg	*) func_append dlprefiles " $lib" ;;
9395dc407927Smrg	esac
9396dc407927Smrg      done
9397dc407927Smrg
93981a9c160aSmrg      if test yes = "$build_libtool_libs"; then
9399dc407927Smrg	if test -n "$rpath"; then
9400dc407927Smrg	  case $host in
9401dd0822caSmrg	  *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-beos* | *-cegcc* | *-*-haiku*)
9402dc407927Smrg	    # these systems don't actually have a c library (as such)!
9403dc407927Smrg	    ;;
9404dc407927Smrg	  *-*-rhapsody* | *-*-darwin1.[012])
9405dc407927Smrg	    # Rhapsody C library is in the System framework
9406dd0822caSmrg	    func_append deplibs " System.ltframework"
9407dc407927Smrg	    ;;
9408dc407927Smrg	  *-*-netbsd*)
9409dc407927Smrg	    # Don't link with libc until the a.out ld.so is fixed.
9410dc407927Smrg	    ;;
9411621f50c3Smrg	  *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-midnightbsd*)
9412dc407927Smrg	    # Do not include libc due to us having libc/libc_r.
9413dc407927Smrg	    ;;
9414dc407927Smrg	  *-*-sco3.2v5* | *-*-sco5v6*)
9415dc407927Smrg	    # Causes problems with __ctype
9416dc407927Smrg	    ;;
9417dc407927Smrg	  *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*)
9418dc407927Smrg	    # Compiler inserts libc in the correct place for threads to work
9419dc407927Smrg	    ;;
9420dc407927Smrg	  *)
9421dc407927Smrg	    # Add libc to deplibs on all other systems if necessary.
94221a9c160aSmrg	    if test yes = "$build_libtool_need_lc"; then
9423dd0822caSmrg	      func_append deplibs " -lc"
9424dc407927Smrg	    fi
9425dc407927Smrg	    ;;
9426dc407927Smrg	  esac
9427dc407927Smrg	fi
9428dc407927Smrg
9429dc407927Smrg	# Transform deplibs into only deplibs that can be linked in shared.
9430dc407927Smrg	name_save=$name
9431dc407927Smrg	libname_save=$libname
9432dc407927Smrg	release_save=$release
9433dc407927Smrg	versuffix_save=$versuffix
9434dc407927Smrg	major_save=$major
9435dc407927Smrg	# I'm not sure if I'm treating the release correctly.  I think
9436dc407927Smrg	# release should show up in the -l (ie -lgmp5) so we don't want to
9437dc407927Smrg	# add it in twice.  Is that correct?
94381a9c160aSmrg	release=
94391a9c160aSmrg	versuffix=
94401a9c160aSmrg	major=
9441dc407927Smrg	newdeplibs=
9442dc407927Smrg	droppeddeps=no
9443dc407927Smrg	case $deplibs_check_method in
9444dc407927Smrg	pass_all)
9445dc407927Smrg	  # Don't check for shared/static.  Everything works.
9446dc407927Smrg	  # This might be a little naive.  We might want to check
9447dc407927Smrg	  # whether the library exists or not.  But this is on
9448dc407927Smrg	  # osf3 & osf4 and I'm not really sure... Just
9449dc407927Smrg	  # implementing what was already the behavior.
9450dc407927Smrg	  newdeplibs=$deplibs
9451dc407927Smrg	  ;;
9452dc407927Smrg	test_compile)
9453dc407927Smrg	  # This code stresses the "libraries are programs" paradigm to its
9454dc407927Smrg	  # limits. Maybe even breaks it.  We compile a program, linking it
9455dc407927Smrg	  # against the deplibs as a proxy for the library.  Then we can check
9456dc407927Smrg	  # whether they linked in statically or dynamically with ldd.
9457dc407927Smrg	  $opt_dry_run || $RM conftest.c
9458dc407927Smrg	  cat > conftest.c <<EOF
9459dc407927Smrg	  int main() { return 0; }
9460dc407927SmrgEOF
9461dc407927Smrg	  $opt_dry_run || $RM conftest
9462dc407927Smrg	  if $LTCC $LTCFLAGS -o conftest conftest.c $deplibs; then
9463dc407927Smrg	    ldd_output=`ldd conftest`
9464dc407927Smrg	    for i in $deplibs; do
9465dc407927Smrg	      case $i in
9466dc407927Smrg	      -l*)
9467dc407927Smrg		func_stripname -l '' "$i"
9468dc407927Smrg		name=$func_stripname_result
94691a9c160aSmrg		if test yes = "$allow_libtool_libs_with_static_runtimes"; then
9470dc407927Smrg		  case " $predeps $postdeps " in
9471dc407927Smrg		  *" $i "*)
9472dd0822caSmrg		    func_append newdeplibs " $i"
94731a9c160aSmrg		    i=
9474dc407927Smrg		    ;;
9475dc407927Smrg		  esac
9476dc407927Smrg		fi
94771a9c160aSmrg		if test -n "$i"; then
9478dc407927Smrg		  libname=`eval "\\$ECHO \"$libname_spec\""`
9479dc407927Smrg		  deplib_matches=`eval "\\$ECHO \"$library_names_spec\""`
9480dc407927Smrg		  set dummy $deplib_matches; shift
9481dc407927Smrg		  deplib_match=$1
94821a9c160aSmrg		  if test `expr "$ldd_output" : ".*$deplib_match"` -ne 0; then
9483dd0822caSmrg		    func_append newdeplibs " $i"
9484dc407927Smrg		  else
9485dc407927Smrg		    droppeddeps=yes
9486dd0822caSmrg		    echo
9487dc407927Smrg		    $ECHO "*** Warning: dynamic linker does not accept needed library $i."
9488dd0822caSmrg		    echo "*** I have the capability to make that library automatically link in when"
9489dd0822caSmrg		    echo "*** you link to this library.  But I can only do this if you have a"
9490dd0822caSmrg		    echo "*** shared version of the library, which I believe you do not have"
9491dd0822caSmrg		    echo "*** because a test_compile did reveal that the linker did not use it for"
9492dd0822caSmrg		    echo "*** its dynamic dependency list that programs get resolved with at runtime."
9493dc407927Smrg		  fi
9494dc407927Smrg		fi
9495dc407927Smrg		;;
9496dc407927Smrg	      *)
9497dd0822caSmrg		func_append newdeplibs " $i"
9498dc407927Smrg		;;
9499dc407927Smrg	      esac
9500dc407927Smrg	    done
9501dc407927Smrg	  else
9502dc407927Smrg	    # Error occurred in the first compile.  Let's try to salvage
9503dc407927Smrg	    # the situation: Compile a separate program for each library.
9504dc407927Smrg	    for i in $deplibs; do
9505dc407927Smrg	      case $i in
9506dc407927Smrg	      -l*)
9507dc407927Smrg		func_stripname -l '' "$i"
9508dc407927Smrg		name=$func_stripname_result
9509dc407927Smrg		$opt_dry_run || $RM conftest
9510dc407927Smrg		if $LTCC $LTCFLAGS -o conftest conftest.c $i; then
9511dc407927Smrg		  ldd_output=`ldd conftest`
95121a9c160aSmrg		  if test yes = "$allow_libtool_libs_with_static_runtimes"; then
9513dc407927Smrg		    case " $predeps $postdeps " in
9514dc407927Smrg		    *" $i "*)
9515dd0822caSmrg		      func_append newdeplibs " $i"
95161a9c160aSmrg		      i=
9517dc407927Smrg		      ;;
9518dc407927Smrg		    esac
9519dc407927Smrg		  fi
95201a9c160aSmrg		  if test -n "$i"; then
9521dc407927Smrg		    libname=`eval "\\$ECHO \"$libname_spec\""`
9522dc407927Smrg		    deplib_matches=`eval "\\$ECHO \"$library_names_spec\""`
9523dc407927Smrg		    set dummy $deplib_matches; shift
9524dc407927Smrg		    deplib_match=$1
95251a9c160aSmrg		    if test `expr "$ldd_output" : ".*$deplib_match"` -ne 0; then
9526dd0822caSmrg		      func_append newdeplibs " $i"
9527dc407927Smrg		    else
9528dc407927Smrg		      droppeddeps=yes
9529dd0822caSmrg		      echo
9530dc407927Smrg		      $ECHO "*** Warning: dynamic linker does not accept needed library $i."
9531dd0822caSmrg		      echo "*** I have the capability to make that library automatically link in when"
9532dd0822caSmrg		      echo "*** you link to this library.  But I can only do this if you have a"
9533dd0822caSmrg		      echo "*** shared version of the library, which you do not appear to have"
9534dd0822caSmrg		      echo "*** because a test_compile did reveal that the linker did not use this one"
9535dd0822caSmrg		      echo "*** as a dynamic dependency that programs can get resolved with at runtime."
9536dc407927Smrg		    fi
9537dc407927Smrg		  fi
9538dc407927Smrg		else
9539dc407927Smrg		  droppeddeps=yes
9540dd0822caSmrg		  echo
9541dc407927Smrg		  $ECHO "*** Warning!  Library $i is needed by this library but I was not able to"
9542dd0822caSmrg		  echo "*** make it link in!  You will probably need to install it or some"
9543dd0822caSmrg		  echo "*** library that it depends on before this library will be fully"
9544dd0822caSmrg		  echo "*** functional.  Installing it before continuing would be even better."
9545dc407927Smrg		fi
9546dc407927Smrg		;;
9547dc407927Smrg	      *)
9548dd0822caSmrg		func_append newdeplibs " $i"
9549dc407927Smrg		;;
9550dc407927Smrg	      esac
9551dc407927Smrg	    done
9552dc407927Smrg	  fi
9553dc407927Smrg	  ;;
9554dc407927Smrg	file_magic*)
9555dc407927Smrg	  set dummy $deplibs_check_method; shift
9556dc407927Smrg	  file_magic_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
9557dc407927Smrg	  for a_deplib in $deplibs; do
9558dc407927Smrg	    case $a_deplib in
9559dc407927Smrg	    -l*)
9560dc407927Smrg	      func_stripname -l '' "$a_deplib"
9561dc407927Smrg	      name=$func_stripname_result
95621a9c160aSmrg	      if test yes = "$allow_libtool_libs_with_static_runtimes"; then
9563dc407927Smrg		case " $predeps $postdeps " in
9564dc407927Smrg		*" $a_deplib "*)
9565dd0822caSmrg		  func_append newdeplibs " $a_deplib"
95661a9c160aSmrg		  a_deplib=
9567dc407927Smrg		  ;;
9568dc407927Smrg		esac
9569dc407927Smrg	      fi
95701a9c160aSmrg	      if test -n "$a_deplib"; then
9571dc407927Smrg		libname=`eval "\\$ECHO \"$libname_spec\""`
9572dd0822caSmrg		if test -n "$file_magic_glob"; then
9573dd0822caSmrg		  libnameglob=`func_echo_all "$libname" | $SED -e $file_magic_glob`
9574dd0822caSmrg		else
9575dd0822caSmrg		  libnameglob=$libname
9576dd0822caSmrg		fi
95771a9c160aSmrg		test yes = "$want_nocaseglob" && nocaseglob=`shopt -p nocaseglob`
9578dc407927Smrg		for i in $lib_search_path $sys_lib_search_path $shlib_search_path; do
95791a9c160aSmrg		  if test yes = "$want_nocaseglob"; then
9580dd0822caSmrg		    shopt -s nocaseglob
9581dd0822caSmrg		    potential_libs=`ls $i/$libnameglob[.-]* 2>/dev/null`
9582dd0822caSmrg		    $nocaseglob
9583dd0822caSmrg		  else
9584dd0822caSmrg		    potential_libs=`ls $i/$libnameglob[.-]* 2>/dev/null`
9585dd0822caSmrg		  fi
9586dc407927Smrg		  for potent_lib in $potential_libs; do
9587dc407927Smrg		      # Follow soft links.
9588dc407927Smrg		      if ls -lLd "$potent_lib" 2>/dev/null |
9589dc407927Smrg			 $GREP " -> " >/dev/null; then
9590dc407927Smrg			continue
9591dc407927Smrg		      fi
9592dc407927Smrg		      # The statement above tries to avoid entering an
9593dc407927Smrg		      # endless loop below, in case of cyclic links.
9594dc407927Smrg		      # We might still enter an endless loop, since a link
9595dc407927Smrg		      # loop can be closed while we follow links,
9596dc407927Smrg		      # but so what?
95971a9c160aSmrg		      potlib=$potent_lib
9598dc407927Smrg		      while test -h "$potlib" 2>/dev/null; do
95991a9c160aSmrg			potliblink=`ls -ld $potlib | $SED 's/.* -> //'`
9600dc407927Smrg			case $potliblink in
96011a9c160aSmrg			[\\/]* | [A-Za-z]:[\\/]*) potlib=$potliblink;;
96021a9c160aSmrg			*) potlib=`$ECHO "$potlib" | $SED 's|[^/]*$||'`"$potliblink";;
9603dc407927Smrg			esac
9604dc407927Smrg		      done
9605dc407927Smrg		      if eval $file_magic_cmd \"\$potlib\" 2>/dev/null |
9606dc407927Smrg			 $SED -e 10q |
9607dc407927Smrg			 $EGREP "$file_magic_regex" > /dev/null; then
9608dd0822caSmrg			func_append newdeplibs " $a_deplib"
96091a9c160aSmrg			a_deplib=
9610dc407927Smrg			break 2
9611dc407927Smrg		      fi
9612dc407927Smrg		  done
9613dc407927Smrg		done
9614dc407927Smrg	      fi
96151a9c160aSmrg	      if test -n "$a_deplib"; then
9616dc407927Smrg		droppeddeps=yes
9617dd0822caSmrg		echo
9618dc407927Smrg		$ECHO "*** Warning: linker path does not have real file for library $a_deplib."
9619dd0822caSmrg		echo "*** I have the capability to make that library automatically link in when"
9620dd0822caSmrg		echo "*** you link to this library.  But I can only do this if you have a"
9621dd0822caSmrg		echo "*** shared version of the library, which you do not appear to have"
9622dd0822caSmrg		echo "*** because I did check the linker path looking for a file starting"
96231a9c160aSmrg		if test -z "$potlib"; then
9624dc407927Smrg		  $ECHO "*** with $libname but no candidates were found. (...for file magic test)"
9625dc407927Smrg		else
9626dc407927Smrg		  $ECHO "*** with $libname and none of the candidates passed a file format test"
9627dc407927Smrg		  $ECHO "*** using a file magic. Last file checked: $potlib"
9628dc407927Smrg		fi
9629dc407927Smrg	      fi
9630dc407927Smrg	      ;;
9631dc407927Smrg	    *)
9632dc407927Smrg	      # Add a -L argument.
9633dd0822caSmrg	      func_append newdeplibs " $a_deplib"
9634dc407927Smrg	      ;;
9635dc407927Smrg	    esac
9636dc407927Smrg	  done # Gone through all deplibs.
9637dc407927Smrg	  ;;
9638dc407927Smrg	match_pattern*)
9639dc407927Smrg	  set dummy $deplibs_check_method; shift
9640dc407927Smrg	  match_pattern_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
9641dc407927Smrg	  for a_deplib in $deplibs; do
9642dc407927Smrg	    case $a_deplib in
9643dc407927Smrg	    -l*)
9644dc407927Smrg	      func_stripname -l '' "$a_deplib"
9645dc407927Smrg	      name=$func_stripname_result
96461a9c160aSmrg	      if test yes = "$allow_libtool_libs_with_static_runtimes"; then
9647dc407927Smrg		case " $predeps $postdeps " in
9648dc407927Smrg		*" $a_deplib "*)
9649dd0822caSmrg		  func_append newdeplibs " $a_deplib"
96501a9c160aSmrg		  a_deplib=
9651dc407927Smrg		  ;;
9652dc407927Smrg		esac
9653dc407927Smrg	      fi
96541a9c160aSmrg	      if test -n "$a_deplib"; then
9655dc407927Smrg		libname=`eval "\\$ECHO \"$libname_spec\""`
9656dc407927Smrg		for i in $lib_search_path $sys_lib_search_path $shlib_search_path; do
9657dc407927Smrg		  potential_libs=`ls $i/$libname[.-]* 2>/dev/null`
9658dc407927Smrg		  for potent_lib in $potential_libs; do
96591a9c160aSmrg		    potlib=$potent_lib # see symlink-check above in file_magic test
9660dd0822caSmrg		    if eval "\$ECHO \"$potent_lib\"" 2>/dev/null | $SED 10q | \
9661dc407927Smrg		       $EGREP "$match_pattern_regex" > /dev/null; then
9662dd0822caSmrg		      func_append newdeplibs " $a_deplib"
96631a9c160aSmrg		      a_deplib=
9664dc407927Smrg		      break 2
9665dc407927Smrg		    fi
9666dc407927Smrg		  done
9667dc407927Smrg		done
9668dc407927Smrg	      fi
96691a9c160aSmrg	      if test -n "$a_deplib"; then
9670dc407927Smrg		droppeddeps=yes
9671dd0822caSmrg		echo
9672dc407927Smrg		$ECHO "*** Warning: linker path does not have real file for library $a_deplib."
9673dd0822caSmrg		echo "*** I have the capability to make that library automatically link in when"
9674dd0822caSmrg		echo "*** you link to this library.  But I can only do this if you have a"
9675dd0822caSmrg		echo "*** shared version of the library, which you do not appear to have"
9676dd0822caSmrg		echo "*** because I did check the linker path looking for a file starting"
96771a9c160aSmrg		if test -z "$potlib"; then
9678dc407927Smrg		  $ECHO "*** with $libname but no candidates were found. (...for regex pattern test)"
9679dc407927Smrg		else
9680dc407927Smrg		  $ECHO "*** with $libname and none of the candidates passed a file format test"
9681dc407927Smrg		  $ECHO "*** using a regex pattern. Last file checked: $potlib"
9682dc407927Smrg		fi
9683dc407927Smrg	      fi
9684dc407927Smrg	      ;;
9685dc407927Smrg	    *)
9686dc407927Smrg	      # Add a -L argument.
9687dd0822caSmrg	      func_append newdeplibs " $a_deplib"
9688dc407927Smrg	      ;;
9689dc407927Smrg	    esac
9690dc407927Smrg	  done # Gone through all deplibs.
9691dc407927Smrg	  ;;
9692dc407927Smrg	none | unknown | *)
96931a9c160aSmrg	  newdeplibs=
9694dd0822caSmrg	  tmp_deplibs=`$ECHO " $deplibs" | $SED 's/ -lc$//; s/ -[LR][^ ]*//g'`
96951a9c160aSmrg	  if test yes = "$allow_libtool_libs_with_static_runtimes"; then
96961a9c160aSmrg	    for i in $predeps $postdeps; do
9697dc407927Smrg	      # can't use Xsed below, because $i might contain '/'
96981a9c160aSmrg	      tmp_deplibs=`$ECHO " $tmp_deplibs" | $SED "s|$i||"`
9699dc407927Smrg	    done
9700dc407927Smrg	  fi
9701dd0822caSmrg	  case $tmp_deplibs in
9702dd0822caSmrg	  *[!\	\ ]*)
9703dd0822caSmrg	    echo
97041a9c160aSmrg	    if test none = "$deplibs_check_method"; then
9705dd0822caSmrg	      echo "*** Warning: inter-library dependencies are not supported in this platform."
9706dc407927Smrg	    else
9707dd0822caSmrg	      echo "*** Warning: inter-library dependencies are not known to be supported."
9708dc407927Smrg	    fi
9709dd0822caSmrg	    echo "*** All declared inter-library dependencies are being dropped."
9710dc407927Smrg	    droppeddeps=yes
9711dd0822caSmrg	    ;;
9712dd0822caSmrg	  esac
9713dc407927Smrg	  ;;
9714dc407927Smrg	esac
9715dc407927Smrg	versuffix=$versuffix_save
9716dc407927Smrg	major=$major_save
9717dc407927Smrg	release=$release_save
9718dc407927Smrg	libname=$libname_save
9719dc407927Smrg	name=$name_save
9720dc407927Smrg
9721dc407927Smrg	case $host in
9722dc407927Smrg	*-*-rhapsody* | *-*-darwin1.[012])
9723dc407927Smrg	  # On Rhapsody replace the C library with the System framework
9724dd0822caSmrg	  newdeplibs=`$ECHO " $newdeplibs" | $SED 's/ -lc / System.ltframework /'`
9725dc407927Smrg	  ;;
9726dc407927Smrg	esac
9727dc407927Smrg
97281a9c160aSmrg	if test yes = "$droppeddeps"; then
97291a9c160aSmrg	  if test yes = "$module"; then
9730dd0822caSmrg	    echo
9731dd0822caSmrg	    echo "*** Warning: libtool could not satisfy all declared inter-library"
9732dc407927Smrg	    $ECHO "*** dependencies of module $libname.  Therefore, libtool will create"
9733dd0822caSmrg	    echo "*** a static module, that should work as long as the dlopening"
9734dd0822caSmrg	    echo "*** application is linked with the -dlopen flag."
9735dc407927Smrg	    if test -z "$global_symbol_pipe"; then
9736dd0822caSmrg	      echo
9737dd0822caSmrg	      echo "*** However, this would only work if libtool was able to extract symbol"
97381a9c160aSmrg	      echo "*** lists from a program, using 'nm' or equivalent, but libtool could"
9739dd0822caSmrg	      echo "*** not find such a program.  So, this module is probably useless."
97401a9c160aSmrg	      echo "*** 'nm' from GNU binutils and a full rebuild may help."
9741dc407927Smrg	    fi
97421a9c160aSmrg	    if test no = "$build_old_libs"; then
97431a9c160aSmrg	      oldlibs=$output_objdir/$libname.$libext
9744dc407927Smrg	      build_libtool_libs=module
9745dc407927Smrg	      build_old_libs=yes
9746dc407927Smrg	    else
9747dc407927Smrg	      build_libtool_libs=no
9748dc407927Smrg	    fi
9749dc407927Smrg	  else
9750dd0822caSmrg	    echo "*** The inter-library dependencies that have been dropped here will be"
9751dd0822caSmrg	    echo "*** automatically added whenever a program is linked with this library"
9752dd0822caSmrg	    echo "*** or is declared to -dlopen it."
9753dc407927Smrg
97541a9c160aSmrg	    if test no = "$allow_undefined"; then
9755dd0822caSmrg	      echo
9756dd0822caSmrg	      echo "*** Since this library must not contain undefined symbols,"
9757dd0822caSmrg	      echo "*** because either the platform does not support them or"
9758dd0822caSmrg	      echo "*** it was explicitly requested with -no-undefined,"
9759dd0822caSmrg	      echo "*** libtool will only create a static version of it."
97601a9c160aSmrg	      if test no = "$build_old_libs"; then
97611a9c160aSmrg		oldlibs=$output_objdir/$libname.$libext
9762dc407927Smrg		build_libtool_libs=module
9763dc407927Smrg		build_old_libs=yes
9764dc407927Smrg	      else
9765dc407927Smrg		build_libtool_libs=no
9766dc407927Smrg	      fi
9767dc407927Smrg	    fi
9768dc407927Smrg	  fi
9769dc407927Smrg	fi
9770dc407927Smrg	# Done checking deplibs!
9771dc407927Smrg	deplibs=$newdeplibs
9772dc407927Smrg      fi
9773dc407927Smrg      # Time to change all our "foo.ltframework" stuff back to "-framework foo"
9774dc407927Smrg      case $host in
9775dc407927Smrg	*-*-darwin*)
9776dd0822caSmrg	  newdeplibs=`$ECHO " $newdeplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
9777dd0822caSmrg	  new_inherited_linker_flags=`$ECHO " $new_inherited_linker_flags" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
9778dd0822caSmrg	  deplibs=`$ECHO " $deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
9779dc407927Smrg	  ;;
9780dc407927Smrg      esac
9781dc407927Smrg
9782dc407927Smrg      # move library search paths that coincide with paths to not yet
9783dc407927Smrg      # installed libraries to the beginning of the library search list
9784dc407927Smrg      new_libs=
9785dc407927Smrg      for path in $notinst_path; do
9786dc407927Smrg	case " $new_libs " in
9787dc407927Smrg	*" -L$path/$objdir "*) ;;
9788dc407927Smrg	*)
9789dc407927Smrg	  case " $deplibs " in
9790dc407927Smrg	  *" -L$path/$objdir "*)
9791dd0822caSmrg	    func_append new_libs " -L$path/$objdir" ;;
9792dc407927Smrg	  esac
9793dc407927Smrg	  ;;
9794dc407927Smrg	esac
9795dc407927Smrg      done
9796dc407927Smrg      for deplib in $deplibs; do
9797dc407927Smrg	case $deplib in
9798dc407927Smrg	-L*)
9799dc407927Smrg	  case " $new_libs " in
9800dc407927Smrg	  *" $deplib "*) ;;
9801dd0822caSmrg	  *) func_append new_libs " $deplib" ;;
9802dc407927Smrg	  esac
9803dc407927Smrg	  ;;
9804dd0822caSmrg	*) func_append new_libs " $deplib" ;;
9805dc407927Smrg	esac
9806dc407927Smrg      done
98071a9c160aSmrg      deplibs=$new_libs
9808dc407927Smrg
9809dc407927Smrg      # All the library-specific variables (install_libdir is set above).
9810dc407927Smrg      library_names=
9811dc407927Smrg      old_library=
9812dc407927Smrg      dlname=
9813dc407927Smrg
9814dc407927Smrg      # Test again, we may have decided not to build it any more
98151a9c160aSmrg      if test yes = "$build_libtool_libs"; then
98161a9c160aSmrg	# Remove $wl instances when linking with ld.
981775cbef56Smrg	# FIXME: should test the right _cmds variable.
981875cbef56Smrg	case $archive_cmds in
981975cbef56Smrg	  *\$LD\ *) wl= ;;
982075cbef56Smrg        esac
98211a9c160aSmrg	if test yes = "$hardcode_into_libs"; then
9822dc407927Smrg	  # Hardcode the library paths
9823dc407927Smrg	  hardcode_libdirs=
9824dc407927Smrg	  dep_rpath=
98251a9c160aSmrg	  rpath=$finalize_rpath
98261a9c160aSmrg	  test relink = "$opt_mode" || rpath=$compile_rpath$rpath
9827dc407927Smrg	  for libdir in $rpath; do
9828dc407927Smrg	    if test -n "$hardcode_libdir_flag_spec"; then
9829dc407927Smrg	      if test -n "$hardcode_libdir_separator"; then
9830dd0822caSmrg		func_replace_sysroot "$libdir"
9831dd0822caSmrg		libdir=$func_replace_sysroot_result
9832dc407927Smrg		if test -z "$hardcode_libdirs"; then
98331a9c160aSmrg		  hardcode_libdirs=$libdir
9834dc407927Smrg		else
9835dc407927Smrg		  # Just accumulate the unique libdirs.
9836dc407927Smrg		  case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
9837dc407927Smrg		  *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
9838dc407927Smrg		    ;;
9839dc407927Smrg		  *)
9840dd0822caSmrg		    func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
9841dc407927Smrg		    ;;
9842dc407927Smrg		  esac
9843dc407927Smrg		fi
9844dc407927Smrg	      else
9845dc407927Smrg		eval flag=\"$hardcode_libdir_flag_spec\"
9846dd0822caSmrg		func_append dep_rpath " $flag"
9847dc407927Smrg	      fi
9848dc407927Smrg	    elif test -n "$runpath_var"; then
9849dc407927Smrg	      case "$perm_rpath " in
9850dc407927Smrg	      *" $libdir "*) ;;
985175cbef56Smrg	      *) func_append perm_rpath " $libdir" ;;
9852dc407927Smrg	      esac
9853dc407927Smrg	    fi
9854dc407927Smrg	  done
9855dc407927Smrg	  # Substitute the hardcoded libdirs into the rpath.
9856dc407927Smrg	  if test -n "$hardcode_libdir_separator" &&
9857dc407927Smrg	     test -n "$hardcode_libdirs"; then
98581a9c160aSmrg	    libdir=$hardcode_libdirs
985975cbef56Smrg	    eval "dep_rpath=\"$hardcode_libdir_flag_spec\""
9860dc407927Smrg	  fi
9861dc407927Smrg	  if test -n "$runpath_var" && test -n "$perm_rpath"; then
9862dc407927Smrg	    # We should set the runpath_var.
9863dc407927Smrg	    rpath=
9864dc407927Smrg	    for dir in $perm_rpath; do
9865dd0822caSmrg	      func_append rpath "$dir:"
9866dc407927Smrg	    done
9867dc407927Smrg	    eval "$runpath_var='$rpath\$$runpath_var'; export $runpath_var"
9868dc407927Smrg	  fi
9869dc407927Smrg	  test -n "$dep_rpath" && deplibs="$dep_rpath $deplibs"
9870dc407927Smrg	fi
98713eed67faSmbalmer
98721a9c160aSmrg	shlibpath=$finalize_shlibpath
98731a9c160aSmrg	test relink = "$opt_mode" || shlibpath=$compile_shlibpath$shlibpath
9874dc407927Smrg	if test -n "$shlibpath"; then
9875dc407927Smrg	  eval "$shlibpath_var='$shlibpath\$$shlibpath_var'; export $shlibpath_var"
9876dc407927Smrg	fi
98773eed67faSmbalmer
9878dc407927Smrg	# Get the real and link names of the library.
9879dc407927Smrg	eval shared_ext=\"$shrext_cmds\"
9880dc407927Smrg	eval library_names=\"$library_names_spec\"
9881dc407927Smrg	set dummy $library_names
9882dc407927Smrg	shift
98831a9c160aSmrg	realname=$1
9884dc407927Smrg	shift
98853eed67faSmbalmer
9886dc407927Smrg	if test -n "$soname_spec"; then
9887dc407927Smrg	  eval soname=\"$soname_spec\"
9888dc407927Smrg	else
98891a9c160aSmrg	  soname=$realname
9890dc407927Smrg	fi
9891dc407927Smrg	if test -z "$dlname"; then
9892dc407927Smrg	  dlname=$soname
9893dc407927Smrg	fi
98943eed67faSmbalmer
98951a9c160aSmrg	lib=$output_objdir/$realname
9896dc407927Smrg	linknames=
9897dc407927Smrg	for link
9898dc407927Smrg	do
9899dd0822caSmrg	  func_append linknames " $link"
9900dc407927Smrg	done
99013eed67faSmbalmer
9902dc407927Smrg	# Use standard objects if they are pic
9903dd0822caSmrg	test -z "$pic_flag" && libobjs=`$ECHO "$libobjs" | $SP2NL | $SED "$lo2o" | $NL2SP`
9904dc407927Smrg	test "X$libobjs" = "X " && libobjs=
99053eed67faSmbalmer
9906dc407927Smrg	delfiles=
9907dc407927Smrg	if test -n "$export_symbols" && test -n "$include_expsyms"; then
9908dc407927Smrg	  $opt_dry_run || cp "$export_symbols" "$output_objdir/$libname.uexp"
99091a9c160aSmrg	  export_symbols=$output_objdir/$libname.uexp
9910dd0822caSmrg	  func_append delfiles " $export_symbols"
9911dc407927Smrg	fi
99123eed67faSmbalmer
9913dc407927Smrg	orig_export_symbols=
9914dc407927Smrg	case $host_os in
9915dc407927Smrg	cygwin* | mingw* | cegcc*)
9916dc407927Smrg	  if test -n "$export_symbols" && test -z "$export_symbols_regex"; then
9917dc407927Smrg	    # exporting using user supplied symfile
99181a9c160aSmrg	    func_dll_def_p "$export_symbols" || {
9919dc407927Smrg	      # and it's NOT already a .def file. Must figure out
9920dc407927Smrg	      # which of the given symbols are data symbols and tag
9921dc407927Smrg	      # them as such. So, trigger use of export_symbols_cmds.
9922dc407927Smrg	      # export_symbols gets reassigned inside the "prepare
9923dc407927Smrg	      # the list of exported symbols" if statement, so the
9924dc407927Smrg	      # include_expsyms logic still works.
99251a9c160aSmrg	      orig_export_symbols=$export_symbols
9926dc407927Smrg	      export_symbols=
9927dc407927Smrg	      always_export_symbols=yes
99281a9c160aSmrg	    }
9929dc407927Smrg	  fi
9930dc407927Smrg	  ;;
9931dc407927Smrg	esac
99323eed67faSmbalmer
9933dc407927Smrg	# Prepare the list of exported symbols
9934dc407927Smrg	if test -z "$export_symbols"; then
99351a9c160aSmrg	  if test yes = "$always_export_symbols" || test -n "$export_symbols_regex"; then
99361a9c160aSmrg	    func_verbose "generating symbol list for '$libname.la'"
99371a9c160aSmrg	    export_symbols=$output_objdir/$libname.exp
9938dc407927Smrg	    $opt_dry_run || $RM $export_symbols
9939dc407927Smrg	    cmds=$export_symbols_cmds
99401a9c160aSmrg	    save_ifs=$IFS; IFS='~'
9941dd0822caSmrg	    for cmd1 in $cmds; do
99421a9c160aSmrg	      IFS=$save_ifs
9943dd0822caSmrg	      # Take the normal branch if the nm_file_list_spec branch
9944dd0822caSmrg	      # doesn't work or if tool conversion is not needed.
9945dd0822caSmrg	      case $nm_file_list_spec~$to_tool_file_cmd in
9946dd0822caSmrg		*~func_convert_file_noop | *~func_convert_file_msys_to_w32 | ~*)
9947dd0822caSmrg		  try_normal_branch=yes
9948dd0822caSmrg		  eval cmd=\"$cmd1\"
9949dd0822caSmrg		  func_len " $cmd"
9950dd0822caSmrg		  len=$func_len_result
9951dd0822caSmrg		  ;;
9952dd0822caSmrg		*)
9953dd0822caSmrg		  try_normal_branch=no
9954dd0822caSmrg		  ;;
9955dd0822caSmrg	      esac
99561a9c160aSmrg	      if test yes = "$try_normal_branch" \
9957dd0822caSmrg		 && { test "$len" -lt "$max_cmd_len" \
9958dd0822caSmrg		      || test "$max_cmd_len" -le -1; }
9959dd0822caSmrg	      then
9960dd0822caSmrg		func_show_eval "$cmd" 'exit $?'
9961dd0822caSmrg		skipped_export=false
9962dd0822caSmrg	      elif test -n "$nm_file_list_spec"; then
9963dd0822caSmrg		func_basename "$output"
9964dd0822caSmrg		output_la=$func_basename_result
9965dd0822caSmrg		save_libobjs=$libobjs
9966dd0822caSmrg		save_output=$output
99671a9c160aSmrg		output=$output_objdir/$output_la.nm
9968dd0822caSmrg		func_to_tool_file "$output"
9969dd0822caSmrg		libobjs=$nm_file_list_spec$func_to_tool_file_result
9970dd0822caSmrg		func_append delfiles " $output"
9971dd0822caSmrg		func_verbose "creating $NM input file list: $output"
9972dd0822caSmrg		for obj in $save_libobjs; do
9973dd0822caSmrg		  func_to_tool_file "$obj"
9974dd0822caSmrg		  $ECHO "$func_to_tool_file_result"
9975dd0822caSmrg		done > "$output"
9976dd0822caSmrg		eval cmd=\"$cmd1\"
9977dc407927Smrg		func_show_eval "$cmd" 'exit $?'
9978dd0822caSmrg		output=$save_output
9979dd0822caSmrg		libobjs=$save_libobjs
9980dc407927Smrg		skipped_export=false
9981dc407927Smrg	      else
9982dc407927Smrg		# The command line is too long to execute in one step.
9983dc407927Smrg		func_verbose "using reloadable object file for export list..."
9984dc407927Smrg		skipped_export=:
9985dc407927Smrg		# Break out early, otherwise skipped_export may be
9986dc407927Smrg		# set to false by a later but shorter cmd.
9987dc407927Smrg		break
9988dc407927Smrg	      fi
9989dc407927Smrg	    done
99901a9c160aSmrg	    IFS=$save_ifs
99911a9c160aSmrg	    if test -n "$export_symbols_regex" && test : != "$skipped_export"; then
9992dc407927Smrg	      func_show_eval '$EGREP -e "$export_symbols_regex" "$export_symbols" > "${export_symbols}T"'
9993dc407927Smrg	      func_show_eval '$MV "${export_symbols}T" "$export_symbols"'
9994dc407927Smrg	    fi
9995dc407927Smrg	  fi
99963eed67faSmbalmer	fi
99973eed67faSmbalmer
9998dc407927Smrg	if test -n "$export_symbols" && test -n "$include_expsyms"; then
99991a9c160aSmrg	  tmp_export_symbols=$export_symbols
100001a9c160aSmrg	  test -n "$orig_export_symbols" && tmp_export_symbols=$orig_export_symbols
10001dd0822caSmrg	  $opt_dry_run || eval '$ECHO "$include_expsyms" | $SP2NL >> "$tmp_export_symbols"'
10002dc407927Smrg	fi
100033eed67faSmbalmer
100041a9c160aSmrg	if test : != "$skipped_export" && test -n "$orig_export_symbols"; then
10005dc407927Smrg	  # The given exports_symbols file has to be filtered, so filter it.
100061a9c160aSmrg	  func_verbose "filter symbol list for '$libname.la' to tag DATA exports"
10007dc407927Smrg	  # FIXME: $output_objdir/$libname.filter potentially contains lots of
100081a9c160aSmrg	  # 's' commands, which not all seds can handle. GNU sed should be fine
10009dc407927Smrg	  # though. Also, the filter scales superlinearly with the number of
10010dc407927Smrg	  # global variables. join(1) would be nice here, but unfortunately
10011dc407927Smrg	  # isn't a blessed tool.
10012dc407927Smrg	  $opt_dry_run || $SED -e '/[ ,]DATA/!d;s,\(.*\)\([ \,].*\),s|^\1$|\1\2|,' < $export_symbols > $output_objdir/$libname.filter
10013dd0822caSmrg	  func_append delfiles " $export_symbols $output_objdir/$libname.filter"
10014dc407927Smrg	  export_symbols=$output_objdir/$libname.def
10015dc407927Smrg	  $opt_dry_run || $SED -f $output_objdir/$libname.filter < $orig_export_symbols > $export_symbols
10016dc407927Smrg	fi
100173eed67faSmbalmer
10018dc407927Smrg	tmp_deplibs=
10019dc407927Smrg	for test_deplib in $deplibs; do
10020dc407927Smrg	  case " $convenience " in
10021dc407927Smrg	  *" $test_deplib "*) ;;
10022dc407927Smrg	  *)
10023dd0822caSmrg	    func_append tmp_deplibs " $test_deplib"
10024dc407927Smrg	    ;;
10025dc407927Smrg	  esac
10026dc407927Smrg	done
100271a9c160aSmrg	deplibs=$tmp_deplibs
100283eed67faSmbalmer
10029dc407927Smrg	if test -n "$convenience"; then
10030dc407927Smrg	  if test -n "$whole_archive_flag_spec" &&
100311a9c160aSmrg	    test yes = "$compiler_needs_object" &&
10032dc407927Smrg	    test -z "$libobjs"; then
10033dc407927Smrg	    # extract the archives, so we have objects to list.
10034dc407927Smrg	    # TODO: could optimize this to just extract one archive.
10035dc407927Smrg	    whole_archive_flag_spec=
10036dc407927Smrg	  fi
10037dc407927Smrg	  if test -n "$whole_archive_flag_spec"; then
10038dc407927Smrg	    save_libobjs=$libobjs
10039dc407927Smrg	    eval libobjs=\"\$libobjs $whole_archive_flag_spec\"
10040dc407927Smrg	    test "X$libobjs" = "X " && libobjs=
10041dc407927Smrg	  else
100421a9c160aSmrg	    gentop=$output_objdir/${outputname}x
10043dd0822caSmrg	    func_append generated " $gentop"
100443eed67faSmbalmer
10045dc407927Smrg	    func_extract_archives $gentop $convenience
10046dd0822caSmrg	    func_append libobjs " $func_extract_archives_result"
10047dc407927Smrg	    test "X$libobjs" = "X " && libobjs=
10048dc407927Smrg	  fi
100493eed67faSmbalmer	fi
100503eed67faSmbalmer
100511a9c160aSmrg	if test yes = "$thread_safe" && test -n "$thread_safe_flag_spec"; then
10052dc407927Smrg	  eval flag=\"$thread_safe_flag_spec\"
10053dd0822caSmrg	  func_append linker_flags " $flag"
100543eed67faSmbalmer	fi
100553eed67faSmbalmer
10056dc407927Smrg	# Make a backup of the uninstalled library when relinking
100571a9c160aSmrg	if test relink = "$opt_mode"; then
10058dc407927Smrg	  $opt_dry_run || eval '(cd $output_objdir && $RM ${realname}U && $MV $realname ${realname}U)' || exit $?
10059dc407927Smrg	fi
100603eed67faSmbalmer
10061dc407927Smrg	# Do each of the archive commands.
100621a9c160aSmrg	if test yes = "$module" && test -n "$module_cmds"; then
10063dc407927Smrg	  if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then
10064dc407927Smrg	    eval test_cmds=\"$module_expsym_cmds\"
10065dc407927Smrg	    cmds=$module_expsym_cmds
10066dc407927Smrg	  else
10067dc407927Smrg	    eval test_cmds=\"$module_cmds\"
10068dc407927Smrg	    cmds=$module_cmds
10069dc407927Smrg	  fi
100703eed67faSmbalmer	else
10071dc407927Smrg	  if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then
10072dc407927Smrg	    eval test_cmds=\"$archive_expsym_cmds\"
10073dc407927Smrg	    cmds=$archive_expsym_cmds
10074dc407927Smrg	  else
10075dc407927Smrg	    eval test_cmds=\"$archive_cmds\"
10076dc407927Smrg	    cmds=$archive_cmds
10077dc407927Smrg	  fi
100783eed67faSmbalmer	fi
100793eed67faSmbalmer
100801a9c160aSmrg	if test : != "$skipped_export" &&
10081dc407927Smrg	   func_len " $test_cmds" &&
10082dc407927Smrg	   len=$func_len_result &&
10083dc407927Smrg	   test "$len" -lt "$max_cmd_len" || test "$max_cmd_len" -le -1; then
10084dc407927Smrg	  :
10085dc407927Smrg	else
10086dc407927Smrg	  # The command line is too long to link in one step, link piecewise
10087dc407927Smrg	  # or, if using GNU ld and skipped_export is not :, use a linker
10088dc407927Smrg	  # script.
100893eed67faSmbalmer
10090dc407927Smrg	  # Save the value of $output and $libobjs because we want to
10091dc407927Smrg	  # use them later.  If we have whole_archive_flag_spec, we
10092dc407927Smrg	  # want to use save_libobjs as it was before
10093dc407927Smrg	  # whole_archive_flag_spec was expanded, because we can't
10094dc407927Smrg	  # assume the linker understands whole_archive_flag_spec.
10095dc407927Smrg	  # This may have to be revisited, in case too many
10096dc407927Smrg	  # convenience libraries get linked in and end up exceeding
10097dc407927Smrg	  # the spec.
10098dc407927Smrg	  if test -z "$convenience" || test -z "$whole_archive_flag_spec"; then
10099dc407927Smrg	    save_libobjs=$libobjs
10100dc407927Smrg	  fi
10101dc407927Smrg	  save_output=$output
10102dd0822caSmrg	  func_basename "$output"
10103dd0822caSmrg	  output_la=$func_basename_result
101043eed67faSmbalmer
10105dc407927Smrg	  # Clear the reloadable object creation command queue and
10106dc407927Smrg	  # initialize k to one.
10107dc407927Smrg	  test_cmds=
10108dc407927Smrg	  concat_cmds=
10109dc407927Smrg	  objlist=
10110dc407927Smrg	  last_robj=
10111dc407927Smrg	  k=1
10112dc407927Smrg
101131a9c160aSmrg	  if test -n "$save_libobjs" && test : != "$skipped_export" && test yes = "$with_gnu_ld"; then
101141a9c160aSmrg	    output=$output_objdir/$output_la.lnkscript
10115dc407927Smrg	    func_verbose "creating GNU ld script: $output"
10116dd0822caSmrg	    echo 'INPUT (' > $output
10117dc407927Smrg	    for obj in $save_libobjs
101183eed67faSmbalmer	    do
10119dd0822caSmrg	      func_to_tool_file "$obj"
10120dd0822caSmrg	      $ECHO "$func_to_tool_file_result" >> $output
10121dc407927Smrg	    done
10122dd0822caSmrg	    echo ')' >> $output
10123dd0822caSmrg	    func_append delfiles " $output"
10124dd0822caSmrg	    func_to_tool_file "$output"
10125dd0822caSmrg	    output=$func_to_tool_file_result
101261a9c160aSmrg	  elif test -n "$save_libobjs" && test : != "$skipped_export" && test -n "$file_list_spec"; then
101271a9c160aSmrg	    output=$output_objdir/$output_la.lnk
10128dc407927Smrg	    func_verbose "creating linker input file list: $output"
10129dc407927Smrg	    : > $output
10130dc407927Smrg	    set x $save_libobjs
10131dc407927Smrg	    shift
10132dc407927Smrg	    firstobj=
101331a9c160aSmrg	    if test yes = "$compiler_needs_object"; then
10134dc407927Smrg	      firstobj="$1 "
10135dc407927Smrg	      shift
10136dc407927Smrg	    fi
10137dc407927Smrg	    for obj
10138dc407927Smrg	    do
10139dd0822caSmrg	      func_to_tool_file "$obj"
10140dd0822caSmrg	      $ECHO "$func_to_tool_file_result" >> $output
10141dc407927Smrg	    done
10142dd0822caSmrg	    func_append delfiles " $output"
10143dd0822caSmrg	    func_to_tool_file "$output"
10144dd0822caSmrg	    output=$firstobj\"$file_list_spec$func_to_tool_file_result\"
10145dc407927Smrg	  else
10146dc407927Smrg	    if test -n "$save_libobjs"; then
10147dc407927Smrg	      func_verbose "creating reloadable object files..."
101481a9c160aSmrg	      output=$output_objdir/$output_la-$k.$objext
10149dc407927Smrg	      eval test_cmds=\"$reload_cmds\"
10150dc407927Smrg	      func_len " $test_cmds"
10151dc407927Smrg	      len0=$func_len_result
10152dc407927Smrg	      len=$len0
10153dc407927Smrg
10154dc407927Smrg	      # Loop over the list of objects to be linked.
10155dc407927Smrg	      for obj in $save_libobjs
10156dc407927Smrg	      do
10157dc407927Smrg		func_len " $obj"
10158dc407927Smrg		func_arith $len + $func_len_result
10159dc407927Smrg		len=$func_arith_result
101601a9c160aSmrg		if test -z "$objlist" ||
10161dc407927Smrg		   test "$len" -lt "$max_cmd_len"; then
10162dc407927Smrg		  func_append objlist " $obj"
10163dc407927Smrg		else
10164dc407927Smrg		  # The command $test_cmds is almost too long, add a
10165dc407927Smrg		  # command to the queue.
101661a9c160aSmrg		  if test 1 -eq "$k"; then
10167dc407927Smrg		    # The first file doesn't have a previous command to add.
10168dd0822caSmrg		    reload_objs=$objlist
10169dd0822caSmrg		    eval concat_cmds=\"$reload_cmds\"
10170dc407927Smrg		  else
10171dc407927Smrg		    # All subsequent reloadable object files will link in
10172dc407927Smrg		    # the last one created.
10173dd0822caSmrg		    reload_objs="$objlist $last_robj"
10174dd0822caSmrg		    eval concat_cmds=\"\$concat_cmds~$reload_cmds~\$RM $last_robj\"
10175dc407927Smrg		  fi
101761a9c160aSmrg		  last_robj=$output_objdir/$output_la-$k.$objext
10177dc407927Smrg		  func_arith $k + 1
10178dc407927Smrg		  k=$func_arith_result
101791a9c160aSmrg		  output=$output_objdir/$output_la-$k.$objext
10180dd0822caSmrg		  objlist=" $obj"
10181dc407927Smrg		  func_len " $last_robj"
10182dc407927Smrg		  func_arith $len0 + $func_len_result
10183dc407927Smrg		  len=$func_arith_result
10184dc407927Smrg		fi
10185dc407927Smrg	      done
10186dc407927Smrg	      # Handle the remaining objects by creating one last
10187dc407927Smrg	      # reloadable object file.  All subsequent reloadable object
10188dc407927Smrg	      # files will link in the last one created.
10189dc407927Smrg	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
10190dd0822caSmrg	      reload_objs="$objlist $last_robj"
101911a9c160aSmrg	      eval concat_cmds=\"\$concat_cmds$reload_cmds\"
10192dc407927Smrg	      if test -n "$last_robj"; then
101931a9c160aSmrg	        eval concat_cmds=\"\$concat_cmds~\$RM $last_robj\"
10194dc407927Smrg	      fi
10195dd0822caSmrg	      func_append delfiles " $output"
101963eed67faSmbalmer
10197dc407927Smrg	    else
10198dc407927Smrg	      output=
10199dc407927Smrg	    fi
10200dc407927Smrg
102011a9c160aSmrg	    ${skipped_export-false} && {
102021a9c160aSmrg	      func_verbose "generating symbol list for '$libname.la'"
102031a9c160aSmrg	      export_symbols=$output_objdir/$libname.exp
10204dc407927Smrg	      $opt_dry_run || $RM $export_symbols
10205dc407927Smrg	      libobjs=$output
10206dc407927Smrg	      # Append the command to create the export file.
10207dc407927Smrg	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
10208dc407927Smrg	      eval concat_cmds=\"\$concat_cmds$export_symbols_cmds\"
10209dc407927Smrg	      if test -n "$last_robj"; then
10210dc407927Smrg		eval concat_cmds=\"\$concat_cmds~\$RM $last_robj\"
10211dc407927Smrg	      fi
102121a9c160aSmrg	    }
10213dc407927Smrg
10214dc407927Smrg	    test -n "$save_libobjs" &&
10215dc407927Smrg	      func_verbose "creating a temporary reloadable object file: $output"
10216dc407927Smrg
10217dc407927Smrg	    # Loop through the commands generated above and execute them.
102181a9c160aSmrg	    save_ifs=$IFS; IFS='~'
10219dc407927Smrg	    for cmd in $concat_cmds; do
102201a9c160aSmrg	      IFS=$save_ifs
102211a9c160aSmrg	      $opt_quiet || {
10222621f50c3Smrg		  func_quote_arg expand,pretty "$cmd"
10223621f50c3Smrg		  eval "func_echo $func_quote_arg_result"
10224dc407927Smrg	      }
10225dc407927Smrg	      $opt_dry_run || eval "$cmd" || {
10226dc407927Smrg		lt_exit=$?
10227dc407927Smrg
10228dc407927Smrg		# Restore the uninstalled library and exit
102291a9c160aSmrg		if test relink = "$opt_mode"; then
10230dc407927Smrg		  ( cd "$output_objdir" && \
10231dc407927Smrg		    $RM "${realname}T" && \
10232dc407927Smrg		    $MV "${realname}U" "$realname" )
10233dc407927Smrg		fi
10234dc407927Smrg
10235dc407927Smrg		exit $lt_exit
10236dc407927Smrg	      }
10237dc407927Smrg	    done
102381a9c160aSmrg	    IFS=$save_ifs
102393eed67faSmbalmer
10240dc407927Smrg	    if test -n "$export_symbols_regex" && ${skipped_export-false}; then
10241dc407927Smrg	      func_show_eval '$EGREP -e "$export_symbols_regex" "$export_symbols" > "${export_symbols}T"'
10242dc407927Smrg	      func_show_eval '$MV "${export_symbols}T" "$export_symbols"'
102433eed67faSmbalmer	    fi
102443eed67faSmbalmer	  fi
102453eed67faSmbalmer
102461a9c160aSmrg          ${skipped_export-false} && {
10247dc407927Smrg	    if test -n "$export_symbols" && test -n "$include_expsyms"; then
102481a9c160aSmrg	      tmp_export_symbols=$export_symbols
102491a9c160aSmrg	      test -n "$orig_export_symbols" && tmp_export_symbols=$orig_export_symbols
10250dd0822caSmrg	      $opt_dry_run || eval '$ECHO "$include_expsyms" | $SP2NL >> "$tmp_export_symbols"'
10251dc407927Smrg	    fi
102523eed67faSmbalmer
10253dc407927Smrg	    if test -n "$orig_export_symbols"; then
10254dc407927Smrg	      # The given exports_symbols file has to be filtered, so filter it.
102551a9c160aSmrg	      func_verbose "filter symbol list for '$libname.la' to tag DATA exports"
10256dc407927Smrg	      # FIXME: $output_objdir/$libname.filter potentially contains lots of
102571a9c160aSmrg	      # 's' commands, which not all seds can handle. GNU sed should be fine
10258dc407927Smrg	      # though. Also, the filter scales superlinearly with the number of
10259dc407927Smrg	      # global variables. join(1) would be nice here, but unfortunately
10260dc407927Smrg	      # isn't a blessed tool.
10261dc407927Smrg	      $opt_dry_run || $SED -e '/[ ,]DATA/!d;s,\(.*\)\([ \,].*\),s|^\1$|\1\2|,' < $export_symbols > $output_objdir/$libname.filter
10262dd0822caSmrg	      func_append delfiles " $export_symbols $output_objdir/$libname.filter"
10263dc407927Smrg	      export_symbols=$output_objdir/$libname.def
10264dc407927Smrg	      $opt_dry_run || $SED -f $output_objdir/$libname.filter < $orig_export_symbols > $export_symbols
10265dc407927Smrg	    fi
102661a9c160aSmrg	  }
102673eed67faSmbalmer
10268dc407927Smrg	  libobjs=$output
10269dc407927Smrg	  # Restore the value of output.
10270dc407927Smrg	  output=$save_output
102713eed67faSmbalmer
10272dc407927Smrg	  if test -n "$convenience" && test -n "$whole_archive_flag_spec"; then
10273dc407927Smrg	    eval libobjs=\"\$libobjs $whole_archive_flag_spec\"
10274dc407927Smrg	    test "X$libobjs" = "X " && libobjs=
10275dc407927Smrg	  fi
10276dc407927Smrg	  # Expand the library linking commands again to reset the
10277dc407927Smrg	  # value of $libobjs for piecewise linking.
10278dc407927Smrg
10279dc407927Smrg	  # Do each of the archive commands.
102801a9c160aSmrg	  if test yes = "$module" && test -n "$module_cmds"; then
10281dc407927Smrg	    if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then
10282dc407927Smrg	      cmds=$module_expsym_cmds
102833eed67faSmbalmer	    else
10284dc407927Smrg	      cmds=$module_cmds
102853eed67faSmbalmer	    fi
102863eed67faSmbalmer	  else
10287dc407927Smrg	    if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then
10288dc407927Smrg	      cmds=$archive_expsym_cmds
10289dc407927Smrg	    else
10290dc407927Smrg	      cmds=$archive_cmds
10291dc407927Smrg	    fi
102923eed67faSmbalmer	  fi
102933eed67faSmbalmer	fi
102943eed67faSmbalmer
10295dc407927Smrg	if test -n "$delfiles"; then
10296dc407927Smrg	  # Append the command to remove temporary files to $cmds.
10297dc407927Smrg	  eval cmds=\"\$cmds~\$RM $delfiles\"
10298dc407927Smrg	fi
102993eed67faSmbalmer
10300dc407927Smrg	# Add any objects from preloaded convenience libraries
10301dc407927Smrg	if test -n "$dlprefiles"; then
103021a9c160aSmrg	  gentop=$output_objdir/${outputname}x
10303dd0822caSmrg	  func_append generated " $gentop"
103043eed67faSmbalmer
10305dc407927Smrg	  func_extract_archives $gentop $dlprefiles
10306dd0822caSmrg	  func_append libobjs " $func_extract_archives_result"
10307dc407927Smrg	  test "X$libobjs" = "X " && libobjs=
103083eed67faSmbalmer	fi
103093eed67faSmbalmer
103101a9c160aSmrg	save_ifs=$IFS; IFS='~'
10311dc407927Smrg	for cmd in $cmds; do
103121a9c160aSmrg	  IFS=$sp$nl
10313dc407927Smrg	  eval cmd=\"$cmd\"
103141a9c160aSmrg	  IFS=$save_ifs
103151a9c160aSmrg	  $opt_quiet || {
10316621f50c3Smrg	    func_quote_arg expand,pretty "$cmd"
10317621f50c3Smrg	    eval "func_echo $func_quote_arg_result"
10318dc407927Smrg	  }
10319dc407927Smrg	  $opt_dry_run || eval "$cmd" || {
10320dc407927Smrg	    lt_exit=$?
103213eed67faSmbalmer
10322dc407927Smrg	    # Restore the uninstalled library and exit
103231a9c160aSmrg	    if test relink = "$opt_mode"; then
10324dc407927Smrg	      ( cd "$output_objdir" && \
10325dc407927Smrg	        $RM "${realname}T" && \
10326dc407927Smrg		$MV "${realname}U" "$realname" )
10327dc407927Smrg	    fi
10328dc407927Smrg
10329dc407927Smrg	    exit $lt_exit
10330dc407927Smrg	  }
10331dc407927Smrg	done
103321a9c160aSmrg	IFS=$save_ifs
10333dc407927Smrg
10334dc407927Smrg	# Restore the uninstalled library and exit
103351a9c160aSmrg	if test relink = "$opt_mode"; then
10336dc407927Smrg	  $opt_dry_run || eval '(cd $output_objdir && $RM ${realname}T && $MV $realname ${realname}T && $MV ${realname}U $realname)' || exit $?
10337dc407927Smrg
10338dc407927Smrg	  if test -n "$convenience"; then
10339dc407927Smrg	    if test -z "$whole_archive_flag_spec"; then
10340dc407927Smrg	      func_show_eval '${RM}r "$gentop"'
103413eed67faSmbalmer	    fi
103423eed67faSmbalmer	  fi
103433eed67faSmbalmer
10344dc407927Smrg	  exit $EXIT_SUCCESS
10345dc407927Smrg	fi
103463eed67faSmbalmer
10347dc407927Smrg	# Create links to the real library.
10348dc407927Smrg	for linkname in $linknames; do
10349dc407927Smrg	  if test "$realname" != "$linkname"; then
10350dc407927Smrg	    func_show_eval '(cd "$output_objdir" && $RM "$linkname" && $LN_S "$realname" "$linkname")' 'exit $?'
10351dc407927Smrg	  fi
10352dc407927Smrg	done
10353dc407927Smrg
10354dc407927Smrg	# If -module or -export-dynamic was specified, set the dlname.
103551a9c160aSmrg	if test yes = "$module" || test yes = "$export_dynamic"; then
10356dc407927Smrg	  # On all known operating systems, these are identical.
103571a9c160aSmrg	  dlname=$soname
10358dc407927Smrg	fi
10359dc407927Smrg      fi
10360dc407927Smrg      ;;
10361dc407927Smrg
10362dc407927Smrg    obj)
103631a9c160aSmrg      if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then
103641a9c160aSmrg	func_warning "'-dlopen' is ignored for objects"
10365dc407927Smrg      fi
10366dc407927Smrg
10367dc407927Smrg      case " $deplibs" in
10368dc407927Smrg      *\ -l* | *\ -L*)
103691a9c160aSmrg	func_warning "'-l' and '-L' are ignored for objects" ;;
10370dc407927Smrg      esac
10371dc407927Smrg
10372dc407927Smrg      test -n "$rpath" && \
103731a9c160aSmrg	func_warning "'-rpath' is ignored for objects"
10374dc407927Smrg
10375dc407927Smrg      test -n "$xrpath" && \
103761a9c160aSmrg	func_warning "'-R' is ignored for objects"
10377dc407927Smrg
10378dc407927Smrg      test -n "$vinfo" && \
103791a9c160aSmrg	func_warning "'-version-info' is ignored for objects"
10380dc407927Smrg
10381dc407927Smrg      test -n "$release" && \
103821a9c160aSmrg	func_warning "'-release' is ignored for objects"
10383dc407927Smrg
10384dc407927Smrg      case $output in
10385dc407927Smrg      *.lo)
10386dc407927Smrg	test -n "$objs$old_deplibs" && \
103871a9c160aSmrg	  func_fatal_error "cannot build library object '$output' from non-libtool objects"
10388dc407927Smrg
10389dc407927Smrg	libobj=$output
10390dc407927Smrg	func_lo2o "$libobj"
10391dc407927Smrg	obj=$func_lo2o_result
10392dc407927Smrg	;;
10393dc407927Smrg      *)
10394dc407927Smrg	libobj=
103951a9c160aSmrg	obj=$output
10396dc407927Smrg	;;
10397dc407927Smrg      esac
10398dc407927Smrg
10399dc407927Smrg      # Delete the old objects.
10400dc407927Smrg      $opt_dry_run || $RM $obj $libobj
10401dc407927Smrg
10402dc407927Smrg      # Objects from convenience libraries.  This assumes
10403dc407927Smrg      # single-version convenience libraries.  Whenever we create
10404dc407927Smrg      # different ones for PIC/non-PIC, this we'll have to duplicate
10405dc407927Smrg      # the extraction.
10406dc407927Smrg      reload_conv_objs=
10407dc407927Smrg      gentop=
104081a9c160aSmrg      # if reload_cmds runs $LD directly, get rid of -Wl from
104091a9c160aSmrg      # whole_archive_flag_spec and hope we can get by with turning comma
104101a9c160aSmrg      # into space.
104111a9c160aSmrg      case $reload_cmds in
104121a9c160aSmrg        *\$LD[\ \$]*) wl= ;;
104131a9c160aSmrg      esac
10414dc407927Smrg      if test -n "$convenience"; then
10415dc407927Smrg	if test -n "$whole_archive_flag_spec"; then
10416dc407927Smrg	  eval tmp_whole_archive_flags=\"$whole_archive_flag_spec\"
104171a9c160aSmrg	  test -n "$wl" || tmp_whole_archive_flags=`$ECHO "$tmp_whole_archive_flags" | $SED 's|,| |g'`
104181a9c160aSmrg	  reload_conv_objs=$reload_objs\ $tmp_whole_archive_flags
10419dc407927Smrg	else
104201a9c160aSmrg	  gentop=$output_objdir/${obj}x
10421dd0822caSmrg	  func_append generated " $gentop"
10422dc407927Smrg
10423dc407927Smrg	  func_extract_archives $gentop $convenience
10424dc407927Smrg	  reload_conv_objs="$reload_objs $func_extract_archives_result"
10425dc407927Smrg	fi
10426dc407927Smrg      fi
10427dc407927Smrg
10428dd0822caSmrg      # If we're not building shared, we need to use non_pic_objs
104291a9c160aSmrg      test yes = "$build_libtool_libs" || libobjs=$non_pic_objects
10430dd0822caSmrg
10431dc407927Smrg      # Create the old-style object.
104321a9c160aSmrg      reload_objs=$objs$old_deplibs' '`$ECHO "$libobjs" | $SP2NL | $SED "/\.$libext$/d; /\.lib$/d; $lo2o" | $NL2SP`' '$reload_conv_objs
104333eed67faSmbalmer
104341a9c160aSmrg      output=$obj
10435dc407927Smrg      func_execute_cmds "$reload_cmds" 'exit $?'
104363eed67faSmbalmer
10437dc407927Smrg      # Exit if we aren't doing a library object file.
10438dc407927Smrg      if test -z "$libobj"; then
10439dc407927Smrg	if test -n "$gentop"; then
10440dc407927Smrg	  func_show_eval '${RM}r "$gentop"'
10441dc407927Smrg	fi
104423eed67faSmbalmer
10443dc407927Smrg	exit $EXIT_SUCCESS
10444dc407927Smrg      fi
104453eed67faSmbalmer
104461a9c160aSmrg      test yes = "$build_libtool_libs" || {
10447dc407927Smrg	if test -n "$gentop"; then
10448dc407927Smrg	  func_show_eval '${RM}r "$gentop"'
10449dc407927Smrg	fi
104503eed67faSmbalmer
10451dc407927Smrg	# Create an invalid libtool object if no PIC, so that we don't
10452dc407927Smrg	# accidentally link it into a program.
10453dc407927Smrg	# $show "echo timestamp > $libobj"
10454dc407927Smrg	# $opt_dry_run || eval "echo timestamp > $libobj" || exit $?
10455dc407927Smrg	exit $EXIT_SUCCESS
104561a9c160aSmrg      }
104573eed67faSmbalmer
104581a9c160aSmrg      if test -n "$pic_flag" || test default != "$pic_mode"; then
10459dc407927Smrg	# Only do commands if we really have different PIC objects.
10460dc407927Smrg	reload_objs="$libobjs $reload_conv_objs"
104611a9c160aSmrg	output=$libobj
10462dc407927Smrg	func_execute_cmds "$reload_cmds" 'exit $?'
10463dc407927Smrg      fi
104643eed67faSmbalmer
10465dc407927Smrg      if test -n "$gentop"; then
10466dc407927Smrg	func_show_eval '${RM}r "$gentop"'
104673eed67faSmbalmer      fi
104683eed67faSmbalmer
10469dc407927Smrg      exit $EXIT_SUCCESS
104703eed67faSmbalmer      ;;
104713eed67faSmbalmer
10472dc407927Smrg    prog)
10473dc407927Smrg      case $host in
10474dc407927Smrg	*cygwin*) func_stripname '' '.exe' "$output"
10475dc407927Smrg	          output=$func_stripname_result.exe;;
104763eed67faSmbalmer      esac
10477dc407927Smrg      test -n "$vinfo" && \
104781a9c160aSmrg	func_warning "'-version-info' is ignored for programs"
104793eed67faSmbalmer
10480dc407927Smrg      test -n "$release" && \
104811a9c160aSmrg	func_warning "'-release' is ignored for programs"
104823eed67faSmbalmer
104831a9c160aSmrg      $preload \
104841a9c160aSmrg	&& test unknown,unknown,unknown = "$dlopen_support,$dlopen_self,$dlopen_self_static" \
104851a9c160aSmrg	&& func_warning "'LT_INIT([dlopen])' not used. Assuming no dlopen support."
104863eed67faSmbalmer
10487dc407927Smrg      case $host in
10488dc407927Smrg      *-*-rhapsody* | *-*-darwin1.[012])
10489dc407927Smrg	# On Rhapsody replace the C library is the System framework
10490dd0822caSmrg	compile_deplibs=`$ECHO " $compile_deplibs" | $SED 's/ -lc / System.ltframework /'`
10491dd0822caSmrg	finalize_deplibs=`$ECHO " $finalize_deplibs" | $SED 's/ -lc / System.ltframework /'`
104923eed67faSmbalmer	;;
104933eed67faSmbalmer      esac
104943eed67faSmbalmer
10495dc407927Smrg      case $host in
10496dc407927Smrg      *-*-darwin*)
10497dc407927Smrg	# Don't allow lazy linking, it breaks C++ global constructors
10498dc407927Smrg	# But is supposedly fixed on 10.4 or later (yay!).
104991a9c160aSmrg	if test CXX = "$tagname"; then
10500dc407927Smrg	  case ${MACOSX_DEPLOYMENT_TARGET-10.0} in
10501dc407927Smrg	    10.[0123])
105021a9c160aSmrg	      func_append compile_command " $wl-bind_at_load"
105031a9c160aSmrg	      func_append finalize_command " $wl-bind_at_load"
10504dc407927Smrg	    ;;
10505dc407927Smrg	  esac
10506dc407927Smrg	fi
10507dc407927Smrg	# Time to change all our "foo.ltframework" stuff back to "-framework foo"
10508dd0822caSmrg	compile_deplibs=`$ECHO " $compile_deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
10509dd0822caSmrg	finalize_deplibs=`$ECHO " $finalize_deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
105103eed67faSmbalmer	;;
105113eed67faSmbalmer      esac
105123eed67faSmbalmer
105133eed67faSmbalmer
10514dc407927Smrg      # move library search paths that coincide with paths to not yet
10515dc407927Smrg      # installed libraries to the beginning of the library search list
10516dc407927Smrg      new_libs=
10517dc407927Smrg      for path in $notinst_path; do
10518dc407927Smrg	case " $new_libs " in
10519dc407927Smrg	*" -L$path/$objdir "*) ;;
105203eed67faSmbalmer	*)
10521dc407927Smrg	  case " $compile_deplibs " in
10522dc407927Smrg	  *" -L$path/$objdir "*)
10523dd0822caSmrg	    func_append new_libs " -L$path/$objdir" ;;
10524dc407927Smrg	  esac
105253eed67faSmbalmer	  ;;
105263eed67faSmbalmer	esac
105273eed67faSmbalmer      done
10528dc407927Smrg      for deplib in $compile_deplibs; do
10529dc407927Smrg	case $deplib in
10530dc407927Smrg	-L*)
10531dc407927Smrg	  case " $new_libs " in
10532dc407927Smrg	  *" $deplib "*) ;;
10533dd0822caSmrg	  *) func_append new_libs " $deplib" ;;
10534dc407927Smrg	  esac
10535dc407927Smrg	  ;;
10536dd0822caSmrg	*) func_append new_libs " $deplib" ;;
10537dc407927Smrg	esac
10538dc407927Smrg      done
105391a9c160aSmrg      compile_deplibs=$new_libs
105403eed67faSmbalmer
105413eed67faSmbalmer
10542dd0822caSmrg      func_append compile_command " $compile_deplibs"
10543dd0822caSmrg      func_append finalize_command " $finalize_deplibs"
105443eed67faSmbalmer
10545dc407927Smrg      if test -n "$rpath$xrpath"; then
10546dc407927Smrg	# If the user specified any rpath flags, then add them.
10547dc407927Smrg	for libdir in $rpath $xrpath; do
10548dc407927Smrg	  # This is the magic to use -rpath.
10549dc407927Smrg	  case "$finalize_rpath " in
10550dc407927Smrg	  *" $libdir "*) ;;
10551dd0822caSmrg	  *) func_append finalize_rpath " $libdir" ;;
10552dc407927Smrg	  esac
10553dc407927Smrg	done
10554dc407927Smrg      fi
105553eed67faSmbalmer
10556dc407927Smrg      # Now hardcode the library paths
10557dc407927Smrg      rpath=
10558dc407927Smrg      hardcode_libdirs=
10559dc407927Smrg      for libdir in $compile_rpath $finalize_rpath; do
10560dc407927Smrg	if test -n "$hardcode_libdir_flag_spec"; then
10561dc407927Smrg	  if test -n "$hardcode_libdir_separator"; then
10562dc407927Smrg	    if test -z "$hardcode_libdirs"; then
105631a9c160aSmrg	      hardcode_libdirs=$libdir
10564dc407927Smrg	    else
10565dc407927Smrg	      # Just accumulate the unique libdirs.
10566dc407927Smrg	      case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
10567dc407927Smrg	      *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
10568dc407927Smrg		;;
10569dc407927Smrg	      *)
10570dd0822caSmrg		func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
10571dc407927Smrg		;;
10572dc407927Smrg	      esac
10573dc407927Smrg	    fi
10574dc407927Smrg	  else
10575dc407927Smrg	    eval flag=\"$hardcode_libdir_flag_spec\"
10576dd0822caSmrg	    func_append rpath " $flag"
10577dc407927Smrg	  fi
10578dc407927Smrg	elif test -n "$runpath_var"; then
10579dc407927Smrg	  case "$perm_rpath " in
105803eed67faSmbalmer	  *" $libdir "*) ;;
10581dd0822caSmrg	  *) func_append perm_rpath " $libdir" ;;
105823eed67faSmbalmer	  esac
10583dc407927Smrg	fi
10584dc407927Smrg	case $host in
10585dc407927Smrg	*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
105861a9c160aSmrg	  testbindir=`$ECHO "$libdir" | $SED -e 's*/lib$*/bin*'`
10587dc407927Smrg	  case :$dllsearchpath: in
10588dc407927Smrg	  *":$libdir:"*) ;;
10589dc407927Smrg	  ::) dllsearchpath=$libdir;;
10590dd0822caSmrg	  *) func_append dllsearchpath ":$libdir";;
10591dc407927Smrg	  esac
10592dc407927Smrg	  case :$dllsearchpath: in
10593dc407927Smrg	  *":$testbindir:"*) ;;
10594dc407927Smrg	  ::) dllsearchpath=$testbindir;;
10595dd0822caSmrg	  *) func_append dllsearchpath ":$testbindir";;
10596dc407927Smrg	  esac
10597dc407927Smrg	  ;;
10598dc407927Smrg	esac
10599dc407927Smrg      done
10600dc407927Smrg      # Substitute the hardcoded libdirs into the rpath.
10601dc407927Smrg      if test -n "$hardcode_libdir_separator" &&
10602dc407927Smrg	 test -n "$hardcode_libdirs"; then
106031a9c160aSmrg	libdir=$hardcode_libdirs
10604dc407927Smrg	eval rpath=\" $hardcode_libdir_flag_spec\"
10605dc407927Smrg      fi
106061a9c160aSmrg      compile_rpath=$rpath
10607dc407927Smrg
10608dc407927Smrg      rpath=
10609dc407927Smrg      hardcode_libdirs=
10610dc407927Smrg      for libdir in $finalize_rpath; do
10611dc407927Smrg	if test -n "$hardcode_libdir_flag_spec"; then
10612dc407927Smrg	  if test -n "$hardcode_libdir_separator"; then
10613dc407927Smrg	    if test -z "$hardcode_libdirs"; then
106141a9c160aSmrg	      hardcode_libdirs=$libdir
10615dc407927Smrg	    else
10616dc407927Smrg	      # Just accumulate the unique libdirs.
10617dc407927Smrg	      case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
10618dc407927Smrg	      *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
10619dc407927Smrg		;;
10620dc407927Smrg	      *)
10621dd0822caSmrg		func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
10622dc407927Smrg		;;
10623dc407927Smrg	      esac
10624dc407927Smrg	    fi
10625dc407927Smrg	  else
10626dc407927Smrg	    eval flag=\"$hardcode_libdir_flag_spec\"
10627dd0822caSmrg	    func_append rpath " $flag"
10628dc407927Smrg	  fi
10629dc407927Smrg	elif test -n "$runpath_var"; then
10630dc407927Smrg	  case "$finalize_perm_rpath " in
106313eed67faSmbalmer	  *" $libdir "*) ;;
10632dd0822caSmrg	  *) func_append finalize_perm_rpath " $libdir" ;;
106333eed67faSmbalmer	  esac
106343eed67faSmbalmer	fi
10635dc407927Smrg      done
10636dc407927Smrg      # Substitute the hardcoded libdirs into the rpath.
10637dc407927Smrg      if test -n "$hardcode_libdir_separator" &&
10638dc407927Smrg	 test -n "$hardcode_libdirs"; then
106391a9c160aSmrg	libdir=$hardcode_libdirs
10640dc407927Smrg	eval rpath=\" $hardcode_libdir_flag_spec\"
10641dc407927Smrg      fi
106421a9c160aSmrg      finalize_rpath=$rpath
106433eed67faSmbalmer
106441a9c160aSmrg      if test -n "$libobjs" && test yes = "$build_old_libs"; then
10645dc407927Smrg	# Transform all the library objects into standard objects.
10646dd0822caSmrg	compile_command=`$ECHO "$compile_command" | $SP2NL | $SED "$lo2o" | $NL2SP`
10647dd0822caSmrg	finalize_command=`$ECHO "$finalize_command" | $SP2NL | $SED "$lo2o" | $NL2SP`
10648dc407927Smrg      fi
106493eed67faSmbalmer
106501a9c160aSmrg      func_generate_dlsyms "$outputname" "@PROGRAM@" false
106513eed67faSmbalmer
10652dc407927Smrg      # template prelinking step
10653dc407927Smrg      if test -n "$prelink_cmds"; then
10654dc407927Smrg	func_execute_cmds "$prelink_cmds" 'exit $?'
10655dc407927Smrg      fi
106563eed67faSmbalmer
106571a9c160aSmrg      wrappers_required=:
10658dc407927Smrg      case $host in
10659dd0822caSmrg      *cegcc* | *mingw32ce*)
10660dd0822caSmrg        # Disable wrappers for cegcc and mingw32ce hosts, we are cross compiling anyway.
106611a9c160aSmrg        wrappers_required=false
10662dd0822caSmrg        ;;
10663dc407927Smrg      *cygwin* | *mingw* )
106641a9c160aSmrg        test yes = "$build_libtool_libs" || wrappers_required=false
10665dc407927Smrg        ;;
10666dc407927Smrg      *)
106671a9c160aSmrg        if test no = "$need_relink" || test yes != "$build_libtool_libs"; then
106681a9c160aSmrg          wrappers_required=false
10669dc407927Smrg        fi
10670dc407927Smrg        ;;
10671dc407927Smrg      esac
106721a9c160aSmrg      $wrappers_required || {
10673dc407927Smrg	# Replace the output file specification.
10674dd0822caSmrg	compile_command=`$ECHO "$compile_command" | $SED 's%@OUTPUT@%'"$output"'%g'`
106751a9c160aSmrg	link_command=$compile_command$compile_rpath
106763eed67faSmbalmer
10677dc407927Smrg	# We have no uninstalled library dependencies, so finalize right now.
10678dc407927Smrg	exit_status=0
10679dc407927Smrg	func_show_eval "$link_command" 'exit_status=$?'
106803eed67faSmbalmer
10681dd0822caSmrg	if test -n "$postlink_cmds"; then
10682dd0822caSmrg	  func_to_tool_file "$output"
10683dd0822caSmrg	  postlink_cmds=`func_echo_all "$postlink_cmds" | $SED -e 's%@OUTPUT@%'"$output"'%g' -e 's%@TOOL_OUTPUT@%'"$func_to_tool_file_result"'%g'`
10684dd0822caSmrg	  func_execute_cmds "$postlink_cmds" 'exit $?'
10685dd0822caSmrg	fi
10686dd0822caSmrg
10687dc407927Smrg	# Delete the generated files.
106881a9c160aSmrg	if test -f "$output_objdir/${outputname}S.$objext"; then
106891a9c160aSmrg	  func_show_eval '$RM "$output_objdir/${outputname}S.$objext"'
10690dc407927Smrg	fi
106913eed67faSmbalmer
10692dc407927Smrg	exit $exit_status
106931a9c160aSmrg      }
106943eed67faSmbalmer
10695dc407927Smrg      if test -n "$compile_shlibpath$finalize_shlibpath"; then
10696dc407927Smrg	compile_command="$shlibpath_var=\"$compile_shlibpath$finalize_shlibpath\$$shlibpath_var\" $compile_command"
10697dc407927Smrg      fi
10698dc407927Smrg      if test -n "$finalize_shlibpath"; then
10699dc407927Smrg	finalize_command="$shlibpath_var=\"$finalize_shlibpath\$$shlibpath_var\" $finalize_command"
10700dc407927Smrg      fi
107013eed67faSmbalmer
10702dc407927Smrg      compile_var=
10703dc407927Smrg      finalize_var=
10704dc407927Smrg      if test -n "$runpath_var"; then
10705dc407927Smrg	if test -n "$perm_rpath"; then
10706dc407927Smrg	  # We should set the runpath_var.
10707dc407927Smrg	  rpath=
10708dc407927Smrg	  for dir in $perm_rpath; do
10709dd0822caSmrg	    func_append rpath "$dir:"
107103eed67faSmbalmer	  done
10711dc407927Smrg	  compile_var="$runpath_var=\"$rpath\$$runpath_var\" "
107123eed67faSmbalmer	fi
10713dc407927Smrg	if test -n "$finalize_perm_rpath"; then
10714dc407927Smrg	  # We should set the runpath_var.
10715dc407927Smrg	  rpath=
10716dc407927Smrg	  for dir in $finalize_perm_rpath; do
10717dd0822caSmrg	    func_append rpath "$dir:"
10718dc407927Smrg	  done
10719dc407927Smrg	  finalize_var="$runpath_var=\"$rpath\$$runpath_var\" "
10720dc407927Smrg	fi
10721dc407927Smrg      fi
107223eed67faSmbalmer
107231a9c160aSmrg      if test yes = "$no_install"; then
10724dc407927Smrg	# We don't need to create a wrapper script.
107251a9c160aSmrg	link_command=$compile_var$compile_command$compile_rpath
10726dc407927Smrg	# Replace the output file specification.
10727dd0822caSmrg	link_command=`$ECHO "$link_command" | $SED 's%@OUTPUT@%'"$output"'%g'`
10728dc407927Smrg	# Delete the old output file.
10729dc407927Smrg	$opt_dry_run || $RM $output
10730dc407927Smrg	# Link the executable and exit
10731dc407927Smrg	func_show_eval "$link_command" 'exit $?'
10732dd0822caSmrg
10733dd0822caSmrg	if test -n "$postlink_cmds"; then
10734dd0822caSmrg	  func_to_tool_file "$output"
10735dd0822caSmrg	  postlink_cmds=`func_echo_all "$postlink_cmds" | $SED -e 's%@OUTPUT@%'"$output"'%g' -e 's%@TOOL_OUTPUT@%'"$func_to_tool_file_result"'%g'`
10736dd0822caSmrg	  func_execute_cmds "$postlink_cmds" 'exit $?'
10737dd0822caSmrg	fi
10738dd0822caSmrg
10739dc407927Smrg	exit $EXIT_SUCCESS
10740dc407927Smrg      fi
107413eed67faSmbalmer
107421a9c160aSmrg      case $hardcode_action,$fast_install in
107431a9c160aSmrg        relink,*)
107441a9c160aSmrg	  # Fast installation is not supported
107451a9c160aSmrg	  link_command=$compile_var$compile_command$compile_rpath
107461a9c160aSmrg	  relink_command=$finalize_var$finalize_command$finalize_rpath
107473eed67faSmbalmer
107481a9c160aSmrg	  func_warning "this platform does not like uninstalled shared libraries"
107491a9c160aSmrg	  func_warning "'$output' will be relinked during installation"
107501a9c160aSmrg	  ;;
107511a9c160aSmrg        *,yes)
107521a9c160aSmrg	  link_command=$finalize_var$compile_command$finalize_rpath
107531a9c160aSmrg	  relink_command=`$ECHO "$compile_var$compile_command$compile_rpath" | $SED 's%@OUTPUT@%\$progdir/\$file%g'`
107541a9c160aSmrg          ;;
107551a9c160aSmrg	*,no)
107561a9c160aSmrg	  link_command=$compile_var$compile_command$compile_rpath
107571a9c160aSmrg	  relink_command=$finalize_var$finalize_command$finalize_rpath
107581a9c160aSmrg          ;;
107591a9c160aSmrg	*,needless)
107601a9c160aSmrg	  link_command=$finalize_var$compile_command$finalize_rpath
107611a9c160aSmrg	  relink_command=
107621a9c160aSmrg          ;;
107631a9c160aSmrg      esac
107643eed67faSmbalmer
10765dc407927Smrg      # Replace the output file specification.
10766dd0822caSmrg      link_command=`$ECHO "$link_command" | $SED 's%@OUTPUT@%'"$output_objdir/$outputname"'%g'`
107673eed67faSmbalmer
10768dc407927Smrg      # Delete the old output files.
10769dc407927Smrg      $opt_dry_run || $RM $output $output_objdir/$outputname $output_objdir/lt-$outputname
107703eed67faSmbalmer
10771dc407927Smrg      func_show_eval "$link_command" 'exit $?'
107723eed67faSmbalmer
10773dd0822caSmrg      if test -n "$postlink_cmds"; then
10774dd0822caSmrg	func_to_tool_file "$output_objdir/$outputname"
10775dd0822caSmrg	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'`
10776dd0822caSmrg	func_execute_cmds "$postlink_cmds" 'exit $?'
10777dd0822caSmrg      fi
10778dd0822caSmrg
10779dc407927Smrg      # Now create the wrapper script.
10780dc407927Smrg      func_verbose "creating $output"
107813eed67faSmbalmer
10782dc407927Smrg      # Quote the relink command for shipping.
10783dc407927Smrg      if test -n "$relink_command"; then
10784dc407927Smrg	# Preserve any variables that may affect compiler behavior
10785dc407927Smrg	for var in $variables_saved_for_relink; do
10786dc407927Smrg	  if eval test -z \"\${$var+set}\"; then
10787dc407927Smrg	    relink_command="{ test -z \"\${$var+set}\" || $lt_unset $var || { $var=; export $var; }; }; $relink_command"
10788dc407927Smrg	  elif eval var_value=\$$var; test -z "$var_value"; then
10789dc407927Smrg	    relink_command="$var=; export $var; $relink_command"
10790dc407927Smrg	  else
10791621f50c3Smrg	    func_quote_arg pretty "$var_value"
10792621f50c3Smrg	    relink_command="$var=$func_quote_arg_result; export $var; $relink_command"
10793dc407927Smrg	  fi
10794dc407927Smrg	done
10795621f50c3Smrg	func_quote eval cd "`pwd`"
10796621f50c3Smrg	func_quote_arg pretty,unquoted "($func_quote_result; $relink_command)"
10797621f50c3Smrg	relink_command=$func_quote_arg_unquoted_result
10798dc407927Smrg      fi
107993eed67faSmbalmer
10800dc407927Smrg      # Only actually do things if not in dry run mode.
10801dc407927Smrg      $opt_dry_run || {
10802dc407927Smrg	# win32 will think the script is a binary if it has
10803dc407927Smrg	# a .exe suffix, so we strip it off here.
10804dc407927Smrg	case $output in
10805dc407927Smrg	  *.exe) func_stripname '' '.exe' "$output"
10806dc407927Smrg	         output=$func_stripname_result ;;
10807dc407927Smrg	esac
10808dc407927Smrg	# test for cygwin because mv fails w/o .exe extensions
108093eed67faSmbalmer	case $host in
10810dc407927Smrg	  *cygwin*)
10811dc407927Smrg	    exeext=.exe
10812dc407927Smrg	    func_stripname '' '.exe' "$outputname"
10813dc407927Smrg	    outputname=$func_stripname_result ;;
10814dc407927Smrg	  *) exeext= ;;
108153eed67faSmbalmer	esac
10816dc407927Smrg	case $host in
10817dc407927Smrg	  *cygwin* | *mingw* )
10818dc407927Smrg	    func_dirname_and_basename "$output" "" "."
10819dc407927Smrg	    output_name=$func_basename_result
10820dc407927Smrg	    output_path=$func_dirname_result
108211a9c160aSmrg	    cwrappersource=$output_path/$objdir/lt-$output_name.c
108221a9c160aSmrg	    cwrapper=$output_path/$output_name.exe
10823dc407927Smrg	    $RM $cwrappersource $cwrapper
10824dc407927Smrg	    trap "$RM $cwrappersource $cwrapper; exit $EXIT_FAILURE" 1 2 15
10825dc407927Smrg
10826dc407927Smrg	    func_emit_cwrapperexe_src > $cwrappersource
10827dc407927Smrg
10828dc407927Smrg	    # The wrapper executable is built using the $host compiler,
10829dc407927Smrg	    # because it contains $host paths and files. If cross-
10830dc407927Smrg	    # compiling, it, like the target executable, must be
10831dc407927Smrg	    # executed on the $host or under an emulation environment.
10832dc407927Smrg	    $opt_dry_run || {
10833dc407927Smrg	      $LTCC $LTCFLAGS -o $cwrapper $cwrappersource
10834dc407927Smrg	      $STRIP $cwrapper
10835dc407927Smrg	    }
10836dc407927Smrg
10837dc407927Smrg	    # Now, create the wrapper script for func_source use:
10838dc407927Smrg	    func_ltwrapper_scriptname $cwrapper
10839dc407927Smrg	    $RM $func_ltwrapper_scriptname_result
10840dc407927Smrg	    trap "$RM $func_ltwrapper_scriptname_result; exit $EXIT_FAILURE" 1 2 15
10841dc407927Smrg	    $opt_dry_run || {
10842dc407927Smrg	      # note: this script will not be executed, so do not chmod.
108431a9c160aSmrg	      if test "x$build" = "x$host"; then
10844dc407927Smrg		$cwrapper --lt-dump-script > $func_ltwrapper_scriptname_result
108453eed67faSmbalmer	      else
10846dc407927Smrg		func_emit_wrapper no > $func_ltwrapper_scriptname_result
108473eed67faSmbalmer	      fi
10848dc407927Smrg	    }
10849dc407927Smrg	  ;;
10850dc407927Smrg	  * )
10851dc407927Smrg	    $RM $output
10852dc407927Smrg	    trap "$RM $output; exit $EXIT_FAILURE" 1 2 15
108533eed67faSmbalmer
10854dc407927Smrg	    func_emit_wrapper no > $output
10855dc407927Smrg	    chmod +x $output
108563eed67faSmbalmer	  ;;
108573eed67faSmbalmer	esac
10858dc407927Smrg      }
10859dc407927Smrg      exit $EXIT_SUCCESS
10860dc407927Smrg      ;;
10861dc407927Smrg    esac
108623eed67faSmbalmer
10863dc407927Smrg    # See if we need to build an old-fashioned archive.
10864dc407927Smrg    for oldlib in $oldlibs; do
108653eed67faSmbalmer
108661a9c160aSmrg      case $build_libtool_libs in
108671a9c160aSmrg        convenience)
108681a9c160aSmrg	  oldobjs="$libobjs_save $symfileobj"
108691a9c160aSmrg	  addlibs=$convenience
10870dc407927Smrg	  build_libtool_libs=no
108711a9c160aSmrg	  ;;
108721a9c160aSmrg	module)
108731a9c160aSmrg	  oldobjs=$libobjs_save
108741a9c160aSmrg	  addlibs=$old_convenience
108751a9c160aSmrg	  build_libtool_libs=no
108761a9c160aSmrg          ;;
108771a9c160aSmrg	*)
10878dc407927Smrg	  oldobjs="$old_deplibs $non_pic_objects"
108791a9c160aSmrg	  $preload && test -f "$symfileobj" \
108801a9c160aSmrg	    && func_append oldobjs " $symfileobj"
108811a9c160aSmrg	  addlibs=$old_convenience
108821a9c160aSmrg	  ;;
108831a9c160aSmrg      esac
108843eed67faSmbalmer
10885dc407927Smrg      if test -n "$addlibs"; then
108861a9c160aSmrg	gentop=$output_objdir/${outputname}x
10887dd0822caSmrg	func_append generated " $gentop"
108883eed67faSmbalmer
10889dc407927Smrg	func_extract_archives $gentop $addlibs
10890dd0822caSmrg	func_append oldobjs " $func_extract_archives_result"
10891dc407927Smrg      fi
108923eed67faSmbalmer
10893dc407927Smrg      # Do each command in the archive commands.
108941a9c160aSmrg      if test -n "$old_archive_from_new_cmds" && test yes = "$build_libtool_libs"; then
10895dc407927Smrg	cmds=$old_archive_from_new_cmds
10896dc407927Smrg      else
108973eed67faSmbalmer
10898dc407927Smrg	# Add any objects from preloaded convenience libraries
10899dc407927Smrg	if test -n "$dlprefiles"; then
109001a9c160aSmrg	  gentop=$output_objdir/${outputname}x
10901dd0822caSmrg	  func_append generated " $gentop"
109023eed67faSmbalmer
10903dc407927Smrg	  func_extract_archives $gentop $dlprefiles
10904dd0822caSmrg	  func_append oldobjs " $func_extract_archives_result"
10905dc407927Smrg	fi
109063eed67faSmbalmer
10907dc407927Smrg	# POSIX demands no paths to be encoded in archives.  We have
10908dc407927Smrg	# to avoid creating archives with duplicate basenames if we
10909dc407927Smrg	# might have to extract them afterwards, e.g., when creating a
10910dc407927Smrg	# static archive out of a convenience library, or when linking
10911dc407927Smrg	# the entirety of a libtool archive into another (currently
10912dc407927Smrg	# not supported by libtool).
10913dc407927Smrg	if (for obj in $oldobjs
10914dc407927Smrg	    do
10915dc407927Smrg	      func_basename "$obj"
10916dc407927Smrg	      $ECHO "$func_basename_result"
10917dc407927Smrg	    done | sort | sort -uc >/dev/null 2>&1); then
10918dc407927Smrg	  :
10919dc407927Smrg	else
10920dd0822caSmrg	  echo "copying selected object files to avoid basename conflicts..."
109211a9c160aSmrg	  gentop=$output_objdir/${outputname}x
10922dd0822caSmrg	  func_append generated " $gentop"
10923dc407927Smrg	  func_mkdir_p "$gentop"
10924dc407927Smrg	  save_oldobjs=$oldobjs
10925dc407927Smrg	  oldobjs=
10926dc407927Smrg	  counter=1
10927dc407927Smrg	  for obj in $save_oldobjs
10928dc407927Smrg	  do
10929dc407927Smrg	    func_basename "$obj"
109301a9c160aSmrg	    objbase=$func_basename_result
10931dc407927Smrg	    case " $oldobjs " in
10932dc407927Smrg	    " ") oldobjs=$obj ;;
10933dc407927Smrg	    *[\ /]"$objbase "*)
10934dc407927Smrg	      while :; do
10935dc407927Smrg		# Make sure we don't pick an alternate name that also
10936dc407927Smrg		# overlaps.
10937dc407927Smrg		newobj=lt$counter-$objbase
10938dc407927Smrg		func_arith $counter + 1
10939dc407927Smrg		counter=$func_arith_result
10940dc407927Smrg		case " $oldobjs " in
10941dc407927Smrg		*[\ /]"$newobj "*) ;;
10942dc407927Smrg		*) if test ! -f "$gentop/$newobj"; then break; fi ;;
10943dc407927Smrg		esac
10944dc407927Smrg	      done
10945dc407927Smrg	      func_show_eval "ln $obj $gentop/$newobj || cp $obj $gentop/$newobj"
10946dd0822caSmrg	      func_append oldobjs " $gentop/$newobj"
10947dc407927Smrg	      ;;
10948dd0822caSmrg	    *) func_append oldobjs " $obj" ;;
10949dc407927Smrg	    esac
109503eed67faSmbalmer	  done
109513eed67faSmbalmer	fi
1095275cbef56Smrg	func_to_tool_file "$oldlib" func_convert_file_msys_to_w32
1095375cbef56Smrg	tool_oldlib=$func_to_tool_file_result
10954dc407927Smrg	eval cmds=\"$old_archive_cmds\"
109553eed67faSmbalmer
10956dc407927Smrg	func_len " $cmds"
10957dc407927Smrg	len=$func_len_result
10958dc407927Smrg	if test "$len" -lt "$max_cmd_len" || test "$max_cmd_len" -le -1; then
10959dc407927Smrg	  cmds=$old_archive_cmds
10960dd0822caSmrg	elif test -n "$archiver_list_spec"; then
10961dd0822caSmrg	  func_verbose "using command file archive linking..."
10962dd0822caSmrg	  for obj in $oldobjs
10963dd0822caSmrg	  do
10964dd0822caSmrg	    func_to_tool_file "$obj"
10965dd0822caSmrg	    $ECHO "$func_to_tool_file_result"
10966dd0822caSmrg	  done > $output_objdir/$libname.libcmd
10967dd0822caSmrg	  func_to_tool_file "$output_objdir/$libname.libcmd"
10968dd0822caSmrg	  oldobjs=" $archiver_list_spec$func_to_tool_file_result"
10969dd0822caSmrg	  cmds=$old_archive_cmds
10970dc407927Smrg	else
10971dc407927Smrg	  # the command line is too long to link in one step, link in parts
10972dc407927Smrg	  func_verbose "using piecewise archive linking..."
10973dc407927Smrg	  save_RANLIB=$RANLIB
10974dc407927Smrg	  RANLIB=:
10975dc407927Smrg	  objlist=
10976dc407927Smrg	  concat_cmds=
10977dc407927Smrg	  save_oldobjs=$oldobjs
10978dc407927Smrg	  oldobjs=
10979dc407927Smrg	  # Is there a better way of finding the last object in the list?
10980dc407927Smrg	  for obj in $save_oldobjs
10981dc407927Smrg	  do
10982dc407927Smrg	    last_oldobj=$obj
10983dc407927Smrg	  done
10984dc407927Smrg	  eval test_cmds=\"$old_archive_cmds\"
10985dc407927Smrg	  func_len " $test_cmds"
10986dc407927Smrg	  len0=$func_len_result
10987dc407927Smrg	  len=$len0
10988dc407927Smrg	  for obj in $save_oldobjs
10989dc407927Smrg	  do
10990dc407927Smrg	    func_len " $obj"
10991dc407927Smrg	    func_arith $len + $func_len_result
10992dc407927Smrg	    len=$func_arith_result
10993dc407927Smrg	    func_append objlist " $obj"
10994dc407927Smrg	    if test "$len" -lt "$max_cmd_len"; then
10995dc407927Smrg	      :
10996dc407927Smrg	    else
10997dc407927Smrg	      # the above command should be used before it gets too long
10998dc407927Smrg	      oldobjs=$objlist
109991a9c160aSmrg	      if test "$obj" = "$last_oldobj"; then
11000dc407927Smrg		RANLIB=$save_RANLIB
11001dc407927Smrg	      fi
11002dc407927Smrg	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
110031a9c160aSmrg	      eval concat_cmds=\"\$concat_cmds$old_archive_cmds\"
11004dc407927Smrg	      objlist=
11005dc407927Smrg	      len=$len0
11006dc407927Smrg	    fi
11007dc407927Smrg	  done
11008dc407927Smrg	  RANLIB=$save_RANLIB
11009dc407927Smrg	  oldobjs=$objlist
110101a9c160aSmrg	  if test -z "$oldobjs"; then
11011dc407927Smrg	    eval cmds=\"\$concat_cmds\"
11012dc407927Smrg	  else
11013dc407927Smrg	    eval cmds=\"\$concat_cmds~\$old_archive_cmds\"
11014dc407927Smrg	  fi
11015dc407927Smrg	fi
11016dc407927Smrg      fi
11017dc407927Smrg      func_execute_cmds "$cmds" 'exit $?'
11018dc407927Smrg    done
110193eed67faSmbalmer
11020dc407927Smrg    test -n "$generated" && \
11021dc407927Smrg      func_show_eval "${RM}r$generated"
110223eed67faSmbalmer
11023dc407927Smrg    # Now create the libtool archive.
11024dc407927Smrg    case $output in
11025dc407927Smrg    *.la)
11026dc407927Smrg      old_library=
110271a9c160aSmrg      test yes = "$build_old_libs" && old_library=$libname.$libext
11028dc407927Smrg      func_verbose "creating $output"
110293eed67faSmbalmer
11030dc407927Smrg      # Preserve any variables that may affect compiler behavior
11031dc407927Smrg      for var in $variables_saved_for_relink; do
11032dc407927Smrg	if eval test -z \"\${$var+set}\"; then
11033dc407927Smrg	  relink_command="{ test -z \"\${$var+set}\" || $lt_unset $var || { $var=; export $var; }; }; $relink_command"
11034dc407927Smrg	elif eval var_value=\$$var; test -z "$var_value"; then
11035dc407927Smrg	  relink_command="$var=; export $var; $relink_command"
110363eed67faSmbalmer	else
11037621f50c3Smrg	  func_quote_arg pretty,unquoted "$var_value"
11038621f50c3Smrg	  relink_command="$var=$func_quote_arg_unquoted_result; export $var; $relink_command"
110393eed67faSmbalmer	fi
11040dc407927Smrg      done
11041dc407927Smrg      # Quote the link command for shipping.
11042621f50c3Smrg      func_quote eval cd "`pwd`"
11043621f50c3Smrg      relink_command="($func_quote_result; $SHELL \"$progpath\" $preserve_args --mode=relink $libtool_args @inst_prefix_dir@)"
11044621f50c3Smrg      func_quote_arg pretty,unquoted "$relink_command"
11045621f50c3Smrg      relink_command=$func_quote_arg_unquoted_result
110461a9c160aSmrg      if test yes = "$hardcode_automatic"; then
11047dc407927Smrg	relink_command=
11048dc407927Smrg      fi
110493eed67faSmbalmer
11050dc407927Smrg      # Only create the output if not a dry run.
11051dc407927Smrg      $opt_dry_run || {
11052dc407927Smrg	for installed in no yes; do
110531a9c160aSmrg	  if test yes = "$installed"; then
11054dc407927Smrg	    if test -z "$install_libdir"; then
11055dc407927Smrg	      break
11056dc407927Smrg	    fi
110571a9c160aSmrg	    output=$output_objdir/${outputname}i
11058dc407927Smrg	    # Replace all uninstalled libtool libraries with the installed ones
11059dc407927Smrg	    newdependency_libs=
11060dc407927Smrg	    for deplib in $dependency_libs; do
11061dc407927Smrg	      case $deplib in
11062dc407927Smrg	      *.la)
11063dc407927Smrg		func_basename "$deplib"
110641a9c160aSmrg		name=$func_basename_result
1106575cbef56Smrg		func_resolve_sysroot "$deplib"
110661a9c160aSmrg		eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $func_resolve_sysroot_result`
11067dc407927Smrg		test -z "$libdir" && \
110681a9c160aSmrg		  func_fatal_error "'$deplib' is not a valid libtool archive"
11069dd0822caSmrg		func_append newdependency_libs " ${lt_sysroot:+=}$libdir/$name"
11070dd0822caSmrg		;;
11071dd0822caSmrg	      -L*)
11072dd0822caSmrg		func_stripname -L '' "$deplib"
11073dd0822caSmrg		func_replace_sysroot "$func_stripname_result"
11074dd0822caSmrg		func_append newdependency_libs " -L$func_replace_sysroot_result"
11075dc407927Smrg		;;
11076dd0822caSmrg	      -R*)
11077dd0822caSmrg		func_stripname -R '' "$deplib"
11078dd0822caSmrg		func_replace_sysroot "$func_stripname_result"
11079dd0822caSmrg		func_append newdependency_libs " -R$func_replace_sysroot_result"
11080dd0822caSmrg		;;
11081dd0822caSmrg	      *) func_append newdependency_libs " $deplib" ;;
11082dc407927Smrg	      esac
11083dc407927Smrg	    done
110841a9c160aSmrg	    dependency_libs=$newdependency_libs
11085dc407927Smrg	    newdlfiles=
11086dc407927Smrg
11087dc407927Smrg	    for lib in $dlfiles; do
11088dc407927Smrg	      case $lib in
11089dc407927Smrg	      *.la)
11090dc407927Smrg	        func_basename "$lib"
110911a9c160aSmrg		name=$func_basename_result
110921a9c160aSmrg		eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $lib`
11093dc407927Smrg		test -z "$libdir" && \
110941a9c160aSmrg		  func_fatal_error "'$lib' is not a valid libtool archive"
11095dd0822caSmrg		func_append newdlfiles " ${lt_sysroot:+=}$libdir/$name"
11096dc407927Smrg		;;
11097dd0822caSmrg	      *) func_append newdlfiles " $lib" ;;
11098dc407927Smrg	      esac
11099dc407927Smrg	    done
111001a9c160aSmrg	    dlfiles=$newdlfiles
11101dc407927Smrg	    newdlprefiles=
11102dc407927Smrg	    for lib in $dlprefiles; do
11103dc407927Smrg	      case $lib in
11104dc407927Smrg	      *.la)
11105dc407927Smrg		# Only pass preopened files to the pseudo-archive (for
11106dc407927Smrg		# eventual linking with the app. that links it) if we
11107dc407927Smrg		# didn't already link the preopened objects directly into
11108dc407927Smrg		# the library:
11109dc407927Smrg		func_basename "$lib"
111101a9c160aSmrg		name=$func_basename_result
111111a9c160aSmrg		eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $lib`
11112dc407927Smrg		test -z "$libdir" && \
111131a9c160aSmrg		  func_fatal_error "'$lib' is not a valid libtool archive"
11114dd0822caSmrg		func_append newdlprefiles " ${lt_sysroot:+=}$libdir/$name"
11115dc407927Smrg		;;
11116dc407927Smrg	      esac
11117dc407927Smrg	    done
111181a9c160aSmrg	    dlprefiles=$newdlprefiles
11119dc407927Smrg	  else
11120dc407927Smrg	    newdlfiles=
11121dc407927Smrg	    for lib in $dlfiles; do
11122dc407927Smrg	      case $lib in
111231a9c160aSmrg		[\\/]* | [A-Za-z]:[\\/]*) abs=$lib ;;
11124dc407927Smrg		*) abs=`pwd`"/$lib" ;;
11125dc407927Smrg	      esac
11126dd0822caSmrg	      func_append newdlfiles " $abs"
11127dc407927Smrg	    done
111281a9c160aSmrg	    dlfiles=$newdlfiles
11129dc407927Smrg	    newdlprefiles=
11130dc407927Smrg	    for lib in $dlprefiles; do
11131dc407927Smrg	      case $lib in
111321a9c160aSmrg		[\\/]* | [A-Za-z]:[\\/]*) abs=$lib ;;
11133dc407927Smrg		*) abs=`pwd`"/$lib" ;;
11134dc407927Smrg	      esac
11135dd0822caSmrg	      func_append newdlprefiles " $abs"
11136dc407927Smrg	    done
111371a9c160aSmrg	    dlprefiles=$newdlprefiles
11138dc407927Smrg	  fi
11139dc407927Smrg	  $RM $output
11140dc407927Smrg	  # place dlname in correct position for cygwin
11141dd0822caSmrg	  # In fact, it would be nice if we could use this code for all target
11142dd0822caSmrg	  # systems that can't hard-code library paths into their executables
11143dd0822caSmrg	  # and that have no shared library path variable independent of PATH,
11144dd0822caSmrg	  # but it turns out we can't easily determine that from inspecting
11145dd0822caSmrg	  # libtool variables, so we have to hard-code the OSs to which it
11146dd0822caSmrg	  # applies here; at the moment, that means platforms that use the PE
11147dd0822caSmrg	  # object format with DLL files.  See the long comment at the top of
11148dd0822caSmrg	  # tests/bindir.at for full details.
11149dc407927Smrg	  tdlname=$dlname
11150dc407927Smrg	  case $host,$output,$installed,$module,$dlname in
11151dd0822caSmrg	    *cygwin*,*lai,yes,no,*.dll | *mingw*,*lai,yes,no,*.dll | *cegcc*,*lai,yes,no,*.dll)
11152dd0822caSmrg	      # If a -bindir argument was supplied, place the dll there.
111531a9c160aSmrg	      if test -n "$bindir"; then
11154dd0822caSmrg		func_relative_path "$install_libdir" "$bindir"
111551a9c160aSmrg		tdlname=$func_relative_path_result/$dlname
11156dd0822caSmrg	      else
11157dd0822caSmrg		# Otherwise fall back on heuristic.
11158dd0822caSmrg		tdlname=../bin/$dlname
11159dd0822caSmrg	      fi
11160dd0822caSmrg	      ;;
11161dc407927Smrg	  esac
11162dc407927Smrg	  $ECHO > $output "\
11163dc407927Smrg# $outputname - a libtool library file
111641a9c160aSmrg# Generated by $PROGRAM (GNU $PACKAGE) $VERSION
11165dc407927Smrg#
11166dc407927Smrg# Please DO NOT delete this file!
11167dc407927Smrg# It is necessary for linking the library.
111683eed67faSmbalmer
11169dc407927Smrg# The name that we can dlopen(3).
11170dc407927Smrgdlname='$tdlname'
111713eed67faSmbalmer
11172dc407927Smrg# Names of this library.
11173dc407927Smrglibrary_names='$library_names'
111743eed67faSmbalmer
11175dc407927Smrg# The name of the static archive.
11176dc407927Smrgold_library='$old_library'
111773eed67faSmbalmer
111781a9c160aSmrg# Linker flags that cannot go in dependency_libs.
11179dc407927Smrginherited_linker_flags='$new_inherited_linker_flags'
111803eed67faSmbalmer
11181dc407927Smrg# Libraries that this one depends upon.
11182dc407927Smrgdependency_libs='$dependency_libs'
111833eed67faSmbalmer
11184dc407927Smrg# Names of additional weak libraries provided by this library
11185dc407927Smrgweak_library_names='$weak_libs'
111863eed67faSmbalmer
11187dc407927Smrg# Version information for $libname.
11188dc407927Smrgcurrent=$current
11189dc407927Smrgage=$age
11190dc407927Smrgrevision=$revision
111913eed67faSmbalmer
11192dc407927Smrg# Is this an already installed library?
11193dc407927Smrginstalled=$installed
111943eed67faSmbalmer
11195dc407927Smrg# Should we warn about portability when linking against -modules?
11196dc407927Smrgshouldnotlink=$module
111973eed67faSmbalmer
11198dc407927Smrg# Files to dlopen/dlpreopen
11199dc407927Smrgdlopen='$dlfiles'
11200dc407927Smrgdlpreopen='$dlprefiles'
112013eed67faSmbalmer
11202dc407927Smrg# Directory that this library needs to be installed in:
11203dc407927Smrglibdir='$install_libdir'"
112041a9c160aSmrg	  if test no,yes = "$installed,$need_relink"; then
11205dc407927Smrg	    $ECHO >> $output "\
11206dc407927Smrgrelink_command=\"$relink_command\""
11207dc407927Smrg	  fi
11208dc407927Smrg	done
11209dc407927Smrg      }
112103eed67faSmbalmer
11211dc407927Smrg      # Do a symbolic link so that the libtool archive can be found in
11212dc407927Smrg      # LD_LIBRARY_PATH before the program is installed.
11213dc407927Smrg      func_show_eval '( cd "$output_objdir" && $RM "$outputname" && $LN_S "../$outputname" "$outputname" )' 'exit $?'
11214dc407927Smrg      ;;
11215dc407927Smrg    esac
11216dc407927Smrg    exit $EXIT_SUCCESS
11217dc407927Smrg}
112183eed67faSmbalmer
112191a9c160aSmrgif test link = "$opt_mode" || test relink = "$opt_mode"; then
112201a9c160aSmrg  func_mode_link ${1+"$@"}
112211a9c160aSmrgfi
112223eed67faSmbalmer
112233eed67faSmbalmer
11224dc407927Smrg# func_mode_uninstall arg...
11225dc407927Smrgfunc_mode_uninstall ()
11226dc407927Smrg{
112271a9c160aSmrg    $debug_cmd
112281a9c160aSmrg
112291a9c160aSmrg    RM=$nonopt
112303eed67faSmbalmer    files=
112311a9c160aSmrg    rmforce=false
112323eed67faSmbalmer    exit_status=0
112333eed67faSmbalmer
112343eed67faSmbalmer    # This variable tells wrapper scripts just to set variables rather
112353eed67faSmbalmer    # than running their programs.
112361a9c160aSmrg    libtool_install_magic=$magic
112373eed67faSmbalmer
112383eed67faSmbalmer    for arg
112393eed67faSmbalmer    do
112403eed67faSmbalmer      case $arg in
112411a9c160aSmrg      -f) func_append RM " $arg"; rmforce=: ;;
11242dd0822caSmrg      -*) func_append RM " $arg" ;;
11243dd0822caSmrg      *) func_append files " $arg" ;;
112443eed67faSmbalmer      esac
112453eed67faSmbalmer    done
112463eed67faSmbalmer
11247dc407927Smrg    test -z "$RM" && \
11248dc407927Smrg      func_fatal_help "you must specify an RM program"
112493eed67faSmbalmer
112503eed67faSmbalmer    rmdirs=
112513eed67faSmbalmer
112523eed67faSmbalmer    for file in $files; do
11253dc407927Smrg      func_dirname "$file" "" "."
112541a9c160aSmrg      dir=$func_dirname_result
112551a9c160aSmrg      if test . = "$dir"; then
112561a9c160aSmrg	odir=$objdir
112573eed67faSmbalmer      else
112581a9c160aSmrg	odir=$dir/$objdir
112593eed67faSmbalmer      fi
11260dc407927Smrg      func_basename "$file"
112611a9c160aSmrg      name=$func_basename_result
112621a9c160aSmrg      test uninstall = "$opt_mode" && odir=$dir
112633eed67faSmbalmer
11264dd0822caSmrg      # Remember odir for removal later, being careful to avoid duplicates
112651a9c160aSmrg      if test clean = "$opt_mode"; then
112663eed67faSmbalmer	case " $rmdirs " in
11267dd0822caSmrg	  *" $odir "*) ;;
11268dd0822caSmrg	  *) func_append rmdirs " $odir" ;;
112693eed67faSmbalmer	esac
112703eed67faSmbalmer      fi
112713eed67faSmbalmer
112723eed67faSmbalmer      # Don't error if the file doesn't exist and rm -f was used.
11273dc407927Smrg      if { test -L "$file"; } >/dev/null 2>&1 ||
11274dc407927Smrg	 { test -h "$file"; } >/dev/null 2>&1 ||
11275dc407927Smrg	 test -f "$file"; then
112763eed67faSmbalmer	:
112773eed67faSmbalmer      elif test -d "$file"; then
112783eed67faSmbalmer	exit_status=1
112793eed67faSmbalmer	continue
112801a9c160aSmrg      elif $rmforce; then
112813eed67faSmbalmer	continue
112823eed67faSmbalmer      fi
112833eed67faSmbalmer
112841a9c160aSmrg      rmfiles=$file
112853eed67faSmbalmer
112863eed67faSmbalmer      case $name in
112873eed67faSmbalmer      *.la)
112883eed67faSmbalmer	# Possibly a libtool archive, so verify it.
11289dc407927Smrg	if func_lalib_p "$file"; then
11290dc407927Smrg	  func_source $dir/$name
112913eed67faSmbalmer
112923eed67faSmbalmer	  # Delete the libtool libraries and symlinks.
112933eed67faSmbalmer	  for n in $library_names; do
11294dd0822caSmrg	    func_append rmfiles " $odir/$n"
112953eed67faSmbalmer	  done
11296dd0822caSmrg	  test -n "$old_library" && func_append rmfiles " $odir/$old_library"
112973eed67faSmbalmer
112981a9c160aSmrg	  case $opt_mode in
112993eed67faSmbalmer	  clean)
11300dd0822caSmrg	    case " $library_names " in
113013eed67faSmbalmer	    *" $dlname "*) ;;
11302dd0822caSmrg	    *) test -n "$dlname" && func_append rmfiles " $odir/$dlname" ;;
113033eed67faSmbalmer	    esac
11304dd0822caSmrg	    test -n "$libdir" && func_append rmfiles " $odir/$name $odir/${name}i"
113053eed67faSmbalmer	    ;;
113063eed67faSmbalmer	  uninstall)
113073eed67faSmbalmer	    if test -n "$library_names"; then
113083eed67faSmbalmer	      # Do each command in the postuninstall commands.
113091a9c160aSmrg	      func_execute_cmds "$postuninstall_cmds" '$rmforce || exit_status=1'
113103eed67faSmbalmer	    fi
113113eed67faSmbalmer
113123eed67faSmbalmer	    if test -n "$old_library"; then
113133eed67faSmbalmer	      # Do each command in the old_postuninstall commands.
113141a9c160aSmrg	      func_execute_cmds "$old_postuninstall_cmds" '$rmforce || exit_status=1'
113153eed67faSmbalmer	    fi
113163eed67faSmbalmer	    # FIXME: should reinstall the best remaining shared library.
113173eed67faSmbalmer	    ;;
113183eed67faSmbalmer	  esac
113193eed67faSmbalmer	fi
113203eed67faSmbalmer	;;
113213eed67faSmbalmer
113223eed67faSmbalmer      *.lo)
113233eed67faSmbalmer	# Possibly a libtool object, so verify it.
11324dc407927Smrg	if func_lalib_p "$file"; then
113253eed67faSmbalmer
113263eed67faSmbalmer	  # Read the .lo file
11327dc407927Smrg	  func_source $dir/$name
113283eed67faSmbalmer
113293eed67faSmbalmer	  # Add PIC object to the list of files to remove.
113301a9c160aSmrg	  if test -n "$pic_object" && test none != "$pic_object"; then
11331dd0822caSmrg	    func_append rmfiles " $dir/$pic_object"
113323eed67faSmbalmer	  fi
113333eed67faSmbalmer
113343eed67faSmbalmer	  # Add non-PIC object to the list of files to remove.
113351a9c160aSmrg	  if test -n "$non_pic_object" && test none != "$non_pic_object"; then
11336dd0822caSmrg	    func_append rmfiles " $dir/$non_pic_object"
113373eed67faSmbalmer	  fi
113383eed67faSmbalmer	fi
113393eed67faSmbalmer	;;
113403eed67faSmbalmer
113413eed67faSmbalmer      *)
113421a9c160aSmrg	if test clean = "$opt_mode"; then
113433eed67faSmbalmer	  noexename=$name
113443eed67faSmbalmer	  case $file in
113453eed67faSmbalmer	  *.exe)
11346dc407927Smrg	    func_stripname '' '.exe' "$file"
11347dc407927Smrg	    file=$func_stripname_result
11348dc407927Smrg	    func_stripname '' '.exe' "$name"
11349dc407927Smrg	    noexename=$func_stripname_result
113503eed67faSmbalmer	    # $file with .exe has already been added to rmfiles,
113513eed67faSmbalmer	    # add $file without .exe
11352dd0822caSmrg	    func_append rmfiles " $file"
113533eed67faSmbalmer	    ;;
113543eed67faSmbalmer	  esac
113553eed67faSmbalmer	  # Do a test to see if this is a libtool program.
11356dc407927Smrg	  if func_ltwrapper_p "$file"; then
11357dc407927Smrg	    if func_ltwrapper_executable_p "$file"; then
11358dc407927Smrg	      func_ltwrapper_scriptname "$file"
11359dc407927Smrg	      relink_command=
11360dc407927Smrg	      func_source $func_ltwrapper_scriptname_result
11361dd0822caSmrg	      func_append rmfiles " $func_ltwrapper_scriptname_result"
11362dc407927Smrg	    else
11363dc407927Smrg	      relink_command=
11364dc407927Smrg	      func_source $dir/$noexename
11365dc407927Smrg	    fi
113663eed67faSmbalmer
113673eed67faSmbalmer	    # note $name still contains .exe if it was in $file originally
113683eed67faSmbalmer	    # as does the version of $file that was added into $rmfiles
113691a9c160aSmrg	    func_append rmfiles " $odir/$name $odir/${name}S.$objext"
113701a9c160aSmrg	    if test yes = "$fast_install" && test -n "$relink_command"; then
11371dd0822caSmrg	      func_append rmfiles " $odir/lt-$name"
113723eed67faSmbalmer	    fi
113731a9c160aSmrg	    if test "X$noexename" != "X$name"; then
113741a9c160aSmrg	      func_append rmfiles " $odir/lt-$noexename.c"
113753eed67faSmbalmer	    fi
113763eed67faSmbalmer	  fi
113773eed67faSmbalmer	fi
113783eed67faSmbalmer	;;
113793eed67faSmbalmer      esac
11380dc407927Smrg      func_show_eval "$RM $rmfiles" 'exit_status=1'
113813eed67faSmbalmer    done
113823eed67faSmbalmer
113831a9c160aSmrg    # Try to remove the $objdir's in the directories where we deleted files
113843eed67faSmbalmer    for dir in $rmdirs; do
113853eed67faSmbalmer      if test -d "$dir"; then
11386dc407927Smrg	func_show_eval "rmdir $dir >/dev/null 2>&1"
113873eed67faSmbalmer      fi
113883eed67faSmbalmer    done
113893eed67faSmbalmer
113903eed67faSmbalmer    exit $exit_status
11391dc407927Smrg}
113923eed67faSmbalmer
113931a9c160aSmrgif test uninstall = "$opt_mode" || test clean = "$opt_mode"; then
113941a9c160aSmrg  func_mode_uninstall ${1+"$@"}
113951a9c160aSmrgfi
113963eed67faSmbalmer
11397dd0822caSmrgtest -z "$opt_mode" && {
113981a9c160aSmrg  help=$generic_help
11399dc407927Smrg  func_fatal_help "you must specify a MODE"
11400dc407927Smrg}
11401dc407927Smrg
11402dc407927Smrgtest -z "$exec_cmd" && \
114031a9c160aSmrg  func_fatal_help "invalid operation mode '$opt_mode'"
114043eed67faSmbalmer
114053eed67faSmbalmerif test -n "$exec_cmd"; then
11406dc407927Smrg  eval exec "$exec_cmd"
114073eed67faSmbalmer  exit $EXIT_FAILURE
114083eed67faSmbalmerfi
114093eed67faSmbalmer
11410dc407927Smrgexit $exit_status
114113eed67faSmbalmer
114123eed67faSmbalmer
114133eed67faSmbalmer# The TAGs below are defined such that we never get into a situation
114141a9c160aSmrg# where we disable both kinds of libraries.  Given conflicting
114153eed67faSmbalmer# choices, we go for a static library, that is the most portable,
114163eed67faSmbalmer# since we can't tell whether shared libraries were disabled because
114173eed67faSmbalmer# the user asked for that or because the platform doesn't support
114183eed67faSmbalmer# them.  This is particularly important on AIX, because we don't
114193eed67faSmbalmer# support having both static and shared libraries enabled at the same
114203eed67faSmbalmer# time on that platform, so we default to a shared-only configuration.
114213eed67faSmbalmer# If a disable-shared tag is given, we'll fallback to a static-only
114223eed67faSmbalmer# configuration.  But we'll never go from static-only to shared-only.
114233eed67faSmbalmer
114243eed67faSmbalmer# ### BEGIN LIBTOOL TAG CONFIG: disable-shared
11425dc407927Smrgbuild_libtool_libs=no
11426dc407927Smrgbuild_old_libs=yes
114273eed67faSmbalmer# ### END LIBTOOL TAG CONFIG: disable-shared
114283eed67faSmbalmer
114293eed67faSmbalmer# ### BEGIN LIBTOOL TAG CONFIG: disable-static
11430dc407927Smrgbuild_old_libs=`case $build_libtool_libs in yes) echo no;; *) echo yes;; esac`
114313eed67faSmbalmer# ### END LIBTOOL TAG CONFIG: disable-static
114323eed67faSmbalmer
114333eed67faSmbalmer# Local Variables:
114343eed67faSmbalmer# mode:shell-script
114353eed67faSmbalmer# sh-indentation:2
114363eed67faSmbalmer# End:
11437