1
# lib-link.m4 serial 4 (gettext-0.12)
2
dnl Copyright (C) 2001-2003 Free Software Foundation, Inc.
3
dnl This file is free software, distributed under the terms of the GNU
4
dnl General Public License. As a special exception to the GNU General
5
dnl Public License, this file may be distributed as part of a program
6
dnl that contains a configuration script generated by Autoconf, under
7
dnl the same distribution terms as the rest of that program.
1
# lib-link.m4 serial 13 (gettext-0.17)
2
dnl Copyright (C) 2001-2007 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.
9
7
dnl From Bruno Haible.
11
11
dnl AC_LIB_LINKFLAGS(name [, dependencies]) searches for libname and
12
12
dnl the libraries corresponding to explicit and implicit dependencies.
13
13
dnl Sets and AC_SUBSTs the LIB${NAME} and LTLIB${NAME} variables and
14
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.
15
17
AC_DEFUN([AC_LIB_LINKFLAGS],
17
19
AC_REQUIRE([AC_LIB_PREPARE_PREFIX])
24
26
ac_cv_lib[]Name[]_libs="$LIB[]NAME"
25
27
ac_cv_lib[]Name[]_ltlibs="$LTLIB[]NAME"
26
28
ac_cv_lib[]Name[]_cppflags="$INC[]NAME"
29
ac_cv_lib[]Name[]_prefix="$LIB[]NAME[]_PREFIX"
28
31
LIB[]NAME="$ac_cv_lib[]Name[]_libs"
29
32
LTLIB[]NAME="$ac_cv_lib[]Name[]_ltlibs"
30
33
INC[]NAME="$ac_cv_lib[]Name[]_cppflags"
34
LIB[]NAME[]_PREFIX="$ac_cv_lib[]Name[]_prefix"
31
35
AC_LIB_APPENDTOVAR([CPPFLAGS], [$INC]NAME)
32
36
AC_SUBST([LIB]NAME)
33
37
AC_SUBST([LTLIB]NAME)
38
AC_SUBST([LIB]NAME[_PREFIX])
34
39
dnl Also set HAVE_LIB[]NAME so that AC_LIB_HAVE_LINKFLAGS can reuse the
35
40
dnl results of this search when this library appears as a dependency.
46
51
dnl LTLIB${NAME} variables and augments the CPPFLAGS variable, and
47
52
dnl #defines HAVE_LIB${NAME} to 1. Otherwise, it sets and AC_SUBSTs
48
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.
49
56
AC_DEFUN([AC_LIB_HAVE_LINKFLAGS],
51
58
AC_REQUIRE([AC_LIB_PREPARE_PREFIX])
82
89
CPPFLAGS="$ac_save_CPPFLAGS"
86
94
AC_SUBST([HAVE_LIB]NAME)
87
95
AC_SUBST([LIB]NAME)
88
96
AC_SUBST([LTLIB]NAME)
97
AC_SUBST([LIB]NAME[_PREFIX])
93
102
dnl Determine the platform dependent parameters needed to use rpath:
94
dnl libext, shlibext, hardcode_libdir_flag_spec, hardcode_libdir_separator,
95
dnl hardcode_direct, hardcode_minus_L.
105
dnl acl_hardcode_libdir_flag_spec,
106
dnl acl_hardcode_libdir_separator,
107
dnl acl_hardcode_direct,
108
dnl acl_hardcode_minus_L.
96
109
AC_DEFUN([AC_LIB_RPATH],
111
dnl Tell automake >= 1.10 to complain if config.rpath is missing.
112
m4_ifdef([AC_REQUIRE_AUX_FILE], [AC_REQUIRE_AUX_FILE([config.rpath])])
98
113
AC_REQUIRE([AC_PROG_CC]) dnl we use $CC, $GCC, $LDFLAGS
99
114
AC_REQUIRE([AC_LIB_PROG_LD]) dnl we use $LD, $with_gnu_ld
100
115
AC_REQUIRE([AC_CANONICAL_HOST]) dnl we use $host
107
122
acl_cv_rpath=done
110
libext="$acl_cv_libext"
111
shlibext="$acl_cv_shlibext"
112
hardcode_libdir_flag_spec="$acl_cv_hardcode_libdir_flag_spec"
113
hardcode_libdir_separator="$acl_cv_hardcode_libdir_separator"
114
hardcode_direct="$acl_cv_hardcode_direct"
115
hardcode_minus_L="$acl_cv_hardcode_minus_L"
125
acl_libext="$acl_cv_libext"
126
acl_shlibext="$acl_cv_shlibext"
127
acl_libname_spec="$acl_cv_libname_spec"
128
acl_library_names_spec="$acl_cv_library_names_spec"
129
acl_hardcode_libdir_flag_spec="$acl_cv_hardcode_libdir_flag_spec"
130
acl_hardcode_libdir_separator="$acl_cv_hardcode_libdir_separator"
131
acl_hardcode_direct="$acl_cv_hardcode_direct"
132
acl_hardcode_minus_L="$acl_cv_hardcode_minus_L"
116
133
dnl Determine whether the user wants rpath handling at all.
117
134
AC_ARG_ENABLE(rpath,
118
135
[ --disable-rpath do not hardcode runtime library paths],
122
139
dnl AC_LIB_LINKFLAGS_BODY(name [, dependencies]) searches for libname and
123
140
dnl the libraries corresponding to explicit and implicit dependencies.
124
141
dnl Sets the LIB${NAME}, LTLIB${NAME} and INC${NAME} variables.
142
dnl Also, sets the LIB${NAME}_PREFIX variable to nonempty if libname was found
143
dnl in ${LIB${NAME}_PREFIX}/$acl_libdirstem.
125
144
AC_DEFUN([AC_LIB_LINKFLAGS_BODY],
146
AC_REQUIRE([AC_LIB_PREPARE_MULTILIB])
127
147
define([NAME],[translit([$1],[abcdefghijklmnopqrstuvwxyz./-],
128
148
[ABCDEFGHIJKLMNOPQRSTUVWXYZ___])])
149
dnl Autoconf >= 2.61 supports dots in --with options.
150
define([N_A_M_E],[m4_if(m4_version_compare(m4_defn([m4_PACKAGE_VERSION]),[2.61]),[-1],[translit([$1],[.],[_])],[$1])])
129
151
dnl By default, look in $includedir and $libdir.
130
152
use_additional=yes
131
153
AC_LIB_WITH_FINAL_PREFIX([
132
154
eval additional_includedir=\"$includedir\"
133
155
eval additional_libdir=\"$libdir\"
135
AC_LIB_ARG_WITH([lib$1-prefix],
136
[ --with-lib$1-prefix[=DIR] search for lib$1 in DIR/include and DIR/lib
137
--without-lib$1-prefix don't search for lib$1 in includedir and libdir],
157
AC_LIB_ARG_WITH([lib]N_A_M_E[-prefix],
158
[ --with-lib]N_A_M_E[-prefix[=DIR] search for lib$1 in DIR/include and DIR/lib
159
--without-lib]N_A_M_E[-prefix don't search for lib$1 in includedir and libdir],
139
161
if test "X$withval" = "Xno"; then
140
162
use_additional=no
220
eval libname=\"$acl_libname_spec\" # typically: libname=lib$name
221
if test -n "$acl_shlibext"; then
222
shrext=".$acl_shlibext" # typically: shrext=.so
197
226
if test $use_additional = yes; then
198
if test -n "$shlibext" && test -f "$additional_libdir/lib$name.$shlibext"; then
199
found_dir="$additional_libdir"
200
found_so="$additional_libdir/lib$name.$shlibext"
201
if test -f "$additional_libdir/lib$name.la"; then
202
found_la="$additional_libdir/lib$name.la"
205
if test -f "$additional_libdir/lib$name.$libext"; then
206
found_dir="$additional_libdir"
207
found_a="$additional_libdir/lib$name.$libext"
208
if test -f "$additional_libdir/lib$name.la"; then
209
found_la="$additional_libdir/lib$name.la"
227
dir="$additional_libdir"
228
dnl The same code as in the loop below:
229
dnl First look for a shared library.
230
if test -n "$acl_shlibext"; then
231
if test -f "$dir/$libname$shrext"; then
233
found_so="$dir/$libname$shrext"
235
if test "$acl_library_names_spec" = '$libname$shrext$versuffix'; then
237
for f in "$libname$shrext".*; do echo "$f"; done \
238
| sed -e "s,^$libname$shrext\\\\.,," \
239
| sort -t '.' -n -r -k1,1 -k2,2 -k3,3 -k4,4 -k5,5 \
240
| sed 1q ) 2>/dev/null`
241
if test -n "$ver" && test -f "$dir/$libname$shrext.$ver"; then
243
found_so="$dir/$libname$shrext.$ver"
246
eval library_names=\"$acl_library_names_spec\"
247
for f in $library_names; do
248
if test -f "$dir/$f"; then
257
dnl Then look for a static library.
258
if test "X$found_dir" = "X"; then
259
if test -f "$dir/$libname.$acl_libext"; then
261
found_a="$dir/$libname.$acl_libext"
264
if test "X$found_dir" != "X"; then
265
if test -f "$dir/$libname.la"; then
266
found_la="$dir/$libname.la"
214
270
if test "X$found_dir" = "X"; then
215
271
for x in $LDFLAGS $LTLIB[]NAME; do
219
275
dir=`echo "X$x" | sed -e 's/^X-L//'`
220
if test -n "$shlibext" && test -f "$dir/lib$name.$shlibext"; then
222
found_so="$dir/lib$name.$shlibext"
223
if test -f "$dir/lib$name.la"; then
224
found_la="$dir/lib$name.la"
227
if test -f "$dir/lib$name.$libext"; then
276
dnl First look for a shared library.
277
if test -n "$acl_shlibext"; then
278
if test -f "$dir/$libname$shrext"; then
229
found_a="$dir/lib$name.$libext"
230
if test -f "$dir/lib$name.la"; then
231
found_la="$dir/lib$name.la"
280
found_so="$dir/$libname$shrext"
282
if test "$acl_library_names_spec" = '$libname$shrext$versuffix'; then
284
for f in "$libname$shrext".*; do echo "$f"; done \
285
| sed -e "s,^$libname$shrext\\\\.,," \
286
| sort -t '.' -n -r -k1,1 -k2,2 -k3,3 -k4,4 -k5,5 \
287
| sed 1q ) 2>/dev/null`
288
if test -n "$ver" && test -f "$dir/$libname$shrext.$ver"; then
290
found_so="$dir/$libname$shrext.$ver"
293
eval library_names=\"$acl_library_names_spec\"
294
for f in $library_names; do
295
if test -f "$dir/$f"; then
304
dnl Then look for a static library.
305
if test "X$found_dir" = "X"; then
306
if test -f "$dir/$libname.$acl_libext"; then
308
found_a="$dir/$libname.$acl_libext"
311
if test "X$found_dir" != "X"; then
312
if test -f "$dir/$libname.la"; then
313
found_la="$dir/$libname.la"
237
318
if test "X$found_dir" != "X"; then
246
327
dnl Linking with a shared library. We attempt to hardcode its
247
328
dnl directory into the executable's runpath, unless it's the
248
329
dnl standard /usr/lib.
249
if test "$enable_rpath" = no || test "X$found_dir" = "X/usr/lib"; then
330
if test "$enable_rpath" = no || test "X$found_dir" = "X/usr/$acl_libdirstem"; then
250
331
dnl No hardcoding is needed.
251
332
LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so"
265
346
ltrpathdirs="$ltrpathdirs $found_dir"
267
348
dnl The hardcoding into $LIBNAME is system dependent.
268
if test "$hardcode_direct" = yes; then
349
if test "$acl_hardcode_direct" = yes; then
269
350
dnl Using DIR/libNAME.so during linking hardcodes DIR into the
270
351
dnl resulting binary.
271
352
LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so"
273
if test -n "$hardcode_libdir_flag_spec" && test "$hardcode_minus_L" = no; then
354
if test -n "$acl_hardcode_libdir_flag_spec" && test "$acl_hardcode_minus_L" = no; then
274
355
dnl Use an explicit option to hardcode DIR into the resulting
276
357
LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so"
301
382
if test -z "$haveit"; then
302
383
LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-L$found_dir"
304
if test "$hardcode_minus_L" != no; then
385
if test "$acl_hardcode_minus_L" != no; then
305
386
dnl FIXME: Not sure whether we should use
306
387
dnl "-L$found_dir -l$name" or "-L$found_dir $found_so"
308
389
LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so"
310
dnl We cannot use $hardcode_runpath_var and LD_RUN_PATH
391
dnl We cannot use $acl_hardcode_runpath_var and LD_RUN_PATH
311
392
dnl here, because this doesn't fit in flags passed to the
312
393
dnl compiler. So give up. No hardcoding. This affects only
313
394
dnl very old systems.
332
413
dnl Assume the include files are nearby.
333
414
additional_includedir=
334
415
case "$found_dir" in
336
basedir=`echo "X$found_dir" | sed -e 's,^X,,' -e 's,/lib/*$,,'`
416
*/$acl_libdirstem | */$acl_libdirstem/)
417
basedir=`echo "X$found_dir" | sed -e 's,^X,,' -e "s,/$acl_libdirstem/"'*$,,'`
418
LIB[]NAME[]_PREFIX="$basedir"
337
419
additional_includedir="$basedir/include"
394
476
dnl 3. if it's already present in $LDFLAGS or the already
395
477
dnl constructed $LIBNAME,
396
478
dnl 4. if it doesn't exist as a directory.
397
if test "X$additional_libdir" != "X/usr/lib"; then
479
if test "X$additional_libdir" != "X/usr/$acl_libdirstem"; then
399
if test "X$additional_libdir" = "X/usr/local/lib"; then
481
if test "X$additional_libdir" = "X/usr/local/$acl_libdirstem"; then
400
482
if test -n "$GCC"; then
484
linux* | gnu* | k*bsd*-gnu) haveit=yes;;
497
579
if test "X$rpathdirs" != "X"; then
498
if test -n "$hardcode_libdir_separator"; then
580
if test -n "$acl_hardcode_libdir_separator"; then
499
581
dnl Weird platform: only the last -rpath option counts, the user must
500
582
dnl pass all path elements in one option. We can arrange that for a
501
583
dnl single library, but not when more than one $LIBNAMEs are used.
503
585
for found_dir in $rpathdirs; do
504
alldirs="${alldirs}${alldirs:+$hardcode_libdir_separator}$found_dir"
586
alldirs="${alldirs}${alldirs:+$acl_hardcode_libdir_separator}$found_dir"
506
dnl Note: hardcode_libdir_flag_spec uses $libdir and $wl.
588
dnl Note: acl_hardcode_libdir_flag_spec uses $libdir and $wl.
507
589
acl_save_libdir="$libdir"
508
590
libdir="$alldirs"
509
eval flag=\"$hardcode_libdir_flag_spec\"
591
eval flag=\"$acl_hardcode_libdir_flag_spec\"
510
592
libdir="$acl_save_libdir"
511
593
LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$flag"
514
596
for found_dir in $rpathdirs; do
515
597
acl_save_libdir="$libdir"
516
598
libdir="$found_dir"
517
eval flag=\"$hardcode_libdir_flag_spec\"
599
eval flag=\"$acl_hardcode_libdir_flag_spec\"
518
600
libdir="$acl_save_libdir"
519
601
LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$flag"
635
dnl For those cases where a variable contains several -L and -l options
636
dnl referring to unknown libraries and directories, this macro determines the
637
dnl necessary additional linker options for the runtime path.
638
dnl AC_LIB_LINKFLAGS_FROM_LIBS([LDADDVAR], [LIBSVALUE], [USE-LIBTOOL])
639
dnl sets LDADDVAR to linker options needed together with LIBSVALUE.
640
dnl If USE-LIBTOOL evaluates to non-empty, linking with libtool is assumed,
641
dnl otherwise linking without libtool is assumed.
642
AC_DEFUN([AC_LIB_LINKFLAGS_FROM_LIBS],
644
AC_REQUIRE([AC_LIB_RPATH])
645
AC_REQUIRE([AC_LIB_PREPARE_MULTILIB])
647
if test "$enable_rpath" != no; then
648
if test -n "$acl_hardcode_libdir_flag_spec" && test "$acl_hardcode_minus_L" = no; then
649
dnl Use an explicit option to hardcode directories into the resulting
654
if test -n "$next"; then
656
dnl No need to hardcode the standard /usr/lib.
657
if test "X$dir" != "X/usr/$acl_libdirstem"; then
658
rpathdirs="$rpathdirs $dir"
664
-L*) dir=`echo "X$opt" | sed -e 's,^X-L,,'`
665
dnl No need to hardcode the standard /usr/lib.
666
if test "X$dir" != "X/usr/$acl_libdirstem"; then
667
rpathdirs="$rpathdirs $dir"
674
if test "X$rpathdirs" != "X"; then
675
if test -n ""$3""; then
676
dnl libtool is used for linking. Use -R options.
677
for dir in $rpathdirs; do
678
$1="${$1}${$1:+ }-R$dir"
681
dnl The linker is used for linking directly.
682
if test -n "$acl_hardcode_libdir_separator"; then
683
dnl Weird platform: only the last -rpath option counts, the user
684
dnl must pass all path elements in one option.
686
for dir in $rpathdirs; do
687
alldirs="${alldirs}${alldirs:+$acl_hardcode_libdir_separator}$dir"
689
acl_save_libdir="$libdir"
691
eval flag=\"$acl_hardcode_libdir_flag_spec\"
692
libdir="$acl_save_libdir"
695
dnl The -rpath options are cumulative.
696
for dir in $rpathdirs; do
697
acl_save_libdir="$libdir"
699
eval flag=\"$acl_hardcode_libdir_flag_spec\"
700
libdir="$acl_save_libdir"
701
$1="${$1}${$1:+ }$flag"