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