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