1 # This file is part of Autoconf. -*- Autoconf -*- 2 # Checking for libraries. 3 # Copyright (C) 1992-1996, 1998-2006, 2008-2012 Free Software 4 # Foundation, Inc. 5 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. 11 # 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. 16 # 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. 20 # 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/>. 25 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. 29 30 # Table of contents 31 # 32 # 1. Generic tests for libraries 33 # 2. Tests for specific libraries 34 35 36 ## --------------------------------- ## 37 ## 1. Generic tests for libraries.## ## 38 ## --------------------------------- ## 39 40 41 42 # AC_SEARCH_LIBS(FUNCTION, SEARCH-LIBS, 43 # [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND], 44 # [OTHER-LIBRARIES]) 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" 55 else 56 ac_res=-l$ac_lib 57 LIBS="-l$ac_lib $5 $ac_func_search_save_LIBS" 58 fi 59 AC_LINK_IFELSE([], [AS_VAR_SET([ac_Search], [$ac_res])]) 60 AS_VAR_SET_IF([ac_Search], [break]) 61 done 62 AS_VAR_SET_IF([ac_Search], , [AS_VAR_SET([ac_Search], [no])]) 63 rm conftest.$ac_ext 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" 68 $3], 69 [$4]) 70 AS_VAR_POPDEF([ac_Search])dnl 71 ]) 72 73 74 75 # AC_CHECK_LIB(LIBRARY, FUNCTION, 76 # [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND], 77 # [OTHER-LIBRARIES]) 78 # ------------------------------------------------------ 79 # 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. 84 # 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. 89 # 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. 93 # 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 98 # freedom. 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 106 LIBS="-l$1 $5 $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)) 113 LIBS="-l$1 $LIBS" 114 ])], 115 [$4]) 116 AS_VAR_POPDEF([ac_Lib])dnl 117 ])# AC_CHECK_LIB 118 119 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).])]) 125 126 127 # AC_HAVE_LIBRARY(LIBRARY, 128 # [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND], 129 # [OTHER-LIBRARIES]) 130 # --------------------------------------------------------- 131 # 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]), 141 [-l], []))dnl 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 145 ]) 146 147 148 149 150 ## --------------------------------- ## 151 ## 2. Tests for specific libraries. ## 152 ## --------------------------------- ## 153 154 155 156 # --------------------- # 157 # Checks for X window. # 158 # --------------------- # 159 160 161 # _AC_PATH_X_XMKMF 162 # ---------------- 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 169 cd conftest.dir 170 cat >Imakefile <<'_ACEOF' 171 incroot: 172 @echo incroot='${INCROOT}' 173 usrlibdir: 174 @echo usrlibdir='${USRLIBDIR}' 175 libdir: 176 @echo libdir='${LIBDIR}' 177 _ACEOF 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'\`" 182 done 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 188 fi 189 done 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;; 196 esac 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 ;; 200 esac 201 fi 202 cd .. 203 rm -f -r conftest.dir 204 fi 205 ])# _AC_PATH_X_XMKMF 206 207 208 # _AC_PATH_X_DIRECT 209 # ----------------- 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. 215 ac_x_header_dirs=' 216 /usr/X11/include 217 /usr/X11R7/include 218 /usr/X11R6/include 219 /usr/X11R5/include 220 /usr/X11R4/include 221 222 /usr/include/X11 223 /usr/include/X11R7 224 /usr/include/X11R6 225 /usr/include/X11R5 226 /usr/include/X11R4 227 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 233 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 239 240 /usr/X386/include 241 /usr/x386/include 242 /usr/XFree86/include/X11 243 244 /usr/include 245 /usr/local/include 246 /usr/unsupported/include 247 /usr/athena/include 248 /usr/local/x11r5/include 249 /usr/lpp/Xamples/include 250 251 /usr/openwin/include 252 /usr/openwin/share/include' 253 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. 259 ac_x_includes=], 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 263 break 264 fi 265 done]) 266 fi # $ac_x_includes = no 267 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. 272 ac_save_LIBS=$LIBS 273 LIBS="-lX11 $LIBS" 274 AC_LINK_IFELSE([AC_LANG_PROGRAM([@%:@include <X11/Xlib.h>], 275 [XrmInitialize ()])], 276 [LIBS=$ac_save_LIBS 277 # We can link X programs with no special library path. 278 ac_x_libraries=], 279 [LIBS=$ac_save_LIBS 280 for ac_dir in `AS_ECHO(["$ac_x_includes $ac_x_header_dirs"]) | sed s/include/lib/g` 281 do 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 286 break 2 287 fi 288 done 289 done]) 290 fi # $ac_x_libraries = no 291 ])# _AC_PATH_X_DIRECT 292 293 294 # _AC_PATH_X 295 # ---------- 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 301 _AC_PATH_X_XMKMF 302 _AC_PATH_X_DIRECT 303 case $ac_x_includes,$ac_x_libraries in #( 304 no,* | *,no | *\'*) 305 # Didn't find X, or a directory has "'" in its name. 306 ac_cv_have_x="have_x=no";; #( 307 *) 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'" 312 esac])dnl 313 ]) 314 315 316 # AC_PATH_X 317 # --------- 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], [ 326 X features: 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]) 330 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. 335 have_x=disabled 336 else 337 case $x_includes,$x_libraries in #( 338 *\'*) AC_MSG_ERROR([cannot use X directory names containing ']);; #( 339 *,NONE | NONE,*) _AC_PATH_X;; #( 340 *) have_x=yes;; 341 esac 342 eval "$ac_cv_have_x" 343 fi # $with_x != no 344 345 if test "$have_x" != yes; then 346 AC_MSG_RESULT([$have_x]) 347 no_x=yes 348 else 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]) 357 fi 358 ])# AC_PATH_X 359 360 361 362 # AC_PATH_XTRA 363 # ------------ 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= 372 else 373 if test -n "$x_includes"; then 374 X_CFLAGS="$X_CFLAGS -I$x_includes" 375 fi 376 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()], 387 [AC_MSG_RESULT([no]) 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 395 LIBS=$ac_xsave_LIBS 396 fi 397 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. 401 402 if test "$ISC" = yes; then 403 X_EXTRA_LIBS="$X_EXTRA_LIBS -lnsl_s -linet" 404 else 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])], 410 [], 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"]) 415 fi]) 416 LIBS="$ac_xsave_LIBS" 417 418 # msh (a] 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) 421 # needs -lnsl. 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") 431 fi 432 fi 433 434 # lieder (a] 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", , 444 $X_EXTRA_LIBS) 445 fi 446 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") 451 fi 452 453 # BSDI BSD/OS 2.1 needs -lipc for XOpenDisplay. 454 AC_CHECK_FUNC(shmat) 455 if test $ac_cv_func_shmat = no; then 456 AC_CHECK_LIB(ipc, shmat, X_EXTRA_LIBS="$X_EXTRA_LIBS -lipc") 457 fi 458 fi 459 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 472 473 fi 474 AC_SUBST(X_CFLAGS)dnl 475 AC_SUBST(X_PRE_LIBS)dnl 476 AC_SUBST(X_LIBS)dnl 477 AC_SUBST(X_EXTRA_LIBS)dnl 478 ])# AC_PATH_XTRA 479