libs.m4 16 KB

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