Prefer HTTPS to FTP and HTTP
[autoconf.git] / lib / autoconf / libs.m4
blob8a0c31f3d601dd022953723017e7da14d55e5165
1 # This file is part of Autoconf.                       -*- Autoconf -*-
2 # Checking for libraries.
3 # Copyright (C) 1992-1996, 1998-2006, 2008-2017 Free Software
4 # Foundation, Inc.
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 <https://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.
30 # Table of contents
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],
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
54   if test -z "$ac_lib"; then
55     ac_res="none required"
56   else
57     ac_res=-l$ac_lib
58     LIBS="-l$ac_lib $5 $ac_func_search_save_LIBS"
59   fi
60   AC_LINK_IFELSE([], [AS_VAR_SET([ac_Search], [$ac_res])])
61   AS_VAR_SET_IF([ac_Search], [break])
62 done
63 AS_VAR_SET_IF([ac_Search], , [AS_VAR_SET([ac_Search], [no])])
64 rm conftest.$ac_ext
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"
69   $3],
70       [$4])
71 AS_VAR_POPDEF([ac_Search])dnl
76 # AC_CHECK_LIB(LIBRARY, FUNCTION,
77 #              [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND],
78 #              [OTHER-LIBRARIES])
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
99 # freedom.
100 AC_DEFUN([AC_CHECK_LIB],
101 [m4_ifval([$3], , [AH_CHECK_LIB([$1])])dnl
102 AS_LITERAL_WORD_IF([$1],
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
107 LIBS="-l$1 $5 $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))
114   LIBS="-l$1 $LIBS"
115 ])],
116       [$4])
117 AS_VAR_POPDEF([ac_Lib])dnl
118 ])# AC_CHECK_LIB
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],
130 #                 [OTHER-LIBRARIES])
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]),
142                         [-l], []))dnl
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 # --------------------- #
162 # _AC_PATH_X_XMKMF
163 # ----------------
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
170   cd conftest.dir
171   cat >Imakefile <<'_ACEOF'
172 incroot:
173         @echo incroot='${INCROOT}'
174 usrlibdir:
175         @echo usrlibdir='${USRLIBDIR}'
176 libdir:
177         @echo libdir='${LIBDIR}'
178 _ACEOF
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'\`"
183     done
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
189       fi
190     done
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;;
197     esac
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 ;;
201     esac
202   fi
203   cd ..
204   rm -f -r conftest.dir
206 ])# _AC_PATH_X_XMKMF
209 # _AC_PATH_X_DIRECT
210 # -----------------
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.
216 ac_x_header_dirs='
217 /usr/X11/include
218 /usr/X11R7/include
219 /usr/X11R6/include
220 /usr/X11R5/include
221 /usr/X11R4/include
223 /usr/include/X11
224 /usr/include/X11R7
225 /usr/include/X11R6
226 /usr/include/X11R5
227 /usr/include/X11R4
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
241 /opt/X11/include
243 /usr/X386/include
244 /usr/x386/include
245 /usr/XFree86/include/X11
247 /usr/include
248 /usr/local/include
249 /usr/unsupported/include
250 /usr/athena/include
251 /usr/local/x11r5/include
252 /usr/lpp/Xamples/include
254 /usr/openwin/include
255 /usr/openwin/share/include'
257 if test "$ac_x_includes" = no; then
258   # Guess where to find include files, by looking for Xlib.h.
259   # First, try using that file with no special directory specified.
260   AC_PREPROC_IFELSE([AC_LANG_SOURCE([@%:@include <X11/Xlib.h>])],
261 [# We can compile using X headers with no special include directory.
262 ac_x_includes=],
263 [for ac_dir in $ac_x_header_dirs; do
264   if test -r "$ac_dir/X11/Xlib.h"; then
265     ac_x_includes=$ac_dir
266     break
267   fi
268 done])
269 fi # $ac_x_includes = no
271 if test "$ac_x_libraries" = no; then
272   # Check for the libraries.
273   # See if we find them without any special options.
274   # Don't add to $LIBS permanently.
275   ac_save_LIBS=$LIBS
276   LIBS="-lX11 $LIBS"
277   AC_LINK_IFELSE([AC_LANG_PROGRAM([@%:@include <X11/Xlib.h>],
278                                   [XrmInitialize ()])],
279                  [LIBS=$ac_save_LIBS
280 # We can link X programs with no special library path.
281 ac_x_libraries=],
282                  [LIBS=$ac_save_LIBS
283 for ac_dir in `AS_ECHO(["$ac_x_includes $ac_x_header_dirs"]) | sed s/include/lib/g`
285   # Don't even attempt the hair of trying to link an X program!
286   for ac_extension in a so sl dylib la dll; do
287     if test -r "$ac_dir/libX11.$ac_extension"; then
288       ac_x_libraries=$ac_dir
289       break 2
290     fi
291   done
292 done])
293 fi # $ac_x_libraries = no
294 ])# _AC_PATH_X_DIRECT
297 # _AC_PATH_X
298 # ----------
299 # Compute ac_cv_have_x.
300 AC_DEFUN([_AC_PATH_X],
301 [AC_CACHE_VAL(ac_cv_have_x,
302 [# One or both of the vars are not set, and there is no cached value.
303 ac_x_includes=no ac_x_libraries=no
304 _AC_PATH_X_XMKMF
305 _AC_PATH_X_DIRECT
306 case $ac_x_includes,$ac_x_libraries in #(
307   no,* | *,no | *\'*)
308     # Didn't find X, or a directory has "'" in its name.
309     ac_cv_have_x="have_x=no";; #(
310   *)
311     # Record where we found X for the cache.
312     ac_cv_have_x="have_x=yes\
313         ac_x_includes='$ac_x_includes'\
314         ac_x_libraries='$ac_x_libraries'"
315 esac])dnl
319 # AC_PATH_X
320 # ---------
321 # If we find X, set shell vars x_includes and x_libraries to the
322 # paths, otherwise set no_x=yes.
323 # Uses ac_ vars as temps to allow command line to override cache and checks.
324 # --without-x overrides everything else, but does not touch the cache.
325 AN_HEADER([X11/Xlib.h],  [AC_PATH_X])
326 AC_DEFUN([AC_PATH_X],
327 [dnl Document the X abnormal options inherited from history.
328 m4_divert_once([HELP_BEGIN], [
329 X features:
330   --x-includes=DIR    X include files are in DIR
331   --x-libraries=DIR   X library files are in DIR])dnl
332 AC_MSG_CHECKING([for X])
334 AC_ARG_WITH(x, [  --with-x                use the X Window System])
335 # $have_x is `yes', `no', `disabled', or empty when we do not yet know.
336 if test "x$with_x" = xno; then
337   # The user explicitly disabled X.
338   have_x=disabled
339 else
340   case $x_includes,$x_libraries in #(
341     *\'*) AC_MSG_ERROR([cannot use X directory names containing ']);; #(
342     *,NONE | NONE,*) _AC_PATH_X;; #(
343     *) have_x=yes;;
344   esac
345   eval "$ac_cv_have_x"
346 fi # $with_x != no
348 if test "$have_x" != yes; then
349   AC_MSG_RESULT([$have_x])
350   no_x=yes
351 else
352   # If each of the values was on the command line, it overrides each guess.
353   test "x$x_includes" = xNONE && x_includes=$ac_x_includes
354   test "x$x_libraries" = xNONE && x_libraries=$ac_x_libraries
355   # Update the cache value to reflect the command line values.
356   ac_cv_have_x="have_x=yes\
357         ac_x_includes='$x_includes'\
358         ac_x_libraries='$x_libraries'"
359   AC_MSG_RESULT([libraries $x_libraries, headers $x_includes])
361 ])# AC_PATH_X
365 # AC_PATH_XTRA
366 # ------------
367 # Find additional X libraries, magic flags, etc.
368 AC_DEFUN([AC_PATH_XTRA],
369 [AC_REQUIRE([AC_PATH_X])dnl
370 if test "$no_x" = yes; then
371   # Not all programs may use this symbol, but it does not hurt to define it.
372   AC_DEFINE([X_DISPLAY_MISSING], 1,
373             [Define to 1 if the X Window System is missing or not being used.])
374   X_CFLAGS= X_PRE_LIBS= X_LIBS= X_EXTRA_LIBS=
375 else
376   if test -n "$x_includes"; then
377     X_CFLAGS="$X_CFLAGS -I$x_includes"
378   fi
380   # It would also be nice to do this for all -L options, not just this one.
381   if test -n "$x_libraries"; then
382     X_LIBS="$X_LIBS -L$x_libraries"
383     # For Solaris; some versions of Sun CC require a space after -R and
384     # others require no space.  Words are not sufficient . . . .
385     AC_MSG_CHECKING([whether -R must be followed by a space])
386     ac_xsave_LIBS=$LIBS; LIBS="$LIBS -R$x_libraries"
387     ac_xsave_[]_AC_LANG_ABBREV[]_werror_flag=$ac_[]_AC_LANG_ABBREV[]_werror_flag
388     ac_[]_AC_LANG_ABBREV[]_werror_flag=yes
389     AC_LINK_IFELSE([AC_LANG_PROGRAM()],
390       [AC_MSG_RESULT([no])
391        X_LIBS="$X_LIBS -R$x_libraries"],
392       [LIBS="$ac_xsave_LIBS -R $x_libraries"
393        AC_LINK_IFELSE([AC_LANG_PROGRAM()],
394          [AC_MSG_RESULT([yes])
395           X_LIBS="$X_LIBS -R $x_libraries"],
396          [AC_MSG_RESULT([neither works])])])
397     ac_[]_AC_LANG_ABBREV[]_werror_flag=$ac_xsave_[]_AC_LANG_ABBREV[]_werror_flag
398     LIBS=$ac_xsave_LIBS
399   fi
401   # Check for system-dependent libraries X programs must link with.
402   # Do this before checking for the system-independent R6 libraries
403   # (-lICE), since we may need -lsocket or whatever for X linking.
405   if test "$ISC" = yes; then
406     X_EXTRA_LIBS="$X_EXTRA_LIBS -lnsl_s -linet"
407   else
408     # Martyn Johnson says this is needed for Ultrix, if the X
409     # libraries were built with DECnet support.  And Karl Berry says
410     # the Alpha needs dnet_stub (dnet does not exist).
411     ac_xsave_LIBS="$LIBS"; LIBS="$LIBS $X_LIBS -lX11"
412     AC_LINK_IFELSE([AC_LANG_CALL([], [XOpenDisplay])],
413                    [],
414     [AC_CHECK_LIB(dnet, dnet_ntoa, [X_EXTRA_LIBS="$X_EXTRA_LIBS -ldnet"])
415     if test $ac_cv_lib_dnet_dnet_ntoa = no; then
416       AC_CHECK_LIB(dnet_stub, dnet_ntoa,
417         [X_EXTRA_LIBS="$X_EXTRA_LIBS -ldnet_stub"])
418     fi])
419     LIBS="$ac_xsave_LIBS"
421     # msh@cis.ufl.edu says -lnsl (and -lsocket) are needed for his 386/AT,
422     # to get the SysV transport functions.
423     # Chad R. Larson says the Pyramis MIS-ES running DC/OSx (SVR4)
424     # needs -lnsl.
425     # The nsl library prevents programs from opening the X display
426     # on Irix 5.2, according to T.E. Dickey.
427     # The functions gethostbyname, getservbyname, and inet_addr are
428     # in -lbsd on LynxOS 3.0.1/i386, according to Lars Hecking.
429     AC_CHECK_FUNC(gethostbyname)
430     if test $ac_cv_func_gethostbyname = no; then
431       AC_CHECK_LIB(nsl, gethostbyname, X_EXTRA_LIBS="$X_EXTRA_LIBS -lnsl")
432       if test $ac_cv_lib_nsl_gethostbyname = no; then
433         AC_CHECK_LIB(bsd, gethostbyname, X_EXTRA_LIBS="$X_EXTRA_LIBS -lbsd")
434       fi
435     fi
437     # lieder@skyler.mavd.honeywell.com says without -lsocket,
438     # socket/setsockopt and other routines are undefined under SCO ODT
439     # 2.0.  But -lsocket is broken on IRIX 5.2 (and is not necessary
440     # on later versions), says Simon Leinen: it contains gethostby*
441     # variants that don't use the name server (or something).  -lsocket
442     # must be given before -lnsl if both are needed.  We assume that
443     # if connect needs -lnsl, so does gethostbyname.
444     AC_CHECK_FUNC(connect)
445     if test $ac_cv_func_connect = no; then
446       AC_CHECK_LIB(socket, connect, X_EXTRA_LIBS="-lsocket $X_EXTRA_LIBS", ,
447         $X_EXTRA_LIBS)
448     fi
450     # Guillermo Gomez says -lposix is necessary on A/UX.
451     AC_CHECK_FUNC(remove)
452     if test $ac_cv_func_remove = no; then
453       AC_CHECK_LIB(posix, remove, X_EXTRA_LIBS="$X_EXTRA_LIBS -lposix")
454     fi
456     # BSDI BSD/OS 2.1 needs -lipc for XOpenDisplay.
457     AC_CHECK_FUNC(shmat)
458     if test $ac_cv_func_shmat = no; then
459       AC_CHECK_LIB(ipc, shmat, X_EXTRA_LIBS="$X_EXTRA_LIBS -lipc")
460     fi
461   fi
463   # Check for libraries that X11R6 Xt/Xaw programs need.
464   ac_save_LDFLAGS=$LDFLAGS
465   test -n "$x_libraries" && LDFLAGS="$LDFLAGS -L$x_libraries"
466   # SM needs ICE to (dynamically) link under SunOS 4.x (so we have to
467   # check for ICE first), but we must link in the order -lSM -lICE or
468   # we get undefined symbols.  So assume we have SM if we have ICE.
469   # These have to be linked with before -lX11, unlike the other
470   # libraries we check for below, so use a different variable.
471   # John Interrante, Karl Berry
472   AC_CHECK_LIB(ICE, IceConnectionNumber,
473     [X_PRE_LIBS="$X_PRE_LIBS -lSM -lICE"], , $X_EXTRA_LIBS)
474   LDFLAGS=$ac_save_LDFLAGS
477 AC_SUBST(X_CFLAGS)dnl
478 AC_SUBST(X_PRE_LIBS)dnl
479 AC_SUBST(X_LIBS)dnl
480 AC_SUBST(X_EXTRA_LIBS)dnl
481 ])# AC_PATH_XTRA