xref: /aosp_15_r20/external/flac/m4/lib-link.m4 (revision 600f14f40d737144c998e2ec7a483122d3776fbc)
1*600f14f4SXin Li# lib-link.m4 serial 26 (gettext-0.18.2)
2*600f14f4SXin Lidnl Copyright (C) 2001-2012 Free Software Foundation, Inc.
3*600f14f4SXin Lidnl This file is free software; the Free Software Foundation
4*600f14f4SXin Lidnl gives unlimited permission to copy and/or distribute it,
5*600f14f4SXin Lidnl with or without modifications, as long as this notice is preserved.
6*600f14f4SXin Li
7*600f14f4SXin Lidnl From Bruno Haible.
8*600f14f4SXin Li
9*600f14f4SXin LiAC_PREREQ([2.54])
10*600f14f4SXin Li
11*600f14f4SXin Lidnl AC_LIB_LINKFLAGS(name [, dependencies]) searches for libname and
12*600f14f4SXin Lidnl the libraries corresponding to explicit and implicit dependencies.
13*600f14f4SXin Lidnl Sets and AC_SUBSTs the LIB${NAME} and LTLIB${NAME} variables and
14*600f14f4SXin Lidnl augments the CPPFLAGS variable.
15*600f14f4SXin Lidnl Sets and AC_SUBSTs the LIB${NAME}_PREFIX variable to nonempty if libname
16*600f14f4SXin Lidnl was found in ${LIB${NAME}_PREFIX}/$acl_libdirstem.
17*600f14f4SXin LiAC_DEFUN([AC_LIB_LINKFLAGS],
18*600f14f4SXin Li[
19*600f14f4SXin Li  AC_REQUIRE([AC_LIB_PREPARE_PREFIX])
20*600f14f4SXin Li  AC_REQUIRE([AC_LIB_RPATH])
21*600f14f4SXin Li  pushdef([Name],[m4_translit([$1],[./+-], [____])])
22*600f14f4SXin Li  pushdef([NAME],[m4_translit([$1],[abcdefghijklmnopqrstuvwxyz./+-],
23*600f14f4SXin Li                                   [ABCDEFGHIJKLMNOPQRSTUVWXYZ____])])
24*600f14f4SXin Li  AC_CACHE_CHECK([how to link with lib[]$1], [ac_cv_lib[]Name[]_libs], [
25*600f14f4SXin Li    AC_LIB_LINKFLAGS_BODY([$1], [$2])
26*600f14f4SXin Li    ac_cv_lib[]Name[]_libs="$LIB[]NAME"
27*600f14f4SXin Li    ac_cv_lib[]Name[]_ltlibs="$LTLIB[]NAME"
28*600f14f4SXin Li    ac_cv_lib[]Name[]_cppflags="$INC[]NAME"
29*600f14f4SXin Li    ac_cv_lib[]Name[]_prefix="$LIB[]NAME[]_PREFIX"
30*600f14f4SXin Li  ])
31*600f14f4SXin Li  LIB[]NAME="$ac_cv_lib[]Name[]_libs"
32*600f14f4SXin Li  LTLIB[]NAME="$ac_cv_lib[]Name[]_ltlibs"
33*600f14f4SXin Li  INC[]NAME="$ac_cv_lib[]Name[]_cppflags"
34*600f14f4SXin Li  LIB[]NAME[]_PREFIX="$ac_cv_lib[]Name[]_prefix"
35*600f14f4SXin Li  AC_LIB_APPENDTOVAR([CPPFLAGS], [$INC]NAME)
36*600f14f4SXin Li  AC_SUBST([LIB]NAME)
37*600f14f4SXin Li  AC_SUBST([LTLIB]NAME)
38*600f14f4SXin Li  AC_SUBST([LIB]NAME[_PREFIX])
39*600f14f4SXin Li  dnl Also set HAVE_LIB[]NAME so that AC_LIB_HAVE_LINKFLAGS can reuse the
40*600f14f4SXin Li  dnl results of this search when this library appears as a dependency.
41*600f14f4SXin Li  HAVE_LIB[]NAME=yes
42*600f14f4SXin Li  popdef([NAME])
43*600f14f4SXin Li  popdef([Name])
44*600f14f4SXin Li])
45*600f14f4SXin Li
46*600f14f4SXin Lidnl AC_LIB_HAVE_LINKFLAGS(name, dependencies, includes, testcode, [missing-message])
47*600f14f4SXin Lidnl searches for libname and the libraries corresponding to explicit and
48*600f14f4SXin Lidnl implicit dependencies, together with the specified include files and
49*600f14f4SXin Lidnl the ability to compile and link the specified testcode. The missing-message
50*600f14f4SXin Lidnl defaults to 'no' and may contain additional hints for the user.
51*600f14f4SXin Lidnl If found, it sets and AC_SUBSTs HAVE_LIB${NAME}=yes and the LIB${NAME}
52*600f14f4SXin Lidnl and LTLIB${NAME} variables and augments the CPPFLAGS variable, and
53*600f14f4SXin Lidnl #defines HAVE_LIB${NAME} to 1. Otherwise, it sets and AC_SUBSTs
54*600f14f4SXin Lidnl HAVE_LIB${NAME}=no and LIB${NAME} and LTLIB${NAME} to empty.
55*600f14f4SXin Lidnl Sets and AC_SUBSTs the LIB${NAME}_PREFIX variable to nonempty if libname
56*600f14f4SXin Lidnl was found in ${LIB${NAME}_PREFIX}/$acl_libdirstem.
57*600f14f4SXin LiAC_DEFUN([AC_LIB_HAVE_LINKFLAGS],
58*600f14f4SXin Li[
59*600f14f4SXin Li  AC_REQUIRE([AC_LIB_PREPARE_PREFIX])
60*600f14f4SXin Li  AC_REQUIRE([AC_LIB_RPATH])
61*600f14f4SXin Li  pushdef([Name],[m4_translit([$1],[./+-], [____])])
62*600f14f4SXin Li  pushdef([NAME],[m4_translit([$1],[abcdefghijklmnopqrstuvwxyz./+-],
63*600f14f4SXin Li                                   [ABCDEFGHIJKLMNOPQRSTUVWXYZ____])])
64*600f14f4SXin Li
65*600f14f4SXin Li  dnl Search for lib[]Name and define LIB[]NAME, LTLIB[]NAME and INC[]NAME
66*600f14f4SXin Li  dnl accordingly.
67*600f14f4SXin Li  AC_LIB_LINKFLAGS_BODY([$1], [$2])
68*600f14f4SXin Li
69*600f14f4SXin Li  dnl Add $INC[]NAME to CPPFLAGS before performing the following checks,
70*600f14f4SXin Li  dnl because if the user has installed lib[]Name and not disabled its use
71*600f14f4SXin Li  dnl via --without-lib[]Name-prefix, he wants to use it.
72*600f14f4SXin Li  ac_save_CPPFLAGS="$CPPFLAGS"
73*600f14f4SXin Li  AC_LIB_APPENDTOVAR([CPPFLAGS], [$INC]NAME)
74*600f14f4SXin Li
75*600f14f4SXin Li  AC_CACHE_CHECK([for lib[]$1], [ac_cv_lib[]Name], [
76*600f14f4SXin Li    ac_save_LIBS="$LIBS"
77*600f14f4SXin Li    dnl If $LIB[]NAME contains some -l options, add it to the end of LIBS,
78*600f14f4SXin Li    dnl because these -l options might require -L options that are present in
79*600f14f4SXin Li    dnl LIBS. -l options benefit only from the -L options listed before it.
80*600f14f4SXin Li    dnl Otherwise, add it to the front of LIBS, because it may be a static
81*600f14f4SXin Li    dnl library that depends on another static library that is present in LIBS.
82*600f14f4SXin Li    dnl Static libraries benefit only from the static libraries listed after
83*600f14f4SXin Li    dnl it.
84*600f14f4SXin Li    case " $LIB[]NAME" in
85*600f14f4SXin Li      *" -l"*) LIBS="$LIBS $LIB[]NAME" ;;
86*600f14f4SXin Li      *)       LIBS="$LIB[]NAME $LIBS" ;;
87*600f14f4SXin Li    esac
88*600f14f4SXin Li    AC_LINK_IFELSE(
89*600f14f4SXin Li      [AC_LANG_PROGRAM([[$3]], [[$4]])],
90*600f14f4SXin Li      [ac_cv_lib[]Name=yes],
91*600f14f4SXin Li      [ac_cv_lib[]Name='m4_if([$5], [], [no], [[$5]])'])
92*600f14f4SXin Li    LIBS="$ac_save_LIBS"
93*600f14f4SXin Li  ])
94*600f14f4SXin Li  if test "$ac_cv_lib[]Name" = yes; then
95*600f14f4SXin Li    HAVE_LIB[]NAME=yes
96*600f14f4SXin Li    AC_DEFINE([HAVE_LIB]NAME, 1, [Define if you have the lib][$1 library.])
97*600f14f4SXin Li    AC_MSG_CHECKING([how to link with lib[]$1])
98*600f14f4SXin Li    AC_MSG_RESULT([$LIB[]NAME])
99*600f14f4SXin Li  else
100*600f14f4SXin Li    HAVE_LIB[]NAME=no
101*600f14f4SXin Li    dnl If $LIB[]NAME didn't lead to a usable library, we don't need
102*600f14f4SXin Li    dnl $INC[]NAME either.
103*600f14f4SXin Li    CPPFLAGS="$ac_save_CPPFLAGS"
104*600f14f4SXin Li    LIB[]NAME=
105*600f14f4SXin Li    LTLIB[]NAME=
106*600f14f4SXin Li    LIB[]NAME[]_PREFIX=
107*600f14f4SXin Li  fi
108*600f14f4SXin Li  AC_SUBST([HAVE_LIB]NAME)
109*600f14f4SXin Li  AC_SUBST([LIB]NAME)
110*600f14f4SXin Li  AC_SUBST([LTLIB]NAME)
111*600f14f4SXin Li  AC_SUBST([LIB]NAME[_PREFIX])
112*600f14f4SXin Li  popdef([NAME])
113*600f14f4SXin Li  popdef([Name])
114*600f14f4SXin Li])
115*600f14f4SXin Li
116*600f14f4SXin Lidnl Determine the platform dependent parameters needed to use rpath:
117*600f14f4SXin Lidnl   acl_libext,
118*600f14f4SXin Lidnl   acl_shlibext,
119*600f14f4SXin Lidnl   acl_libname_spec,
120*600f14f4SXin Lidnl   acl_library_names_spec,
121*600f14f4SXin Lidnl   acl_hardcode_libdir_flag_spec,
122*600f14f4SXin Lidnl   acl_hardcode_libdir_separator,
123*600f14f4SXin Lidnl   acl_hardcode_direct,
124*600f14f4SXin Lidnl   acl_hardcode_minus_L.
125*600f14f4SXin LiAC_DEFUN([AC_LIB_RPATH],
126*600f14f4SXin Li[
127*600f14f4SXin Li  dnl Tell automake >= 1.10 to complain if config.rpath is missing.
128*600f14f4SXin Li  m4_ifdef([AC_REQUIRE_AUX_FILE], [AC_REQUIRE_AUX_FILE([config.rpath])])
129*600f14f4SXin Li  AC_REQUIRE([AC_PROG_CC])                dnl we use $CC, $GCC, $LDFLAGS
130*600f14f4SXin Li  AC_REQUIRE([AC_LIB_PROG_LD])            dnl we use $LD, $with_gnu_ld
131*600f14f4SXin Li  AC_REQUIRE([AC_CANONICAL_HOST])         dnl we use $host
132*600f14f4SXin Li  AC_REQUIRE([AC_CONFIG_AUX_DIR_DEFAULT]) dnl we use $ac_aux_dir
133*600f14f4SXin Li  AC_CACHE_CHECK([for shared library run path origin], [acl_cv_rpath], [
134*600f14f4SXin Li    CC="$CC" GCC="$GCC" LDFLAGS="$LDFLAGS" LD="$LD" with_gnu_ld="$with_gnu_ld" \
135*600f14f4SXin Li    ${CONFIG_SHELL-/bin/sh} "$ac_aux_dir/config.rpath" "$host" > conftest.sh
136*600f14f4SXin Li    . ./conftest.sh
137*600f14f4SXin Li    rm -f ./conftest.sh
138*600f14f4SXin Li    acl_cv_rpath=done
139*600f14f4SXin Li  ])
140*600f14f4SXin Li  wl="$acl_cv_wl"
141*600f14f4SXin Li  acl_libext="$acl_cv_libext"
142*600f14f4SXin Li  acl_shlibext="$acl_cv_shlibext"
143*600f14f4SXin Li  acl_libname_spec="$acl_cv_libname_spec"
144*600f14f4SXin Li  acl_library_names_spec="$acl_cv_library_names_spec"
145*600f14f4SXin Li  acl_hardcode_libdir_flag_spec="$acl_cv_hardcode_libdir_flag_spec"
146*600f14f4SXin Li  acl_hardcode_libdir_separator="$acl_cv_hardcode_libdir_separator"
147*600f14f4SXin Li  acl_hardcode_direct="$acl_cv_hardcode_direct"
148*600f14f4SXin Li  acl_hardcode_minus_L="$acl_cv_hardcode_minus_L"
149*600f14f4SXin Li  dnl Determine whether the user wants rpath handling at all.
150*600f14f4SXin Li  AC_ARG_ENABLE([rpath],
151*600f14f4SXin Li    [  --disable-rpath         do not hardcode runtime library paths],
152*600f14f4SXin Li    :, enable_rpath=yes)
153*600f14f4SXin Li])
154*600f14f4SXin Li
155*600f14f4SXin Lidnl AC_LIB_FROMPACKAGE(name, package)
156*600f14f4SXin Lidnl declares that libname comes from the given package. The configure file
157*600f14f4SXin Lidnl will then not have a --with-libname-prefix option but a
158*600f14f4SXin Lidnl --with-package-prefix option. Several libraries can come from the same
159*600f14f4SXin Lidnl package. This declaration must occur before an AC_LIB_LINKFLAGS or similar
160*600f14f4SXin Lidnl macro call that searches for libname.
161*600f14f4SXin LiAC_DEFUN([AC_LIB_FROMPACKAGE],
162*600f14f4SXin Li[
163*600f14f4SXin Li  pushdef([NAME],[m4_translit([$1],[abcdefghijklmnopqrstuvwxyz./+-],
164*600f14f4SXin Li                                   [ABCDEFGHIJKLMNOPQRSTUVWXYZ____])])
165*600f14f4SXin Li  define([acl_frompackage_]NAME, [$2])
166*600f14f4SXin Li  popdef([NAME])
167*600f14f4SXin Li  pushdef([PACK],[$2])
168*600f14f4SXin Li  pushdef([PACKUP],[m4_translit(PACK,[abcdefghijklmnopqrstuvwxyz./+-],
169*600f14f4SXin Li                                     [ABCDEFGHIJKLMNOPQRSTUVWXYZ____])])
170*600f14f4SXin Li  define([acl_libsinpackage_]PACKUP,
171*600f14f4SXin Li    m4_ifdef([acl_libsinpackage_]PACKUP, [m4_defn([acl_libsinpackage_]PACKUP)[, ]],)[lib$1])
172*600f14f4SXin Li  popdef([PACKUP])
173*600f14f4SXin Li  popdef([PACK])
174*600f14f4SXin Li])
175*600f14f4SXin Li
176*600f14f4SXin Lidnl AC_LIB_LINKFLAGS_BODY(name [, dependencies]) searches for libname and
177*600f14f4SXin Lidnl the libraries corresponding to explicit and implicit dependencies.
178*600f14f4SXin Lidnl Sets the LIB${NAME}, LTLIB${NAME} and INC${NAME} variables.
179*600f14f4SXin Lidnl Also, sets the LIB${NAME}_PREFIX variable to nonempty if libname was found
180*600f14f4SXin Lidnl in ${LIB${NAME}_PREFIX}/$acl_libdirstem.
181*600f14f4SXin LiAC_DEFUN([AC_LIB_LINKFLAGS_BODY],
182*600f14f4SXin Li[
183*600f14f4SXin Li  AC_REQUIRE([AC_LIB_PREPARE_MULTILIB])
184*600f14f4SXin Li  pushdef([NAME],[m4_translit([$1],[abcdefghijklmnopqrstuvwxyz./+-],
185*600f14f4SXin Li                                   [ABCDEFGHIJKLMNOPQRSTUVWXYZ____])])
186*600f14f4SXin Li  pushdef([PACK],[m4_ifdef([acl_frompackage_]NAME, [acl_frompackage_]NAME, lib[$1])])
187*600f14f4SXin Li  pushdef([PACKUP],[m4_translit(PACK,[abcdefghijklmnopqrstuvwxyz./+-],
188*600f14f4SXin Li                                     [ABCDEFGHIJKLMNOPQRSTUVWXYZ____])])
189*600f14f4SXin Li  pushdef([PACKLIBS],[m4_ifdef([acl_frompackage_]NAME, [acl_libsinpackage_]PACKUP, lib[$1])])
190*600f14f4SXin Li  dnl Autoconf >= 2.61 supports dots in --with options.
191*600f14f4SXin Li  pushdef([P_A_C_K],[m4_if(m4_version_compare(m4_defn([m4_PACKAGE_VERSION]),[2.61]),[-1],[m4_translit(PACK,[.],[_])],PACK)])
192*600f14f4SXin Li  dnl By default, look in $includedir and $libdir.
193*600f14f4SXin Li  use_additional=yes
194*600f14f4SXin Li  AC_LIB_WITH_FINAL_PREFIX([
195*600f14f4SXin Li    eval additional_includedir=\"$includedir\"
196*600f14f4SXin Li    eval additional_libdir=\"$libdir\"
197*600f14f4SXin Li  ])
198*600f14f4SXin Li  AC_ARG_WITH(P_A_C_K[-prefix],
199*600f14f4SXin Li[[  --with-]]P_A_C_K[[-prefix[=DIR]  search for ]PACKLIBS[ in DIR/include and DIR/lib
200*600f14f4SXin Li  --without-]]P_A_C_K[[-prefix     don't search for ]PACKLIBS[ in includedir and libdir]],
201*600f14f4SXin Li[
202*600f14f4SXin Li    if test "X$withval" = "Xno"; then
203*600f14f4SXin Li      use_additional=no
204*600f14f4SXin Li    else
205*600f14f4SXin Li      if test "X$withval" = "X"; then
206*600f14f4SXin Li        AC_LIB_WITH_FINAL_PREFIX([
207*600f14f4SXin Li          eval additional_includedir=\"$includedir\"
208*600f14f4SXin Li          eval additional_libdir=\"$libdir\"
209*600f14f4SXin Li        ])
210*600f14f4SXin Li      else
211*600f14f4SXin Li        additional_includedir="$withval/include"
212*600f14f4SXin Li        additional_libdir="$withval/$acl_libdirstem"
213*600f14f4SXin Li        if test "$acl_libdirstem2" != "$acl_libdirstem" \
214*600f14f4SXin Li           && ! test -d "$withval/$acl_libdirstem"; then
215*600f14f4SXin Li          additional_libdir="$withval/$acl_libdirstem2"
216*600f14f4SXin Li        fi
217*600f14f4SXin Li      fi
218*600f14f4SXin Li    fi
219*600f14f4SXin Li])
220*600f14f4SXin Li  dnl Search the library and its dependencies in $additional_libdir and
221*600f14f4SXin Li  dnl $LDFLAGS. Using breadth-first-seach.
222*600f14f4SXin Li  LIB[]NAME=
223*600f14f4SXin Li  LTLIB[]NAME=
224*600f14f4SXin Li  INC[]NAME=
225*600f14f4SXin Li  LIB[]NAME[]_PREFIX=
226*600f14f4SXin Li  dnl HAVE_LIB${NAME} is an indicator that LIB${NAME}, LTLIB${NAME} have been
227*600f14f4SXin Li  dnl computed. So it has to be reset here.
228*600f14f4SXin Li  HAVE_LIB[]NAME=
229*600f14f4SXin Li  rpathdirs=
230*600f14f4SXin Li  ltrpathdirs=
231*600f14f4SXin Li  names_already_handled=
232*600f14f4SXin Li  names_next_round='$1 $2'
233*600f14f4SXin Li  while test -n "$names_next_round"; do
234*600f14f4SXin Li    names_this_round="$names_next_round"
235*600f14f4SXin Li    names_next_round=
236*600f14f4SXin Li    for name in $names_this_round; do
237*600f14f4SXin Li      already_handled=
238*600f14f4SXin Li      for n in $names_already_handled; do
239*600f14f4SXin Li        if test "$n" = "$name"; then
240*600f14f4SXin Li          already_handled=yes
241*600f14f4SXin Li          break
242*600f14f4SXin Li        fi
243*600f14f4SXin Li      done
244*600f14f4SXin Li      if test -z "$already_handled"; then
245*600f14f4SXin Li        names_already_handled="$names_already_handled $name"
246*600f14f4SXin Li        dnl See if it was already located by an earlier AC_LIB_LINKFLAGS
247*600f14f4SXin Li        dnl or AC_LIB_HAVE_LINKFLAGS call.
248*600f14f4SXin Li        uppername=`echo "$name" | sed -e 'y|abcdefghijklmnopqrstuvwxyz./+-|ABCDEFGHIJKLMNOPQRSTUVWXYZ____|'`
249*600f14f4SXin Li        eval value=\"\$HAVE_LIB$uppername\"
250*600f14f4SXin Li        if test -n "$value"; then
251*600f14f4SXin Li          if test "$value" = yes; then
252*600f14f4SXin Li            eval value=\"\$LIB$uppername\"
253*600f14f4SXin Li            test -z "$value" || LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$value"
254*600f14f4SXin Li            eval value=\"\$LTLIB$uppername\"
255*600f14f4SXin Li            test -z "$value" || LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }$value"
256*600f14f4SXin Li          else
257*600f14f4SXin Li            dnl An earlier call to AC_LIB_HAVE_LINKFLAGS has determined
258*600f14f4SXin Li            dnl that this library doesn't exist. So just drop it.
259*600f14f4SXin Li            :
260*600f14f4SXin Li          fi
261*600f14f4SXin Li        else
262*600f14f4SXin Li          dnl Search the library lib$name in $additional_libdir and $LDFLAGS
263*600f14f4SXin Li          dnl and the already constructed $LIBNAME/$LTLIBNAME.
264*600f14f4SXin Li          found_dir=
265*600f14f4SXin Li          found_la=
266*600f14f4SXin Li          found_so=
267*600f14f4SXin Li          found_a=
268*600f14f4SXin Li          eval libname=\"$acl_libname_spec\"    # typically: libname=lib$name
269*600f14f4SXin Li          if test -n "$acl_shlibext"; then
270*600f14f4SXin Li            shrext=".$acl_shlibext"             # typically: shrext=.so
271*600f14f4SXin Li          else
272*600f14f4SXin Li            shrext=
273*600f14f4SXin Li          fi
274*600f14f4SXin Li          if test $use_additional = yes; then
275*600f14f4SXin Li            dir="$additional_libdir"
276*600f14f4SXin Li            dnl The same code as in the loop below:
277*600f14f4SXin Li            dnl First look for a shared library.
278*600f14f4SXin Li            if test -n "$acl_shlibext"; then
279*600f14f4SXin Li              if test -f "$dir/$libname$shrext"; then
280*600f14f4SXin Li                found_dir="$dir"
281*600f14f4SXin Li                found_so="$dir/$libname$shrext"
282*600f14f4SXin Li              else
283*600f14f4SXin Li                if test "$acl_library_names_spec" = '$libname$shrext$versuffix'; then
284*600f14f4SXin Li                  ver=`(cd "$dir" && \
285*600f14f4SXin Li                        for f in "$libname$shrext".*; do echo "$f"; done \
286*600f14f4SXin Li                        | sed -e "s,^$libname$shrext\\\\.,," \
287*600f14f4SXin Li                        | sort -t '.' -n -r -k1,1 -k2,2 -k3,3 -k4,4 -k5,5 \
288*600f14f4SXin Li                        | sed 1q ) 2>/dev/null`
289*600f14f4SXin Li                  if test -n "$ver" && test -f "$dir/$libname$shrext.$ver"; then
290*600f14f4SXin Li                    found_dir="$dir"
291*600f14f4SXin Li                    found_so="$dir/$libname$shrext.$ver"
292*600f14f4SXin Li                  fi
293*600f14f4SXin Li                else
294*600f14f4SXin Li                  eval library_names=\"$acl_library_names_spec\"
295*600f14f4SXin Li                  for f in $library_names; do
296*600f14f4SXin Li                    if test -f "$dir/$f"; then
297*600f14f4SXin Li                      found_dir="$dir"
298*600f14f4SXin Li                      found_so="$dir/$f"
299*600f14f4SXin Li                      break
300*600f14f4SXin Li                    fi
301*600f14f4SXin Li                  done
302*600f14f4SXin Li                fi
303*600f14f4SXin Li              fi
304*600f14f4SXin Li            fi
305*600f14f4SXin Li            dnl Then look for a static library.
306*600f14f4SXin Li            if test "X$found_dir" = "X"; then
307*600f14f4SXin Li              if test -f "$dir/$libname.$acl_libext"; then
308*600f14f4SXin Li                found_dir="$dir"
309*600f14f4SXin Li                found_a="$dir/$libname.$acl_libext"
310*600f14f4SXin Li              fi
311*600f14f4SXin Li            fi
312*600f14f4SXin Li            if test "X$found_dir" != "X"; then
313*600f14f4SXin Li              if test -f "$dir/$libname.la"; then
314*600f14f4SXin Li                found_la="$dir/$libname.la"
315*600f14f4SXin Li              fi
316*600f14f4SXin Li            fi
317*600f14f4SXin Li          fi
318*600f14f4SXin Li          if test "X$found_dir" = "X"; then
319*600f14f4SXin Li            for x in $LDFLAGS $LTLIB[]NAME; do
320*600f14f4SXin Li              AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
321*600f14f4SXin Li              case "$x" in
322*600f14f4SXin Li                -L*)
323*600f14f4SXin Li                  dir=`echo "X$x" | sed -e 's/^X-L//'`
324*600f14f4SXin Li                  dnl First look for a shared library.
325*600f14f4SXin Li                  if test -n "$acl_shlibext"; then
326*600f14f4SXin Li                    if test -f "$dir/$libname$shrext"; then
327*600f14f4SXin Li                      found_dir="$dir"
328*600f14f4SXin Li                      found_so="$dir/$libname$shrext"
329*600f14f4SXin Li                    else
330*600f14f4SXin Li                      if test "$acl_library_names_spec" = '$libname$shrext$versuffix'; then
331*600f14f4SXin Li                        ver=`(cd "$dir" && \
332*600f14f4SXin Li                              for f in "$libname$shrext".*; do echo "$f"; done \
333*600f14f4SXin Li                              | sed -e "s,^$libname$shrext\\\\.,," \
334*600f14f4SXin Li                              | sort -t '.' -n -r -k1,1 -k2,2 -k3,3 -k4,4 -k5,5 \
335*600f14f4SXin Li                              | sed 1q ) 2>/dev/null`
336*600f14f4SXin Li                        if test -n "$ver" && test -f "$dir/$libname$shrext.$ver"; then
337*600f14f4SXin Li                          found_dir="$dir"
338*600f14f4SXin Li                          found_so="$dir/$libname$shrext.$ver"
339*600f14f4SXin Li                        fi
340*600f14f4SXin Li                      else
341*600f14f4SXin Li                        eval library_names=\"$acl_library_names_spec\"
342*600f14f4SXin Li                        for f in $library_names; do
343*600f14f4SXin Li                          if test -f "$dir/$f"; then
344*600f14f4SXin Li                            found_dir="$dir"
345*600f14f4SXin Li                            found_so="$dir/$f"
346*600f14f4SXin Li                            break
347*600f14f4SXin Li                          fi
348*600f14f4SXin Li                        done
349*600f14f4SXin Li                      fi
350*600f14f4SXin Li                    fi
351*600f14f4SXin Li                  fi
352*600f14f4SXin Li                  dnl Then look for a static library.
353*600f14f4SXin Li                  if test "X$found_dir" = "X"; then
354*600f14f4SXin Li                    if test -f "$dir/$libname.$acl_libext"; then
355*600f14f4SXin Li                      found_dir="$dir"
356*600f14f4SXin Li                      found_a="$dir/$libname.$acl_libext"
357*600f14f4SXin Li                    fi
358*600f14f4SXin Li                  fi
359*600f14f4SXin Li                  if test "X$found_dir" != "X"; then
360*600f14f4SXin Li                    if test -f "$dir/$libname.la"; then
361*600f14f4SXin Li                      found_la="$dir/$libname.la"
362*600f14f4SXin Li                    fi
363*600f14f4SXin Li                  fi
364*600f14f4SXin Li                  ;;
365*600f14f4SXin Li              esac
366*600f14f4SXin Li              if test "X$found_dir" != "X"; then
367*600f14f4SXin Li                break
368*600f14f4SXin Li              fi
369*600f14f4SXin Li            done
370*600f14f4SXin Li          fi
371*600f14f4SXin Li          if test "X$found_dir" != "X"; then
372*600f14f4SXin Li            dnl Found the library.
373*600f14f4SXin Li            LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-L$found_dir -l$name"
374*600f14f4SXin Li            if test "X$found_so" != "X"; then
375*600f14f4SXin Li              dnl Linking with a shared library. We attempt to hardcode its
376*600f14f4SXin Li              dnl directory into the executable's runpath, unless it's the
377*600f14f4SXin Li              dnl standard /usr/lib.
378*600f14f4SXin Li              if test "$enable_rpath" = no \
379*600f14f4SXin Li                 || test "X$found_dir" = "X/usr/$acl_libdirstem" \
380*600f14f4SXin Li                 || test "X$found_dir" = "X/usr/$acl_libdirstem2"; then
381*600f14f4SXin Li                dnl No hardcoding is needed.
382*600f14f4SXin Li                LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so"
383*600f14f4SXin Li              else
384*600f14f4SXin Li                dnl Use an explicit option to hardcode DIR into the resulting
385*600f14f4SXin Li                dnl binary.
386*600f14f4SXin Li                dnl Potentially add DIR to ltrpathdirs.
387*600f14f4SXin Li                dnl The ltrpathdirs will be appended to $LTLIBNAME at the end.
388*600f14f4SXin Li                haveit=
389*600f14f4SXin Li                for x in $ltrpathdirs; do
390*600f14f4SXin Li                  if test "X$x" = "X$found_dir"; then
391*600f14f4SXin Li                    haveit=yes
392*600f14f4SXin Li                    break
393*600f14f4SXin Li                  fi
394*600f14f4SXin Li                done
395*600f14f4SXin Li                if test -z "$haveit"; then
396*600f14f4SXin Li                  ltrpathdirs="$ltrpathdirs $found_dir"
397*600f14f4SXin Li                fi
398*600f14f4SXin Li                dnl The hardcoding into $LIBNAME is system dependent.
399*600f14f4SXin Li                if test "$acl_hardcode_direct" = yes; then
400*600f14f4SXin Li                  dnl Using DIR/libNAME.so during linking hardcodes DIR into the
401*600f14f4SXin Li                  dnl resulting binary.
402*600f14f4SXin Li                  LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so"
403*600f14f4SXin Li                else
404*600f14f4SXin Li                  if test -n "$acl_hardcode_libdir_flag_spec" && test "$acl_hardcode_minus_L" = no; then
405*600f14f4SXin Li                    dnl Use an explicit option to hardcode DIR into the resulting
406*600f14f4SXin Li                    dnl binary.
407*600f14f4SXin Li                    LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so"
408*600f14f4SXin Li                    dnl Potentially add DIR to rpathdirs.
409*600f14f4SXin Li                    dnl The rpathdirs will be appended to $LIBNAME at the end.
410*600f14f4SXin Li                    haveit=
411*600f14f4SXin Li                    for x in $rpathdirs; do
412*600f14f4SXin Li                      if test "X$x" = "X$found_dir"; then
413*600f14f4SXin Li                        haveit=yes
414*600f14f4SXin Li                        break
415*600f14f4SXin Li                      fi
416*600f14f4SXin Li                    done
417*600f14f4SXin Li                    if test -z "$haveit"; then
418*600f14f4SXin Li                      rpathdirs="$rpathdirs $found_dir"
419*600f14f4SXin Li                    fi
420*600f14f4SXin Li                  else
421*600f14f4SXin Li                    dnl Rely on "-L$found_dir".
422*600f14f4SXin Li                    dnl But don't add it if it's already contained in the LDFLAGS
423*600f14f4SXin Li                    dnl or the already constructed $LIBNAME
424*600f14f4SXin Li                    haveit=
425*600f14f4SXin Li                    for x in $LDFLAGS $LIB[]NAME; do
426*600f14f4SXin Li                      AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
427*600f14f4SXin Li                      if test "X$x" = "X-L$found_dir"; then
428*600f14f4SXin Li                        haveit=yes
429*600f14f4SXin Li                        break
430*600f14f4SXin Li                      fi
431*600f14f4SXin Li                    done
432*600f14f4SXin Li                    if test -z "$haveit"; then
433*600f14f4SXin Li                      LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-L$found_dir"
434*600f14f4SXin Li                    fi
435*600f14f4SXin Li                    if test "$acl_hardcode_minus_L" != no; then
436*600f14f4SXin Li                      dnl FIXME: Not sure whether we should use
437*600f14f4SXin Li                      dnl "-L$found_dir -l$name" or "-L$found_dir $found_so"
438*600f14f4SXin Li                      dnl here.
439*600f14f4SXin Li                      LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so"
440*600f14f4SXin Li                    else
441*600f14f4SXin Li                      dnl We cannot use $acl_hardcode_runpath_var and LD_RUN_PATH
442*600f14f4SXin Li                      dnl here, because this doesn't fit in flags passed to the
443*600f14f4SXin Li                      dnl compiler. So give up. No hardcoding. This affects only
444*600f14f4SXin Li                      dnl very old systems.
445*600f14f4SXin Li                      dnl FIXME: Not sure whether we should use
446*600f14f4SXin Li                      dnl "-L$found_dir -l$name" or "-L$found_dir $found_so"
447*600f14f4SXin Li                      dnl here.
448*600f14f4SXin Li                      LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-l$name"
449*600f14f4SXin Li                    fi
450*600f14f4SXin Li                  fi
451*600f14f4SXin Li                fi
452*600f14f4SXin Li              fi
453*600f14f4SXin Li            else
454*600f14f4SXin Li              if test "X$found_a" != "X"; then
455*600f14f4SXin Li                dnl Linking with a static library.
456*600f14f4SXin Li                LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_a"
457*600f14f4SXin Li              else
458*600f14f4SXin Li                dnl We shouldn't come here, but anyway it's good to have a
459*600f14f4SXin Li                dnl fallback.
460*600f14f4SXin Li                LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-L$found_dir -l$name"
461*600f14f4SXin Li              fi
462*600f14f4SXin Li            fi
463*600f14f4SXin Li            dnl Assume the include files are nearby.
464*600f14f4SXin Li            additional_includedir=
465*600f14f4SXin Li            case "$found_dir" in
466*600f14f4SXin Li              */$acl_libdirstem | */$acl_libdirstem/)
467*600f14f4SXin Li                basedir=`echo "X$found_dir" | sed -e 's,^X,,' -e "s,/$acl_libdirstem/"'*$,,'`
468*600f14f4SXin Li                if test "$name" = '$1'; then
469*600f14f4SXin Li                  LIB[]NAME[]_PREFIX="$basedir"
470*600f14f4SXin Li                fi
471*600f14f4SXin Li                additional_includedir="$basedir/include"
472*600f14f4SXin Li                ;;
473*600f14f4SXin Li              */$acl_libdirstem2 | */$acl_libdirstem2/)
474*600f14f4SXin Li                basedir=`echo "X$found_dir" | sed -e 's,^X,,' -e "s,/$acl_libdirstem2/"'*$,,'`
475*600f14f4SXin Li                if test "$name" = '$1'; then
476*600f14f4SXin Li                  LIB[]NAME[]_PREFIX="$basedir"
477*600f14f4SXin Li                fi
478*600f14f4SXin Li                additional_includedir="$basedir/include"
479*600f14f4SXin Li                ;;
480*600f14f4SXin Li            esac
481*600f14f4SXin Li            if test "X$additional_includedir" != "X"; then
482*600f14f4SXin Li              dnl Potentially add $additional_includedir to $INCNAME.
483*600f14f4SXin Li              dnl But don't add it
484*600f14f4SXin Li              dnl   1. if it's the standard /usr/include,
485*600f14f4SXin Li              dnl   2. if it's /usr/local/include and we are using GCC on Linux,
486*600f14f4SXin Li              dnl   3. if it's already present in $CPPFLAGS or the already
487*600f14f4SXin Li              dnl      constructed $INCNAME,
488*600f14f4SXin Li              dnl   4. if it doesn't exist as a directory.
489*600f14f4SXin Li              if test "X$additional_includedir" != "X/usr/include"; then
490*600f14f4SXin Li                haveit=
491*600f14f4SXin Li                if test "X$additional_includedir" = "X/usr/local/include"; then
492*600f14f4SXin Li                  if test -n "$GCC"; then
493*600f14f4SXin Li                    case $host_os in
494*600f14f4SXin Li                      linux* | gnu* | k*bsd*-gnu) haveit=yes;;
495*600f14f4SXin Li                    esac
496*600f14f4SXin Li                  fi
497*600f14f4SXin Li                fi
498*600f14f4SXin Li                if test -z "$haveit"; then
499*600f14f4SXin Li                  for x in $CPPFLAGS $INC[]NAME; do
500*600f14f4SXin Li                    AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
501*600f14f4SXin Li                    if test "X$x" = "X-I$additional_includedir"; then
502*600f14f4SXin Li                      haveit=yes
503*600f14f4SXin Li                      break
504*600f14f4SXin Li                    fi
505*600f14f4SXin Li                  done
506*600f14f4SXin Li                  if test -z "$haveit"; then
507*600f14f4SXin Li                    if test -d "$additional_includedir"; then
508*600f14f4SXin Li                      dnl Really add $additional_includedir to $INCNAME.
509*600f14f4SXin Li                      INC[]NAME="${INC[]NAME}${INC[]NAME:+ }-I$additional_includedir"
510*600f14f4SXin Li                    fi
511*600f14f4SXin Li                  fi
512*600f14f4SXin Li                fi
513*600f14f4SXin Li              fi
514*600f14f4SXin Li            fi
515*600f14f4SXin Li            dnl Look for dependencies.
516*600f14f4SXin Li            if test -n "$found_la"; then
517*600f14f4SXin Li              dnl Read the .la file. It defines the variables
518*600f14f4SXin Li              dnl dlname, library_names, old_library, dependency_libs, current,
519*600f14f4SXin Li              dnl age, revision, installed, dlopen, dlpreopen, libdir.
520*600f14f4SXin Li              save_libdir="$libdir"
521*600f14f4SXin Li              case "$found_la" in
522*600f14f4SXin Li                */* | *\\*) . "$found_la" ;;
523*600f14f4SXin Li                *) . "./$found_la" ;;
524*600f14f4SXin Li              esac
525*600f14f4SXin Li              libdir="$save_libdir"
526*600f14f4SXin Li              dnl We use only dependency_libs.
527*600f14f4SXin Li              for dep in $dependency_libs; do
528*600f14f4SXin Li                case "$dep" in
529*600f14f4SXin Li                  -L*)
530*600f14f4SXin Li                    additional_libdir=`echo "X$dep" | sed -e 's/^X-L//'`
531*600f14f4SXin Li                    dnl Potentially add $additional_libdir to $LIBNAME and $LTLIBNAME.
532*600f14f4SXin Li                    dnl But don't add it
533*600f14f4SXin Li                    dnl   1. if it's the standard /usr/lib,
534*600f14f4SXin Li                    dnl   2. if it's /usr/local/lib and we are using GCC on Linux,
535*600f14f4SXin Li                    dnl   3. if it's already present in $LDFLAGS or the already
536*600f14f4SXin Li                    dnl      constructed $LIBNAME,
537*600f14f4SXin Li                    dnl   4. if it doesn't exist as a directory.
538*600f14f4SXin Li                    if test "X$additional_libdir" != "X/usr/$acl_libdirstem" \
539*600f14f4SXin Li                       && test "X$additional_libdir" != "X/usr/$acl_libdirstem2"; then
540*600f14f4SXin Li                      haveit=
541*600f14f4SXin Li                      if test "X$additional_libdir" = "X/usr/local/$acl_libdirstem" \
542*600f14f4SXin Li                         || test "X$additional_libdir" = "X/usr/local/$acl_libdirstem2"; then
543*600f14f4SXin Li                        if test -n "$GCC"; then
544*600f14f4SXin Li                          case $host_os in
545*600f14f4SXin Li                            linux* | gnu* | k*bsd*-gnu) haveit=yes;;
546*600f14f4SXin Li                          esac
547*600f14f4SXin Li                        fi
548*600f14f4SXin Li                      fi
549*600f14f4SXin Li                      if test -z "$haveit"; then
550*600f14f4SXin Li                        haveit=
551*600f14f4SXin Li                        for x in $LDFLAGS $LIB[]NAME; do
552*600f14f4SXin Li                          AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
553*600f14f4SXin Li                          if test "X$x" = "X-L$additional_libdir"; then
554*600f14f4SXin Li                            haveit=yes
555*600f14f4SXin Li                            break
556*600f14f4SXin Li                          fi
557*600f14f4SXin Li                        done
558*600f14f4SXin Li                        if test -z "$haveit"; then
559*600f14f4SXin Li                          if test -d "$additional_libdir"; then
560*600f14f4SXin Li                            dnl Really add $additional_libdir to $LIBNAME.
561*600f14f4SXin Li                            LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-L$additional_libdir"
562*600f14f4SXin Li                          fi
563*600f14f4SXin Li                        fi
564*600f14f4SXin Li                        haveit=
565*600f14f4SXin Li                        for x in $LDFLAGS $LTLIB[]NAME; do
566*600f14f4SXin Li                          AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
567*600f14f4SXin Li                          if test "X$x" = "X-L$additional_libdir"; then
568*600f14f4SXin Li                            haveit=yes
569*600f14f4SXin Li                            break
570*600f14f4SXin Li                          fi
571*600f14f4SXin Li                        done
572*600f14f4SXin Li                        if test -z "$haveit"; then
573*600f14f4SXin Li                          if test -d "$additional_libdir"; then
574*600f14f4SXin Li                            dnl Really add $additional_libdir to $LTLIBNAME.
575*600f14f4SXin Li                            LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-L$additional_libdir"
576*600f14f4SXin Li                          fi
577*600f14f4SXin Li                        fi
578*600f14f4SXin Li                      fi
579*600f14f4SXin Li                    fi
580*600f14f4SXin Li                    ;;
581*600f14f4SXin Li                  -R*)
582*600f14f4SXin Li                    dir=`echo "X$dep" | sed -e 's/^X-R//'`
583*600f14f4SXin Li                    if test "$enable_rpath" != no; then
584*600f14f4SXin Li                      dnl Potentially add DIR to rpathdirs.
585*600f14f4SXin Li                      dnl The rpathdirs will be appended to $LIBNAME at the end.
586*600f14f4SXin Li                      haveit=
587*600f14f4SXin Li                      for x in $rpathdirs; do
588*600f14f4SXin Li                        if test "X$x" = "X$dir"; then
589*600f14f4SXin Li                          haveit=yes
590*600f14f4SXin Li                          break
591*600f14f4SXin Li                        fi
592*600f14f4SXin Li                      done
593*600f14f4SXin Li                      if test -z "$haveit"; then
594*600f14f4SXin Li                        rpathdirs="$rpathdirs $dir"
595*600f14f4SXin Li                      fi
596*600f14f4SXin Li                      dnl Potentially add DIR to ltrpathdirs.
597*600f14f4SXin Li                      dnl The ltrpathdirs will be appended to $LTLIBNAME at the end.
598*600f14f4SXin Li                      haveit=
599*600f14f4SXin Li                      for x in $ltrpathdirs; do
600*600f14f4SXin Li                        if test "X$x" = "X$dir"; then
601*600f14f4SXin Li                          haveit=yes
602*600f14f4SXin Li                          break
603*600f14f4SXin Li                        fi
604*600f14f4SXin Li                      done
605*600f14f4SXin Li                      if test -z "$haveit"; then
606*600f14f4SXin Li                        ltrpathdirs="$ltrpathdirs $dir"
607*600f14f4SXin Li                      fi
608*600f14f4SXin Li                    fi
609*600f14f4SXin Li                    ;;
610*600f14f4SXin Li                  -l*)
611*600f14f4SXin Li                    dnl Handle this in the next round.
612*600f14f4SXin Li                    names_next_round="$names_next_round "`echo "X$dep" | sed -e 's/^X-l//'`
613*600f14f4SXin Li                    ;;
614*600f14f4SXin Li                  *.la)
615*600f14f4SXin Li                    dnl Handle this in the next round. Throw away the .la's
616*600f14f4SXin Li                    dnl directory; it is already contained in a preceding -L
617*600f14f4SXin Li                    dnl option.
618*600f14f4SXin Li                    names_next_round="$names_next_round "`echo "X$dep" | sed -e 's,^X.*/,,' -e 's,^lib,,' -e 's,\.la$,,'`
619*600f14f4SXin Li                    ;;
620*600f14f4SXin Li                  *)
621*600f14f4SXin Li                    dnl Most likely an immediate library name.
622*600f14f4SXin Li                    LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$dep"
623*600f14f4SXin Li                    LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }$dep"
624*600f14f4SXin Li                    ;;
625*600f14f4SXin Li                esac
626*600f14f4SXin Li              done
627*600f14f4SXin Li            fi
628*600f14f4SXin Li          else
629*600f14f4SXin Li            dnl Didn't find the library; assume it is in the system directories
630*600f14f4SXin Li            dnl known to the linker and runtime loader. (All the system
631*600f14f4SXin Li            dnl directories known to the linker should also be known to the
632*600f14f4SXin Li            dnl runtime loader, otherwise the system is severely misconfigured.)
633*600f14f4SXin Li            LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-l$name"
634*600f14f4SXin Li            LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-l$name"
635*600f14f4SXin Li          fi
636*600f14f4SXin Li        fi
637*600f14f4SXin Li      fi
638*600f14f4SXin Li    done
639*600f14f4SXin Li  done
640*600f14f4SXin Li  if test "X$rpathdirs" != "X"; then
641*600f14f4SXin Li    if test -n "$acl_hardcode_libdir_separator"; then
642*600f14f4SXin Li      dnl Weird platform: only the last -rpath option counts, the user must
643*600f14f4SXin Li      dnl pass all path elements in one option. We can arrange that for a
644*600f14f4SXin Li      dnl single library, but not when more than one $LIBNAMEs are used.
645*600f14f4SXin Li      alldirs=
646*600f14f4SXin Li      for found_dir in $rpathdirs; do
647*600f14f4SXin Li        alldirs="${alldirs}${alldirs:+$acl_hardcode_libdir_separator}$found_dir"
648*600f14f4SXin Li      done
649*600f14f4SXin Li      dnl Note: acl_hardcode_libdir_flag_spec uses $libdir and $wl.
650*600f14f4SXin Li      acl_save_libdir="$libdir"
651*600f14f4SXin Li      libdir="$alldirs"
652*600f14f4SXin Li      eval flag=\"$acl_hardcode_libdir_flag_spec\"
653*600f14f4SXin Li      libdir="$acl_save_libdir"
654*600f14f4SXin Li      LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$flag"
655*600f14f4SXin Li    else
656*600f14f4SXin Li      dnl The -rpath options are cumulative.
657*600f14f4SXin Li      for found_dir in $rpathdirs; do
658*600f14f4SXin Li        acl_save_libdir="$libdir"
659*600f14f4SXin Li        libdir="$found_dir"
660*600f14f4SXin Li        eval flag=\"$acl_hardcode_libdir_flag_spec\"
661*600f14f4SXin Li        libdir="$acl_save_libdir"
662*600f14f4SXin Li        LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$flag"
663*600f14f4SXin Li      done
664*600f14f4SXin Li    fi
665*600f14f4SXin Li  fi
666*600f14f4SXin Li  if test "X$ltrpathdirs" != "X"; then
667*600f14f4SXin Li    dnl When using libtool, the option that works for both libraries and
668*600f14f4SXin Li    dnl executables is -R. The -R options are cumulative.
669*600f14f4SXin Li    for found_dir in $ltrpathdirs; do
670*600f14f4SXin Li      LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-R$found_dir"
671*600f14f4SXin Li    done
672*600f14f4SXin Li  fi
673*600f14f4SXin Li  popdef([P_A_C_K])
674*600f14f4SXin Li  popdef([PACKLIBS])
675*600f14f4SXin Li  popdef([PACKUP])
676*600f14f4SXin Li  popdef([PACK])
677*600f14f4SXin Li  popdef([NAME])
678*600f14f4SXin Li])
679*600f14f4SXin Li
680*600f14f4SXin Lidnl AC_LIB_APPENDTOVAR(VAR, CONTENTS) appends the elements of CONTENTS to VAR,
681*600f14f4SXin Lidnl unless already present in VAR.
682*600f14f4SXin Lidnl Works only for CPPFLAGS, not for LIB* variables because that sometimes
683*600f14f4SXin Lidnl contains two or three consecutive elements that belong together.
684*600f14f4SXin LiAC_DEFUN([AC_LIB_APPENDTOVAR],
685*600f14f4SXin Li[
686*600f14f4SXin Li  for element in [$2]; do
687*600f14f4SXin Li    haveit=
688*600f14f4SXin Li    for x in $[$1]; do
689*600f14f4SXin Li      AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
690*600f14f4SXin Li      if test "X$x" = "X$element"; then
691*600f14f4SXin Li        haveit=yes
692*600f14f4SXin Li        break
693*600f14f4SXin Li      fi
694*600f14f4SXin Li    done
695*600f14f4SXin Li    if test -z "$haveit"; then
696*600f14f4SXin Li      [$1]="${[$1]}${[$1]:+ }$element"
697*600f14f4SXin Li    fi
698*600f14f4SXin Li  done
699*600f14f4SXin Li])
700*600f14f4SXin Li
701*600f14f4SXin Lidnl For those cases where a variable contains several -L and -l options
702*600f14f4SXin Lidnl referring to unknown libraries and directories, this macro determines the
703*600f14f4SXin Lidnl necessary additional linker options for the runtime path.
704*600f14f4SXin Lidnl AC_LIB_LINKFLAGS_FROM_LIBS([LDADDVAR], [LIBSVALUE], [USE-LIBTOOL])
705*600f14f4SXin Lidnl sets LDADDVAR to linker options needed together with LIBSVALUE.
706*600f14f4SXin Lidnl If USE-LIBTOOL evaluates to non-empty, linking with libtool is assumed,
707*600f14f4SXin Lidnl otherwise linking without libtool is assumed.
708*600f14f4SXin LiAC_DEFUN([AC_LIB_LINKFLAGS_FROM_LIBS],
709*600f14f4SXin Li[
710*600f14f4SXin Li  AC_REQUIRE([AC_LIB_RPATH])
711*600f14f4SXin Li  AC_REQUIRE([AC_LIB_PREPARE_MULTILIB])
712*600f14f4SXin Li  $1=
713*600f14f4SXin Li  if test "$enable_rpath" != no; then
714*600f14f4SXin Li    if test -n "$acl_hardcode_libdir_flag_spec" && test "$acl_hardcode_minus_L" = no; then
715*600f14f4SXin Li      dnl Use an explicit option to hardcode directories into the resulting
716*600f14f4SXin Li      dnl binary.
717*600f14f4SXin Li      rpathdirs=
718*600f14f4SXin Li      next=
719*600f14f4SXin Li      for opt in $2; do
720*600f14f4SXin Li        if test -n "$next"; then
721*600f14f4SXin Li          dir="$next"
722*600f14f4SXin Li          dnl No need to hardcode the standard /usr/lib.
723*600f14f4SXin Li          if test "X$dir" != "X/usr/$acl_libdirstem" \
724*600f14f4SXin Li             && test "X$dir" != "X/usr/$acl_libdirstem2"; then
725*600f14f4SXin Li            rpathdirs="$rpathdirs $dir"
726*600f14f4SXin Li          fi
727*600f14f4SXin Li          next=
728*600f14f4SXin Li        else
729*600f14f4SXin Li          case $opt in
730*600f14f4SXin Li            -L) next=yes ;;
731*600f14f4SXin Li            -L*) dir=`echo "X$opt" | sed -e 's,^X-L,,'`
732*600f14f4SXin Li                 dnl No need to hardcode the standard /usr/lib.
733*600f14f4SXin Li                 if test "X$dir" != "X/usr/$acl_libdirstem" \
734*600f14f4SXin Li                    && test "X$dir" != "X/usr/$acl_libdirstem2"; then
735*600f14f4SXin Li                   rpathdirs="$rpathdirs $dir"
736*600f14f4SXin Li                 fi
737*600f14f4SXin Li                 next= ;;
738*600f14f4SXin Li            *) next= ;;
739*600f14f4SXin Li          esac
740*600f14f4SXin Li        fi
741*600f14f4SXin Li      done
742*600f14f4SXin Li      if test "X$rpathdirs" != "X"; then
743*600f14f4SXin Li        if test -n ""$3""; then
744*600f14f4SXin Li          dnl libtool is used for linking. Use -R options.
745*600f14f4SXin Li          for dir in $rpathdirs; do
746*600f14f4SXin Li            $1="${$1}${$1:+ }-R$dir"
747*600f14f4SXin Li          done
748*600f14f4SXin Li        else
749*600f14f4SXin Li          dnl The linker is used for linking directly.
750*600f14f4SXin Li          if test -n "$acl_hardcode_libdir_separator"; then
751*600f14f4SXin Li            dnl Weird platform: only the last -rpath option counts, the user
752*600f14f4SXin Li            dnl must pass all path elements in one option.
753*600f14f4SXin Li            alldirs=
754*600f14f4SXin Li            for dir in $rpathdirs; do
755*600f14f4SXin Li              alldirs="${alldirs}${alldirs:+$acl_hardcode_libdir_separator}$dir"
756*600f14f4SXin Li            done
757*600f14f4SXin Li            acl_save_libdir="$libdir"
758*600f14f4SXin Li            libdir="$alldirs"
759*600f14f4SXin Li            eval flag=\"$acl_hardcode_libdir_flag_spec\"
760*600f14f4SXin Li            libdir="$acl_save_libdir"
761*600f14f4SXin Li            $1="$flag"
762*600f14f4SXin Li          else
763*600f14f4SXin Li            dnl The -rpath options are cumulative.
764*600f14f4SXin Li            for dir in $rpathdirs; do
765*600f14f4SXin Li              acl_save_libdir="$libdir"
766*600f14f4SXin Li              libdir="$dir"
767*600f14f4SXin Li              eval flag=\"$acl_hardcode_libdir_flag_spec\"
768*600f14f4SXin Li              libdir="$acl_save_libdir"
769*600f14f4SXin Li              $1="${$1}${$1:+ }$flag"
770*600f14f4SXin Li            done
771*600f14f4SXin Li          fi
772*600f14f4SXin Li        fi
773*600f14f4SXin Li      fi
774*600f14f4SXin Li    fi
775*600f14f4SXin Li  fi
776*600f14f4SXin Li  AC_SUBST([$1])
777*600f14f4SXin Li])
778