1 # This file is part of Autoconf. -*- Autoconf -*-
2 # Checking for libraries.
3 # Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,
4 # 2002, 2003, 2004, 2005, 2006, 2008 Free Software Foundation, Inc.
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2, or (at your option)
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 # As a special exception, the Free Software Foundation gives unlimited
22 # permission to copy, distribute and modify the configure scripts that
23 # are the output of Autoconf. You need not follow the terms of the GNU
24 # General Public License when using or distributing such scripts, even
25 # though portions of the text of Autoconf appear in them. The GNU
26 # General Public License (GPL) does govern all other use of the material
27 # that constitutes the Autoconf program.
29 # Certain portions of the Autoconf source text are designed to be copied
30 # (in certain cases, depending on the input) into the output of
31 # Autoconf. We call these the "data" portions. The rest of the Autoconf
32 # source text consists of comments plus executable code that decides which
33 # of the data portions to output in any given case. We call these
34 # comments and executable code the "non-data" portions. Autoconf never
35 # copies any of the non-data portions into its output.
37 # This special exception to the GPL applies to versions of Autoconf
38 # released by the Free Software Foundation. When you make and
39 # distribute a modified version of Autoconf, you may extend this special
40 # exception to the GPL to apply to your modified version as well, *unless*
41 # your modified version has the potential to copy into its output some
42 # of the text that was the non-data portion of the version that you started
43 # with. (In other words, unless your change moves or copies text from
44 # the non-data portions to the data portions.) If your modification has
45 # such potential, you must delete any notice of this special exception
46 # to the GPL from your modified version.
48 # Written by David MacKenzie, with help from
49 # Franc,ois Pinard, Karl Berry, Richard Pixley, Ian Lance Taylor,
50 # Roland McGrath, Noah Friedman, david d zuhn, and many others.
54 # 1. Generic tests for libraries
55 # 2. Tests for specific libraries
58 ## --------------------------------- ##
59 ## 1. Generic tests for libraries.## ##
60 ## --------------------------------- ##
64 # AC_SEARCH_LIBS(FUNCTION, SEARCH-LIBS,
65 # [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND],
67 # --------------------------------------------------------
68 # Search for a library defining FUNC, if it's not already available.
69 AC_DEFUN([AC_SEARCH_LIBS],
70 [AS_VAR_PUSHDEF([ac_Search], [ac_cv_search_$1])dnl
71 AC_CACHE_CHECK([for library containing $1], [ac_Search],
72 [ac_func_search_save_LIBS=$LIBS
73 AC_LANG_CONFTEST([AC_LANG_CALL([], [$1])])
74 for ac_lib in '' $2; do
75 if test -z "$ac_lib"; then
76 ac_res="none required"
79 LIBS="-l$ac_lib $5 $ac_func_search_save_LIBS"
81 AC_LINK_IFELSE([], [AS_VAR_SET([ac_Search], [$ac_res])])
82 AS_VAR_SET_IF([ac_Search], [break])dnl
84 AS_VAR_SET_IF([ac_Search], , [AS_VAR_SET([ac_Search], [no])])dnl
86 LIBS=$ac_func_search_save_LIBS])
87 ac_res=AS_VAR_GET([ac_Search])
88 AS_IF([test "$ac_res" != no],
89 [test "$ac_res" = "none required" || LIBS="$ac_res $LIBS"
92 AS_VAR_POPDEF([ac_Search])dnl
97 # AC_CHECK_LIB(LIBRARY, FUNCTION,
98 # [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND],
100 # ------------------------------------------------------
102 # Use a cache variable name containing both the library and function name,
103 # because the test really is for library $1 defining function $2, not
104 # just for library $1. Separate tests with the same $1 and different $2s
105 # may have different results.
107 # Note that using directly AS_VAR_PUSHDEF([ac_Lib], [ac_cv_lib_$1_$2])
108 # is asking for troubles, since AC_CHECK_LIB($lib, fun) would give
109 # ac_cv_lib_$lib_fun, which is definitely not what was meant. Hence
110 # the AS_LITERAL_IF indirection.
112 # FIXME: This macro is extremely suspicious. It DEFINEs unconditionally,
113 # whatever the FUNCTION, in addition to not being a *S macro. Note
114 # that the cache does depend upon the function we are looking for.
116 # It is on purpose we used `ac_check_lib_save_LIBS' and not just
117 # `ac_save_LIBS': there are many macros which don't want to see `LIBS'
118 # changed but still want to use AC_CHECK_LIB, so they save `LIBS'.
119 # And ``ac_save_LIBS' is too tempting a name, so let's leave them some
121 AC_DEFUN([AC_CHECK_LIB],
122 [m4_ifval([$3], , [AH_CHECK_LIB([$1])])dnl
124 [AS_VAR_PUSHDEF([ac_Lib], [ac_cv_lib_$1_$2])],
125 [AS_VAR_PUSHDEF([ac_Lib], [ac_cv_lib_$1''_$2])])dnl
126 AC_CACHE_CHECK([for $2 in -l$1], [ac_Lib],
127 [ac_check_lib_save_LIBS=$LIBS
129 AC_LINK_IFELSE([AC_LANG_CALL([], [$2])],
130 [AS_VAR_SET([ac_Lib], [yes])],
131 [AS_VAR_SET([ac_Lib], [no])])
132 LIBS=$ac_check_lib_save_LIBS])
133 AS_IF([test AS_VAR_GET([ac_Lib]) = yes],
134 [m4_default([$3], [AC_DEFINE_UNQUOTED(AS_TR_CPP(HAVE_LIB$1))
138 AS_VAR_POPDEF([ac_Lib])dnl
142 # AH_CHECK_LIB(LIBNAME)
143 # ---------------------
144 m4_define([AH_CHECK_LIB],
145 [AH_TEMPLATE(AS_TR_CPP([HAVE_LIB$1]),
146 [Define to 1 if you have the `$1' library (-l$1).])])
149 # AC_HAVE_LIBRARY(LIBRARY,
150 # [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND],
152 # ---------------------------------------------------------
154 # This macro is equivalent to calling `AC_CHECK_LIB' with a FUNCTION
155 # argument of `main'. In addition, LIBRARY can be written as any of
156 # `foo', `-lfoo', or `libfoo.a'. In all of those cases, the compiler
157 # is passed `-lfoo'. However, LIBRARY cannot be a shell variable;
158 # it must be a literal name.
159 AU_DEFUN([AC_HAVE_LIBRARY],
160 [m4_pushdef([AC_Lib_Name],
161 m4_bpatsubst(m4_bpatsubst([[$1]],
162 [lib\([^\.]*\)\.a], [\1]),
164 AC_CHECK_LIB(AC_Lib_Name, main, [$2], [$3], [$4])dnl
165 ac_cv_lib_[]AC_Lib_Name()=ac_cv_lib_[]AC_Lib_Name()_main
166 m4_popdef([AC_Lib_Name])dnl
172 ## --------------------------------- ##
173 ## 2. Tests for specific libraries. ##
174 ## --------------------------------- ##
178 # --------------------- #
179 # Checks for X window. #
180 # --------------------- #
185 # Internal subroutine of _AC_PATH_X.
186 # Set ac_x_includes and/or ac_x_libraries.
187 m4_define([_AC_PATH_X_XMKMF],
188 [AC_ARG_VAR(XMKMF, [Path to xmkmf, Makefile generator for X Window System])dnl
189 rm -f -r conftest.dir
190 if mkdir conftest.dir; then
192 cat >Imakefile <<'_ACEOF'
194 @echo incroot='${INCROOT}'
196 @echo usrlibdir='${USRLIBDIR}'
198 @echo libdir='${LIBDIR}'
200 if (export CC; ${XMKMF-xmkmf}) >/dev/null 2>/dev/null && test -f Makefile; then
201 # GNU make sometimes prints "make[1]: Entering...", which would confuse us.
202 for ac_var in incroot usrlibdir libdir; do
203 eval "ac_im_$ac_var=\`\${MAKE-make} $ac_var 2>/dev/null | sed -n 's/^$ac_var=//p'\`"
205 # Open Windows xmkmf reportedly sets LIBDIR instead of USRLIBDIR.
206 for ac_extension in a so sl dylib la dll; do
207 if test ! -f "$ac_im_usrlibdir/libX11.$ac_extension" &&
208 test -f "$ac_im_libdir/libX11.$ac_extension"; then
209 ac_im_usrlibdir=$ac_im_libdir; break
212 # Screen out bogus values from the imake configuration. They are
213 # bogus both because they are the default anyway, and because
214 # using them would break gcc on systems where it needs fixed includes.
215 case $ac_im_incroot in
216 /usr/include) ac_x_includes= ;;
217 *) test -f "$ac_im_incroot/X11/Xos.h" && ac_x_includes=$ac_im_incroot;;
219 case $ac_im_usrlibdir in
220 /usr/lib | /usr/lib64 | /lib | /lib64) ;;
221 *) test -d "$ac_im_usrlibdir" && ac_x_libraries=$ac_im_usrlibdir ;;
225 rm -f -r conftest.dir
232 # Internal subroutine of _AC_PATH_X.
233 # Set ac_x_includes and/or ac_x_libraries.
234 m4_define([_AC_PATH_X_DIRECT],
235 [# Standard set of common directories for X headers.
236 # Check X11 before X11Rn because it is often a symlink to the current release.
248 /usr/local/X11/include
249 /usr/local/X11R6/include
250 /usr/local/X11R5/include
251 /usr/local/X11R4/include
253 /usr/local/include/X11
254 /usr/local/include/X11R6
255 /usr/local/include/X11R5
256 /usr/local/include/X11R4
260 /usr/XFree86/include/X11
264 /usr/unsupported/include
266 /usr/local/x11r5/include
267 /usr/lpp/Xamples/include
270 /usr/openwin/share/include'
272 if test "$ac_x_includes" = no; then
273 # Guess where to find include files, by looking for Xlib.h.
274 # First, try using that file with no special directory specified.
275 AC_PREPROC_IFELSE([AC_LANG_SOURCE([@%:@include <X11/Xlib.h>])],
276 [# We can compile using X headers with no special include directory.
278 [for ac_dir in $ac_x_header_dirs; do
279 if test -r "$ac_dir/X11/Xlib.h"; then
280 ac_x_includes=$ac_dir
284 fi # $ac_x_includes = no
286 if test "$ac_x_libraries" = no; then
287 # Check for the libraries.
288 # See if we find them without any special options.
289 # Don't add to $LIBS permanently.
292 AC_LINK_IFELSE([AC_LANG_PROGRAM([@%:@include <X11/Xlib.h>],
293 [XrmInitialize ()])],
295 # We can link X programs with no special library path.
298 for ac_dir in `AS_ECHO(["$ac_x_includes $ac_x_header_dirs"]) | sed s/include/lib/g`
300 # Don't even attempt the hair of trying to link an X program!
301 for ac_extension in a so sl dylib la dll; do
302 if test -r "$ac_dir/libX11.$ac_extension"; then
303 ac_x_libraries=$ac_dir
308 fi # $ac_x_libraries = no
309 ])# _AC_PATH_X_DIRECT
314 # Compute ac_cv_have_x.
315 AC_DEFUN([_AC_PATH_X],
316 [AC_CACHE_VAL(ac_cv_have_x,
317 [# One or both of the vars are not set, and there is no cached value.
318 ac_x_includes=no ac_x_libraries=no
321 case $ac_x_includes,$ac_x_libraries in #(
323 # Didn't find X, or a directory has "'" in its name.
324 ac_cv_have_x="have_x=no";; #(
326 # Record where we found X for the cache.
327 ac_cv_have_x="have_x=yes\
328 ac_x_includes='$ac_x_includes'\
329 ac_x_libraries='$ac_x_libraries'"
336 # If we find X, set shell vars x_includes and x_libraries to the
337 # paths, otherwise set no_x=yes.
338 # Uses ac_ vars as temps to allow command line to override cache and checks.
339 # --without-x overrides everything else, but does not touch the cache.
340 AN_HEADER([X11/Xlib.h], [AC_PATH_X])
341 AC_DEFUN([AC_PATH_X],
342 [dnl Document the X abnormal options inherited from history.
343 m4_divert_once([HELP_BEGIN], [
345 --x-includes=DIR X include files are in DIR
346 --x-libraries=DIR X library files are in DIR])dnl
347 AC_MSG_CHECKING([for X])
349 AC_ARG_WITH(x, [ --with-x use the X Window System])
350 # $have_x is `yes', `no', `disabled', or empty when we do not yet know.
351 if test "x$with_x" = xno; then
352 # The user explicitly disabled X.
355 case $x_includes,$x_libraries in #(
356 *\'*) AC_MSG_ERROR([Cannot use X directory names containing ']);; #(
357 *,NONE | NONE,*) _AC_PATH_X;; #(
363 if test "$have_x" != yes; then
364 AC_MSG_RESULT([$have_x])
367 # If each of the values was on the command line, it overrides each guess.
368 test "x$x_includes" = xNONE && x_includes=$ac_x_includes
369 test "x$x_libraries" = xNONE && x_libraries=$ac_x_libraries
370 # Update the cache value to reflect the command line values.
371 ac_cv_have_x="have_x=yes\
372 ac_x_includes='$x_includes'\
373 ac_x_libraries='$x_libraries'"
374 AC_MSG_RESULT([libraries $x_libraries, headers $x_includes])
382 # Find additional X libraries, magic flags, etc.
383 AC_DEFUN([AC_PATH_XTRA],
384 [AC_REQUIRE([AC_PATH_X])dnl
385 if test "$no_x" = yes; then
386 # Not all programs may use this symbol, but it does not hurt to define it.
387 AC_DEFINE([X_DISPLAY_MISSING], 1,
388 [Define to 1 if the X Window System is missing or not being used.])
389 X_CFLAGS= X_PRE_LIBS= X_LIBS= X_EXTRA_LIBS=
391 if test -n "$x_includes"; then
392 X_CFLAGS="$X_CFLAGS -I$x_includes"
395 # It would also be nice to do this for all -L options, not just this one.
396 if test -n "$x_libraries"; then
397 X_LIBS="$X_LIBS -L$x_libraries"
398 # For Solaris; some versions of Sun CC require a space after -R and
399 # others require no space. Words are not sufficient . . . .
400 AC_MSG_CHECKING([whether -R must be followed by a space])
401 ac_xsave_LIBS=$LIBS; LIBS="$LIBS -R$x_libraries"
402 ac_xsave_[]_AC_LANG_ABBREV[]_werror_flag=$ac_[]_AC_LANG_ABBREV[]_werror_flag
403 ac_[]_AC_LANG_ABBREV[]_werror_flag=yes
404 AC_LINK_IFELSE([AC_LANG_PROGRAM()],
406 X_LIBS="$X_LIBS -R$x_libraries"],
407 [LIBS="$ac_xsave_LIBS -R $x_libraries"
408 AC_LINK_IFELSE([AC_LANG_PROGRAM()],
409 [AC_MSG_RESULT([yes])
410 X_LIBS="$X_LIBS -R $x_libraries"],
411 [AC_MSG_RESULT([neither works])])])
412 ac_[]_AC_LANG_ABBREV[]_werror_flag=$ac_xsave_[]_AC_LANG_ABBREV[]_werror_flag
416 # Check for system-dependent libraries X programs must link with.
417 # Do this before checking for the system-independent R6 libraries
418 # (-lICE), since we may need -lsocket or whatever for X linking.
420 if test "$ISC" = yes; then
421 X_EXTRA_LIBS="$X_EXTRA_LIBS -lnsl_s -linet"
423 # Martyn Johnson says this is needed for Ultrix, if the X
424 # libraries were built with DECnet support. And Karl Berry says
425 # the Alpha needs dnet_stub (dnet does not exist).
426 ac_xsave_LIBS="$LIBS"; LIBS="$LIBS $X_LIBS -lX11"
427 AC_LINK_IFELSE([AC_LANG_CALL([], [XOpenDisplay])],
429 [AC_CHECK_LIB(dnet, dnet_ntoa, [X_EXTRA_LIBS="$X_EXTRA_LIBS -ldnet"])
430 if test $ac_cv_lib_dnet_dnet_ntoa = no; then
431 AC_CHECK_LIB(dnet_stub, dnet_ntoa,
432 [X_EXTRA_LIBS="$X_EXTRA_LIBS -ldnet_stub"])
434 LIBS="$ac_xsave_LIBS"
436 # msh@cis.ufl.edu says -lnsl (and -lsocket) are needed for his 386/AT,
437 # to get the SysV transport functions.
438 # Chad R. Larson says the Pyramis MIS-ES running DC/OSx (SVR4)
440 # The nsl library prevents programs from opening the X display
441 # on Irix 5.2, according to T.E. Dickey.
442 # The functions gethostbyname, getservbyname, and inet_addr are
443 # in -lbsd on LynxOS 3.0.1/i386, according to Lars Hecking.
444 AC_CHECK_FUNC(gethostbyname)
445 if test $ac_cv_func_gethostbyname = no; then
446 AC_CHECK_LIB(nsl, gethostbyname, X_EXTRA_LIBS="$X_EXTRA_LIBS -lnsl")
447 if test $ac_cv_lib_nsl_gethostbyname = no; then
448 AC_CHECK_LIB(bsd, gethostbyname, X_EXTRA_LIBS="$X_EXTRA_LIBS -lbsd")
452 # lieder@skyler.mavd.honeywell.com says without -lsocket,
453 # socket/setsockopt and other routines are undefined under SCO ODT
454 # 2.0. But -lsocket is broken on IRIX 5.2 (and is not necessary
455 # on later versions), says Simon Leinen: it contains gethostby*
456 # variants that don't use the name server (or something). -lsocket
457 # must be given before -lnsl if both are needed. We assume that
458 # if connect needs -lnsl, so does gethostbyname.
459 AC_CHECK_FUNC(connect)
460 if test $ac_cv_func_connect = no; then
461 AC_CHECK_LIB(socket, connect, X_EXTRA_LIBS="-lsocket $X_EXTRA_LIBS", ,
465 # Guillermo Gomez says -lposix is necessary on A/UX.
466 AC_CHECK_FUNC(remove)
467 if test $ac_cv_func_remove = no; then
468 AC_CHECK_LIB(posix, remove, X_EXTRA_LIBS="$X_EXTRA_LIBS -lposix")
471 # BSDI BSD/OS 2.1 needs -lipc for XOpenDisplay.
473 if test $ac_cv_func_shmat = no; then
474 AC_CHECK_LIB(ipc, shmat, X_EXTRA_LIBS="$X_EXTRA_LIBS -lipc")
478 # Check for libraries that X11R6 Xt/Xaw programs need.
479 ac_save_LDFLAGS=$LDFLAGS
480 test -n "$x_libraries" && LDFLAGS="$LDFLAGS -L$x_libraries"
481 # SM needs ICE to (dynamically) link under SunOS 4.x (so we have to
482 # check for ICE first), but we must link in the order -lSM -lICE or
483 # we get undefined symbols. So assume we have SM if we have ICE.
484 # These have to be linked with before -lX11, unlike the other
485 # libraries we check for below, so use a different variable.
486 # John Interrante, Karl Berry
487 AC_CHECK_LIB(ICE, IceConnectionNumber,
488 [X_PRE_LIBS="$X_PRE_LIBS -lSM -lICE"], , $X_EXTRA_LIBS)
489 LDFLAGS=$ac_save_LDFLAGS
492 AC_SUBST(X_CFLAGS)dnl
493 AC_SUBST(X_PRE_LIBS)dnl
495 AC_SUBST(X_EXTRA_LIBS)dnl