1
# lib-link.m4 serial 21 (gettext-0.18)
2
dnl Copyright (C) 2001-2010 Free Software Foundation, Inc.
1
# lib-link.m4 serial 8 (gettext-0.15)
2
dnl Copyright (C) 2001-2006 Free Software Foundation, Inc.
3
3
dnl This file is free software; the Free Software Foundation
4
4
dnl gives unlimited permission to copy and/or distribute it,
5
5
dnl with or without modifications, as long as this notice is preserved.
7
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.
17
15
AC_DEFUN([AC_LIB_LINKFLAGS],
19
17
AC_REQUIRE([AC_LIB_PREPARE_PREFIX])
20
18
AC_REQUIRE([AC_LIB_RPATH])
21
pushdef([Name],[translit([$1],[./-], [___])])
22
pushdef([NAME],[translit([$1],[abcdefghijklmnopqrstuvwxyz./-],
23
[ABCDEFGHIJKLMNOPQRSTUVWXYZ___])])
19
define([Name],[translit([$1],[./-], [___])])
20
define([NAME],[translit([$1],[abcdefghijklmnopqrstuvwxyz./-],
21
[ABCDEFGHIJKLMNOPQRSTUVWXYZ___])])
24
22
AC_CACHE_CHECK([how to link with lib[]$1], [ac_cv_lib[]Name[]_libs], [
25
23
AC_LIB_LINKFLAGS_BODY([$1], [$2])
26
24
ac_cv_lib[]Name[]_libs="$LIB[]NAME"
27
25
ac_cv_lib[]Name[]_ltlibs="$LTLIB[]NAME"
28
26
ac_cv_lib[]Name[]_cppflags="$INC[]NAME"
29
ac_cv_lib[]Name[]_prefix="$LIB[]NAME[]_PREFIX"
31
28
LIB[]NAME="$ac_cv_lib[]Name[]_libs"
32
29
LTLIB[]NAME="$ac_cv_lib[]Name[]_ltlibs"
33
30
INC[]NAME="$ac_cv_lib[]Name[]_cppflags"
34
LIB[]NAME[]_PREFIX="$ac_cv_lib[]Name[]_prefix"
35
31
AC_LIB_APPENDTOVAR([CPPFLAGS], [$INC]NAME)
36
32
AC_SUBST([LIB]NAME)
37
33
AC_SUBST([LTLIB]NAME)
38
AC_SUBST([LIB]NAME[_PREFIX])
39
34
dnl Also set HAVE_LIB[]NAME so that AC_LIB_HAVE_LINKFLAGS can reuse the
40
35
dnl results of this search when this library appears as a dependency.
46
dnl AC_LIB_HAVE_LINKFLAGS(name, dependencies, includes, testcode, [missing-message])
41
dnl AC_LIB_HAVE_LINKFLAGS(name, dependencies, includes, testcode)
47
42
dnl searches for libname and the libraries corresponding to explicit and
48
43
dnl implicit dependencies, together with the specified include files and
49
dnl the ability to compile and link the specified testcode. The missing-message
50
dnl defaults to 'no' and may contain additional hints for the user.
51
dnl If found, it sets and AC_SUBSTs HAVE_LIB${NAME}=yes and the LIB${NAME}
52
dnl and LTLIB${NAME} variables and augments the CPPFLAGS variable, and
44
dnl the ability to compile and link the specified testcode. If found, it
45
dnl sets and AC_SUBSTs HAVE_LIB${NAME}=yes and the LIB${NAME} and
46
dnl LTLIB${NAME} variables and augments the CPPFLAGS variable, and
53
47
dnl #defines HAVE_LIB${NAME} to 1. Otherwise, it sets and AC_SUBSTs
54
48
dnl HAVE_LIB${NAME}=no and LIB${NAME} and LTLIB${NAME} to empty.
55
dnl Sets and AC_SUBSTs the LIB${NAME}_PREFIX variable to nonempty if libname
56
dnl was found in ${LIB${NAME}_PREFIX}/$acl_libdirstem.
57
49
AC_DEFUN([AC_LIB_HAVE_LINKFLAGS],
59
51
AC_REQUIRE([AC_LIB_PREPARE_PREFIX])
60
52
AC_REQUIRE([AC_LIB_RPATH])
61
pushdef([Name],[translit([$1],[./-], [___])])
62
pushdef([NAME],[translit([$1],[abcdefghijklmnopqrstuvwxyz./-],
63
[ABCDEFGHIJKLMNOPQRSTUVWXYZ___])])
53
define([Name],[translit([$1],[./-], [___])])
54
define([NAME],[translit([$1],[abcdefghijklmnopqrstuvwxyz./-],
55
[ABCDEFGHIJKLMNOPQRSTUVWXYZ___])])
65
57
dnl Search for lib[]Name and define LIB[]NAME, LTLIB[]NAME and INC[]NAME
75
67
AC_CACHE_CHECK([for lib[]$1], [ac_cv_lib[]Name], [
76
68
ac_save_LIBS="$LIBS"
77
dnl If $LIB[]NAME contains some -l options, add it to the end of LIBS,
78
dnl because these -l options might require -L options that are present in
79
dnl LIBS. -l options benefit only from the -L options listed before it.
80
dnl Otherwise, add it to the front of LIBS, because it may be a static
81
dnl library that depends on another static library that is present in LIBS.
82
dnl Static libraries benefit only from the static libraries listed after
85
*" -l"*) LIBS="$LIBS $LIB[]NAME" ;;
86
*) LIBS="$LIB[]NAME $LIBS" ;;
88
AC_TRY_LINK([$3], [$4],
89
[ac_cv_lib[]Name=yes],
90
[ac_cv_lib[]Name='m4_if([$5], [], [no], [[$5]])'])
69
LIBS="$LIBS $LIB[]NAME"
70
AC_TRY_LINK([$3], [$4], [ac_cv_lib[]Name=yes], [ac_cv_lib[]Name=no])
91
71
LIBS="$ac_save_LIBS"
93
73
if test "$ac_cv_lib[]Name" = yes; then
95
AC_DEFINE([HAVE_LIB]NAME, 1, [Define if you have the lib][$1 library.])
75
AC_DEFINE([HAVE_LIB]NAME, 1, [Define if you have the $1 library.])
96
76
AC_MSG_CHECKING([how to link with lib[]$1])
97
77
AC_MSG_RESULT([$LIB[]NAME])
135
109
acl_cv_rpath=done
138
acl_libext="$acl_cv_libext"
139
acl_shlibext="$acl_cv_shlibext"
140
acl_libname_spec="$acl_cv_libname_spec"
141
acl_library_names_spec="$acl_cv_library_names_spec"
142
acl_hardcode_libdir_flag_spec="$acl_cv_hardcode_libdir_flag_spec"
143
acl_hardcode_libdir_separator="$acl_cv_hardcode_libdir_separator"
144
acl_hardcode_direct="$acl_cv_hardcode_direct"
145
acl_hardcode_minus_L="$acl_cv_hardcode_minus_L"
112
libext="$acl_cv_libext"
113
shlibext="$acl_cv_shlibext"
114
hardcode_libdir_flag_spec="$acl_cv_hardcode_libdir_flag_spec"
115
hardcode_libdir_separator="$acl_cv_hardcode_libdir_separator"
116
hardcode_direct="$acl_cv_hardcode_direct"
117
hardcode_minus_L="$acl_cv_hardcode_minus_L"
146
118
dnl Determine whether the user wants rpath handling at all.
147
AC_ARG_ENABLE([rpath],
148
120
[ --disable-rpath do not hardcode runtime library paths],
149
121
:, enable_rpath=yes)
152
dnl AC_LIB_FROMPACKAGE(name, package)
153
dnl declares that libname comes from the given package. The configure file
154
dnl will then not have a --with-libname-prefix option but a
155
dnl --with-package-prefix option. Several libraries can come from the same
156
dnl package. This declaration must occur before an AC_LIB_LINKFLAGS or similar
157
dnl macro call that searches for libname.
158
AC_DEFUN([AC_LIB_FROMPACKAGE],
160
pushdef([NAME],[translit([$1],[abcdefghijklmnopqrstuvwxyz./-],
161
[ABCDEFGHIJKLMNOPQRSTUVWXYZ___])])
162
define([acl_frompackage_]NAME, [$2])
165
pushdef([PACKUP],[translit(PACK,[abcdefghijklmnopqrstuvwxyz./-],
166
[ABCDEFGHIJKLMNOPQRSTUVWXYZ___])])
167
define([acl_libsinpackage_]PACKUP,
168
m4_ifdef([acl_libsinpackage_]PACKUP, [acl_libsinpackage_]PACKUP[[, ]],)[lib$1])
173
124
dnl AC_LIB_LINKFLAGS_BODY(name [, dependencies]) searches for libname and
174
125
dnl the libraries corresponding to explicit and implicit dependencies.
175
126
dnl Sets the LIB${NAME}, LTLIB${NAME} and INC${NAME} variables.
176
dnl Also, sets the LIB${NAME}_PREFIX variable to nonempty if libname was found
177
dnl in ${LIB${NAME}_PREFIX}/$acl_libdirstem.
178
127
AC_DEFUN([AC_LIB_LINKFLAGS_BODY],
180
129
AC_REQUIRE([AC_LIB_PREPARE_MULTILIB])
181
pushdef([NAME],[translit([$1],[abcdefghijklmnopqrstuvwxyz./-],
182
[ABCDEFGHIJKLMNOPQRSTUVWXYZ___])])
183
pushdef([PACK],[m4_ifdef([acl_frompackage_]NAME, [acl_frompackage_]NAME, lib[$1])])
184
pushdef([PACKUP],[translit(PACK,[abcdefghijklmnopqrstuvwxyz./-],
185
[ABCDEFGHIJKLMNOPQRSTUVWXYZ___])])
186
pushdef([PACKLIBS],[m4_ifdef([acl_frompackage_]NAME, [acl_libsinpackage_]PACKUP, lib[$1])])
187
dnl Autoconf >= 2.61 supports dots in --with options.
188
pushdef([P_A_C_K],[m4_if(m4_version_compare(m4_defn([m4_PACKAGE_VERSION]),[2.61]),[-1],[translit(PACK,[.],[_])],PACK)])
130
define([NAME],[translit([$1],[abcdefghijklmnopqrstuvwxyz./-],
131
[ABCDEFGHIJKLMNOPQRSTUVWXYZ___])])
189
132
dnl By default, look in $includedir and $libdir.
190
133
use_additional=yes
191
134
AC_LIB_WITH_FINAL_PREFIX([
192
135
eval additional_includedir=\"$includedir\"
193
136
eval additional_libdir=\"$libdir\"
195
AC_ARG_WITH(P_A_C_K[-prefix],
196
[[ --with-]]P_A_C_K[[-prefix[=DIR] search for ]PACKLIBS[ in DIR/include and DIR/lib
197
--without-]]P_A_C_K[[-prefix don't search for ]PACKLIBS[ in includedir and libdir]],
138
AC_LIB_ARG_WITH([lib$1-prefix],
139
[ --with-lib$1-prefix[=DIR] search for lib$1 in DIR/include and DIR/lib
140
--without-lib$1-prefix don't search for lib$1 in includedir and libdir],
199
142
if test "X$withval" = "Xno"; then
200
143
use_additional=no
265
eval libname=\"$acl_libname_spec\" # typically: libname=lib$name
266
if test -n "$acl_shlibext"; then
267
shrext=".$acl_shlibext" # typically: shrext=.so
271
200
if test $use_additional = yes; then
272
dir="$additional_libdir"
273
dnl The same code as in the loop below:
274
dnl First look for a shared library.
275
if test -n "$acl_shlibext"; then
276
if test -f "$dir/$libname$shrext"; then
278
found_so="$dir/$libname$shrext"
280
if test "$acl_library_names_spec" = '$libname$shrext$versuffix'; then
282
for f in "$libname$shrext".*; do echo "$f"; done \
283
| sed -e "s,^$libname$shrext\\\\.,," \
284
| sort -t '.' -n -r -k1,1 -k2,2 -k3,3 -k4,4 -k5,5 \
285
| sed 1q ) 2>/dev/null`
286
if test -n "$ver" && test -f "$dir/$libname$shrext.$ver"; then
288
found_so="$dir/$libname$shrext.$ver"
291
eval library_names=\"$acl_library_names_spec\"
292
for f in $library_names; do
293
if test -f "$dir/$f"; then
201
if test -n "$shlibext" && test -f "$additional_libdir/lib$name.$shlibext"; then
202
found_dir="$additional_libdir"
203
found_so="$additional_libdir/lib$name.$shlibext"
204
if test -f "$additional_libdir/lib$name.la"; then
205
found_la="$additional_libdir/lib$name.la"
208
if test -f "$additional_libdir/lib$name.$libext"; then
209
found_dir="$additional_libdir"
210
found_a="$additional_libdir/lib$name.$libext"
211
if test -f "$additional_libdir/lib$name.la"; then
212
found_la="$additional_libdir/lib$name.la"
302
dnl Then look for a static library.
303
if test "X$found_dir" = "X"; then
304
if test -f "$dir/$libname.$acl_libext"; then
306
found_a="$dir/$libname.$acl_libext"
309
if test "X$found_dir" != "X"; then
310
if test -f "$dir/$libname.la"; then
311
found_la="$dir/$libname.la"
315
217
if test "X$found_dir" = "X"; then
316
218
for x in $LDFLAGS $LTLIB[]NAME; do
320
222
dir=`echo "X$x" | sed -e 's/^X-L//'`
321
dnl First look for a shared library.
322
if test -n "$acl_shlibext"; then
323
if test -f "$dir/$libname$shrext"; then
223
if test -n "$shlibext" && test -f "$dir/lib$name.$shlibext"; then
225
found_so="$dir/lib$name.$shlibext"
226
if test -f "$dir/lib$name.la"; then
227
found_la="$dir/lib$name.la"
230
if test -f "$dir/lib$name.$libext"; then
325
found_so="$dir/$libname$shrext"
327
if test "$acl_library_names_spec" = '$libname$shrext$versuffix'; then
329
for f in "$libname$shrext".*; do echo "$f"; done \
330
| sed -e "s,^$libname$shrext\\\\.,," \
331
| sort -t '.' -n -r -k1,1 -k2,2 -k3,3 -k4,4 -k5,5 \
332
| sed 1q ) 2>/dev/null`
333
if test -n "$ver" && test -f "$dir/$libname$shrext.$ver"; then
335
found_so="$dir/$libname$shrext.$ver"
338
eval library_names=\"$acl_library_names_spec\"
339
for f in $library_names; do
340
if test -f "$dir/$f"; then
232
found_a="$dir/lib$name.$libext"
233
if test -f "$dir/lib$name.la"; then
234
found_la="$dir/lib$name.la"
349
dnl Then look for a static library.
350
if test "X$found_dir" = "X"; then
351
if test -f "$dir/$libname.$acl_libext"; then
353
found_a="$dir/$libname.$acl_libext"
356
if test "X$found_dir" != "X"; then
357
if test -f "$dir/$libname.la"; then
358
found_la="$dir/$libname.la"
363
240
if test "X$found_dir" != "X"; then
462
337
case "$found_dir" in
463
338
*/$acl_libdirstem | */$acl_libdirstem/)
464
339
basedir=`echo "X$found_dir" | sed -e 's,^X,,' -e "s,/$acl_libdirstem/"'*$,,'`
465
if test "$name" = '$1'; then
466
LIB[]NAME[]_PREFIX="$basedir"
468
additional_includedir="$basedir/include"
470
*/$acl_libdirstem2 | */$acl_libdirstem2/)
471
basedir=`echo "X$found_dir" | sed -e 's,^X,,' -e "s,/$acl_libdirstem2/"'*$,,'`
472
if test "$name" = '$1'; then
473
LIB[]NAME[]_PREFIX="$basedir"
475
340
additional_includedir="$basedir/include"
637
500
if test "X$rpathdirs" != "X"; then
638
if test -n "$acl_hardcode_libdir_separator"; then
501
if test -n "$hardcode_libdir_separator"; then
639
502
dnl Weird platform: only the last -rpath option counts, the user must
640
503
dnl pass all path elements in one option. We can arrange that for a
641
504
dnl single library, but not when more than one $LIBNAMEs are used.
643
506
for found_dir in $rpathdirs; do
644
alldirs="${alldirs}${alldirs:+$acl_hardcode_libdir_separator}$found_dir"
507
alldirs="${alldirs}${alldirs:+$hardcode_libdir_separator}$found_dir"
646
dnl Note: acl_hardcode_libdir_flag_spec uses $libdir and $wl.
509
dnl Note: hardcode_libdir_flag_spec uses $libdir and $wl.
647
510
acl_save_libdir="$libdir"
648
511
libdir="$alldirs"
649
eval flag=\"$acl_hardcode_libdir_flag_spec\"
512
eval flag=\"$hardcode_libdir_flag_spec\"
650
513
libdir="$acl_save_libdir"
651
514
LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$flag"