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, 2009 Free Software Foundation,
7 # This file is part of Autoconf. This program is free
8 # software; you can redistribute it and/or modify it under the
9 # terms of the GNU General Public License as published by the
10 # Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # Under Section 7 of GPL version 3, you are granted additional
19 # permissions described in the Autoconf Configure Script Exception,
20 # version 3.0, as published by the Free Software Foundation.
22 # You should have received a copy of the GNU General Public License
23 # and a copy of the Autoconf Configure Script Exception along with
24 # this program; see the files COPYINGv3 and COPYING.EXCEPTION
25 # respectively. If not, see <http://www.gnu.org/licenses/>.
27 # Written by David MacKenzie, with help from
28 # Franc,ois Pinard, Karl Berry, Richard Pixley, Ian Lance Taylor,
29 # Roland McGrath, Noah Friedman, david d zuhn, and many others.
33 # 1. Generic tests for libraries
34 # 2. Tests for specific libraries
37 ## --------------------------------- ##
38 ## 1. Generic tests for libraries.## ##
39 ## --------------------------------- ##
43 # AC_SEARCH_LIBS(FUNCTION, SEARCH-LIBS,
44 # [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND],
46 # --------------------------------------------------------
47 # Search for a library defining FUNC, if it's not already available.
48 AC_DEFUN([AC_SEARCH_LIBS],
49 [AS_VAR_PUSHDEF([ac_Search], [ac_cv_search_$1])dnl
50 AC_CACHE_CHECK([for library containing $1], [ac_Search],
51 [ac_func_search_save_LIBS=$LIBS
52 AC_LANG_CONFTEST([AC_LANG_CALL([], [$1])])
53 for ac_lib in '' $2; do
54 if test -z "$ac_lib"; then
55 ac_res="none required"
58 LIBS="-l$ac_lib $5 $ac_func_search_save_LIBS"
60 AC_LINK_IFELSE([], [AS_VAR_SET([ac_Search], [$ac_res])])
61 AS_VAR_SET_IF([ac_Search], [break])
63 AS_VAR_SET_IF([ac_Search], , [AS_VAR_SET([ac_Search], [no])])
65 LIBS=$ac_func_search_save_LIBS])
66 AS_VAR_COPY([ac_res], [ac_Search])
67 AS_IF([test "$ac_res" != no],
68 [test "$ac_res" = "none required" || LIBS="$ac_res $LIBS"
71 AS_VAR_POPDEF([ac_Search])dnl
76 # AC_CHECK_LIB(LIBRARY, FUNCTION,
77 # [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND],
79 # ------------------------------------------------------
81 # Use a cache variable name containing both the library and function name,
82 # because the test really is for library $1 defining function $2, not
83 # just for library $1. Separate tests with the same $1 and different $2s
84 # may have different results.
86 # Note that using directly AS_VAR_PUSHDEF([ac_Lib], [ac_cv_lib_$1_$2])
87 # is asking for troubles, since AC_CHECK_LIB($lib, fun) would give
88 # ac_cv_lib_$lib_fun, which is definitely not what was meant. Hence
89 # the AS_LITERAL_IF indirection.
91 # FIXME: This macro is extremely suspicious. It DEFINEs unconditionally,
92 # whatever the FUNCTION, in addition to not being a *S macro. Note
93 # that the cache does depend upon the function we are looking for.
95 # It is on purpose we used `ac_check_lib_save_LIBS' and not just
96 # `ac_save_LIBS': there are many macros which don't want to see `LIBS'
97 # changed but still want to use AC_CHECK_LIB, so they save `LIBS'.
98 # And ``ac_save_LIBS' is too tempting a name, so let's leave them some
100 AC_DEFUN([AC_CHECK_LIB],
101 [m4_ifval([$3], , [AH_CHECK_LIB([$1])])dnl
103 [AS_VAR_PUSHDEF([ac_Lib], [ac_cv_lib_$1_$2])],
104 [AS_VAR_PUSHDEF([ac_Lib], [ac_cv_lib_$1''_$2])])dnl
105 AC_CACHE_CHECK([for $2 in -l$1], [ac_Lib],
106 [ac_check_lib_save_LIBS=$LIBS
108 AC_LINK_IFELSE([AC_LANG_CALL([], [$2])],
109 [AS_VAR_SET([ac_Lib], [yes])],
110 [AS_VAR_SET([ac_Lib], [no])])
111 LIBS=$ac_check_lib_save_LIBS])
112 AS_VAR_IF([ac_Lib], [yes],
113 [m4_default([$3], [AC_DEFINE_UNQUOTED(AS_TR_CPP(HAVE_LIB$1))
117 AS_VAR_POPDEF([ac_Lib])dnl
121 # AH_CHECK_LIB(LIBNAME)
122 # ---------------------
123 m4_define([AH_CHECK_LIB],
124 [AH_TEMPLATE(AS_TR_CPP([HAVE_LIB$1]),
125 [Define to 1 if you have the `$1' library (-l$1).])])
128 # AC_HAVE_LIBRARY(LIBRARY,
129 # [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND],
131 # ---------------------------------------------------------
133 # This macro is equivalent to calling `AC_CHECK_LIB' with a FUNCTION
134 # argument of `main'. In addition, LIBRARY can be written as any of
135 # `foo', `-lfoo', or `libfoo.a'. In all of those cases, the compiler
136 # is passed `-lfoo'. However, LIBRARY cannot be a shell variable;
137 # it must be a literal name.
138 AU_DEFUN([AC_HAVE_LIBRARY],
139 [m4_pushdef([AC_Lib_Name],
140 m4_bpatsubst(m4_bpatsubst([[$1]],
141 [lib\([^\.]*\)\.a], [\1]),
143 AC_CHECK_LIB(AC_Lib_Name, main, [$2], [$3], [$4])dnl
144 ac_cv_lib_[]AC_Lib_Name()=ac_cv_lib_[]AC_Lib_Name()_main
145 m4_popdef([AC_Lib_Name])dnl
151 ## --------------------------------- ##
152 ## 2. Tests for specific libraries. ##
153 ## --------------------------------- ##
157 # --------------------- #
158 # Checks for X window. #
159 # --------------------- #
164 # Internal subroutine of _AC_PATH_X.
165 # Set ac_x_includes and/or ac_x_libraries.
166 m4_define([_AC_PATH_X_XMKMF],
167 [AC_ARG_VAR(XMKMF, [Path to xmkmf, Makefile generator for X Window System])dnl
168 rm -f -r conftest.dir
169 if mkdir conftest.dir; then
171 cat >Imakefile <<'_ACEOF'
173 @echo incroot='${INCROOT}'
175 @echo usrlibdir='${USRLIBDIR}'
177 @echo libdir='${LIBDIR}'
179 if (export CC; ${XMKMF-xmkmf}) >/dev/null 2>/dev/null && test -f Makefile; then
180 # GNU make sometimes prints "make[1]: Entering...", which would confuse us.
181 for ac_var in incroot usrlibdir libdir; do
182 eval "ac_im_$ac_var=\`\${MAKE-make} $ac_var 2>/dev/null | sed -n 's/^$ac_var=//p'\`"
184 # Open Windows xmkmf reportedly sets LIBDIR instead of USRLIBDIR.
185 for ac_extension in a so sl dylib la dll; do
186 if test ! -f "$ac_im_usrlibdir/libX11.$ac_extension" &&
187 test -f "$ac_im_libdir/libX11.$ac_extension"; then
188 ac_im_usrlibdir=$ac_im_libdir; break
191 # Screen out bogus values from the imake configuration. They are
192 # bogus both because they are the default anyway, and because
193 # using them would break gcc on systems where it needs fixed includes.
194 case $ac_im_incroot in
195 /usr/include) ac_x_includes= ;;
196 *) test -f "$ac_im_incroot/X11/Xos.h" && ac_x_includes=$ac_im_incroot;;
198 case $ac_im_usrlibdir in
199 /usr/lib | /usr/lib64 | /lib | /lib64) ;;
200 *) test -d "$ac_im_usrlibdir" && ac_x_libraries=$ac_im_usrlibdir ;;
204 rm -f -r conftest.dir
211 # Internal subroutine of _AC_PATH_X.
212 # Set ac_x_includes and/or ac_x_libraries.
213 m4_define([_AC_PATH_X_DIRECT],
214 [# Standard set of common directories for X headers.
215 # Check X11 before X11Rn because it is often a symlink to the current release.
229 /usr/local/X11/include
230 /usr/local/X11R7/include
231 /usr/local/X11R6/include
232 /usr/local/X11R5/include
233 /usr/local/X11R4/include
235 /usr/local/include/X11
236 /usr/local/include/X11R7
237 /usr/local/include/X11R6
238 /usr/local/include/X11R5
239 /usr/local/include/X11R4
243 /usr/XFree86/include/X11
247 /usr/unsupported/include
249 /usr/local/x11r5/include
250 /usr/lpp/Xamples/include
253 /usr/openwin/share/include'
255 if test "$ac_x_includes" = no; then
256 # Guess where to find include files, by looking for Xlib.h.
257 # First, try using that file with no special directory specified.
258 AC_PREPROC_IFELSE([AC_LANG_SOURCE([@%:@include <X11/Xlib.h>])],
259 [# We can compile using X headers with no special include directory.
261 [for ac_dir in $ac_x_header_dirs; do
262 if test -r "$ac_dir/X11/Xlib.h"; then
263 ac_x_includes=$ac_dir
267 fi # $ac_x_includes = no
269 if test "$ac_x_libraries" = no; then
270 # Check for the libraries.
271 # See if we find them without any special options.
272 # Don't add to $LIBS permanently.
275 AC_LINK_IFELSE([AC_LANG_PROGRAM([@%:@include <X11/Xlib.h>],
276 [XrmInitialize ()])],
278 # We can link X programs with no special library path.
281 for ac_dir in `AS_ECHO(["$ac_x_includes $ac_x_header_dirs"]) | sed s/include/lib/g`
283 # Don't even attempt the hair of trying to link an X program!
284 for ac_extension in a so sl dylib la dll; do
285 if test -r "$ac_dir/libX11.$ac_extension"; then
286 ac_x_libraries=$ac_dir
291 fi # $ac_x_libraries = no
292 ])# _AC_PATH_X_DIRECT
297 # Compute ac_cv_have_x.
298 AC_DEFUN([_AC_PATH_X],
299 [AC_CACHE_VAL(ac_cv_have_x,
300 [# One or both of the vars are not set, and there is no cached value.
301 ac_x_includes=no ac_x_libraries=no
304 case $ac_x_includes,$ac_x_libraries in #(
306 # Didn't find X, or a directory has "'" in its name.
307 ac_cv_have_x="have_x=no";; #(
309 # Record where we found X for the cache.
310 ac_cv_have_x="have_x=yes\
311 ac_x_includes='$ac_x_includes'\
312 ac_x_libraries='$ac_x_libraries'"
319 # If we find X, set shell vars x_includes and x_libraries to the
320 # paths, otherwise set no_x=yes.
321 # Uses ac_ vars as temps to allow command line to override cache and checks.
322 # --without-x overrides everything else, but does not touch the cache.
323 AN_HEADER([X11/Xlib.h], [AC_PATH_X])
324 AC_DEFUN([AC_PATH_X],
325 [dnl Document the X abnormal options inherited from history.
326 m4_divert_once([HELP_BEGIN], [
328 --x-includes=DIR X include files are in DIR
329 --x-libraries=DIR X library files are in DIR])dnl
330 AC_MSG_CHECKING([for X])
332 AC_ARG_WITH(x, [ --with-x use the X Window System])
333 # $have_x is `yes', `no', `disabled', or empty when we do not yet know.
334 if test "x$with_x" = xno; then
335 # The user explicitly disabled X.
338 case $x_includes,$x_libraries in #(
339 *\'*) AC_MSG_ERROR([cannot use X directory names containing ']);; #(
340 *,NONE | NONE,*) _AC_PATH_X;; #(
346 if test "$have_x" != yes; then
347 AC_MSG_RESULT([$have_x])
350 # If each of the values was on the command line, it overrides each guess.
351 test "x$x_includes" = xNONE && x_includes=$ac_x_includes
352 test "x$x_libraries" = xNONE && x_libraries=$ac_x_libraries
353 # Update the cache value to reflect the command line values.
354 ac_cv_have_x="have_x=yes\
355 ac_x_includes='$x_includes'\
356 ac_x_libraries='$x_libraries'"
357 AC_MSG_RESULT([libraries $x_libraries, headers $x_includes])
365 # Find additional X libraries, magic flags, etc.
366 AC_DEFUN([AC_PATH_XTRA],
367 [AC_REQUIRE([AC_PATH_X])dnl
368 if test "$no_x" = yes; then
369 # Not all programs may use this symbol, but it does not hurt to define it.
370 AC_DEFINE([X_DISPLAY_MISSING], 1,
371 [Define to 1 if the X Window System is missing or not being used.])
372 X_CFLAGS= X_PRE_LIBS= X_LIBS= X_EXTRA_LIBS=
374 if test -n "$x_includes"; then
375 X_CFLAGS="$X_CFLAGS -I$x_includes"
378 # It would also be nice to do this for all -L options, not just this one.
379 if test -n "$x_libraries"; then
380 X_LIBS="$X_LIBS -L$x_libraries"
381 # For Solaris; some versions of Sun CC require a space after -R and
382 # others require no space. Words are not sufficient . . . .
383 AC_MSG_CHECKING([whether -R must be followed by a space])
384 ac_xsave_LIBS=$LIBS; LIBS="$LIBS -R$x_libraries"
385 ac_xsave_[]_AC_LANG_ABBREV[]_werror_flag=$ac_[]_AC_LANG_ABBREV[]_werror_flag
386 ac_[]_AC_LANG_ABBREV[]_werror_flag=yes
387 AC_LINK_IFELSE([AC_LANG_PROGRAM()],
389 X_LIBS="$X_LIBS -R$x_libraries"],
390 [LIBS="$ac_xsave_LIBS -R $x_libraries"
391 AC_LINK_IFELSE([AC_LANG_PROGRAM()],
392 [AC_MSG_RESULT([yes])
393 X_LIBS="$X_LIBS -R $x_libraries"],
394 [AC_MSG_RESULT([neither works])])])
395 ac_[]_AC_LANG_ABBREV[]_werror_flag=$ac_xsave_[]_AC_LANG_ABBREV[]_werror_flag
399 # Check for system-dependent libraries X programs must link with.
400 # Do this before checking for the system-independent R6 libraries
401 # (-lICE), since we may need -lsocket or whatever for X linking.
403 if test "$ISC" = yes; then
404 X_EXTRA_LIBS="$X_EXTRA_LIBS -lnsl_s -linet"
406 # Martyn Johnson says this is needed for Ultrix, if the X
407 # libraries were built with DECnet support. And Karl Berry says
408 # the Alpha needs dnet_stub (dnet does not exist).
409 ac_xsave_LIBS="$LIBS"; LIBS="$LIBS $X_LIBS -lX11"
410 AC_LINK_IFELSE([AC_LANG_CALL([], [XOpenDisplay])],
412 [AC_CHECK_LIB(dnet, dnet_ntoa, [X_EXTRA_LIBS="$X_EXTRA_LIBS -ldnet"])
413 if test $ac_cv_lib_dnet_dnet_ntoa = no; then
414 AC_CHECK_LIB(dnet_stub, dnet_ntoa,
415 [X_EXTRA_LIBS="$X_EXTRA_LIBS -ldnet_stub"])
417 LIBS="$ac_xsave_LIBS"
419 # msh@cis.ufl.edu says -lnsl (and -lsocket) are needed for his 386/AT,
420 # to get the SysV transport functions.
421 # Chad R. Larson says the Pyramis MIS-ES running DC/OSx (SVR4)
423 # The nsl library prevents programs from opening the X display
424 # on Irix 5.2, according to T.E. Dickey.
425 # The functions gethostbyname, getservbyname, and inet_addr are
426 # in -lbsd on LynxOS 3.0.1/i386, according to Lars Hecking.
427 AC_CHECK_FUNC(gethostbyname)
428 if test $ac_cv_func_gethostbyname = no; then
429 AC_CHECK_LIB(nsl, gethostbyname, X_EXTRA_LIBS="$X_EXTRA_LIBS -lnsl")
430 if test $ac_cv_lib_nsl_gethostbyname = no; then
431 AC_CHECK_LIB(bsd, gethostbyname, X_EXTRA_LIBS="$X_EXTRA_LIBS -lbsd")
435 # lieder@skyler.mavd.honeywell.com says without -lsocket,
436 # socket/setsockopt and other routines are undefined under SCO ODT
437 # 2.0. But -lsocket is broken on IRIX 5.2 (and is not necessary
438 # on later versions), says Simon Leinen: it contains gethostby*
439 # variants that don't use the name server (or something). -lsocket
440 # must be given before -lnsl if both are needed. We assume that
441 # if connect needs -lnsl, so does gethostbyname.
442 AC_CHECK_FUNC(connect)
443 if test $ac_cv_func_connect = no; then
444 AC_CHECK_LIB(socket, connect, X_EXTRA_LIBS="-lsocket $X_EXTRA_LIBS", ,
448 # Guillermo Gomez says -lposix is necessary on A/UX.
449 AC_CHECK_FUNC(remove)
450 if test $ac_cv_func_remove = no; then
451 AC_CHECK_LIB(posix, remove, X_EXTRA_LIBS="$X_EXTRA_LIBS -lposix")
454 # BSDI BSD/OS 2.1 needs -lipc for XOpenDisplay.
456 if test $ac_cv_func_shmat = no; then
457 AC_CHECK_LIB(ipc, shmat, X_EXTRA_LIBS="$X_EXTRA_LIBS -lipc")
461 # Check for libraries that X11R6 Xt/Xaw programs need.
462 ac_save_LDFLAGS=$LDFLAGS
463 test -n "$x_libraries" && LDFLAGS="$LDFLAGS -L$x_libraries"
464 # SM needs ICE to (dynamically) link under SunOS 4.x (so we have to
465 # check for ICE first), but we must link in the order -lSM -lICE or
466 # we get undefined symbols. So assume we have SM if we have ICE.
467 # These have to be linked with before -lX11, unlike the other
468 # libraries we check for below, so use a different variable.
469 # John Interrante, Karl Berry
470 AC_CHECK_LIB(ICE, IceConnectionNumber,
471 [X_PRE_LIBS="$X_PRE_LIBS -lSM -lICE"], , $X_EXTRA_LIBS)
472 LDFLAGS=$ac_save_LDFLAGS
475 AC_SUBST(X_CFLAGS)dnl
476 AC_SUBST(X_PRE_LIBS)dnl
478 AC_SUBST(X_EXTRA_LIBS)dnl