Install msysDTK-1.0.1
[msysgit.git] / share / autoconf / autoconf / libs.m4
blobe886aae4124357bbede94abe03a64b6c1a190597
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 Free Software Foundation, Inc.
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2, or (at your option)
9 # any later version.
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.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
19 # 02111-1307, USA.
21 # As a special exception, the Free Software Foundation gives unlimited
22 # permission to copy, distribute and modify the configure scripts that
23 # are the output of Autoconf.  You need not follow the terms of the GNU
24 # General Public License when using or distributing such scripts, even
25 # though portions of the text of Autoconf appear in them.  The GNU
26 # General Public License (GPL) does govern all other use of the material
27 # that constitutes the Autoconf program.
29 # Certain portions of the Autoconf source text are designed to be copied
30 # (in certain cases, depending on the input) into the output of
31 # Autoconf.  We call these the "data" portions.  The rest of the Autoconf
32 # source text consists of comments plus executable code that decides which
33 # of the data portions to output in any given case.  We call these
34 # comments and executable code the "non-data" portions.  Autoconf never
35 # copies any of the non-data portions into its output.
37 # This special exception to the GPL applies to versions of Autoconf
38 # released by the Free Software Foundation.  When you make and
39 # distribute a modified version of Autoconf, you may extend this special
40 # exception to the GPL to apply to your modified version as well, *unless*
41 # your modified version has the potential to copy into its output some
42 # of the text that was the non-data portion of the version that you started
43 # with.  (In other words, unless your change moves or copies text from
44 # the non-data portions to the data portions.)  If your modification has
45 # such potential, you must delete any notice of this special exception
46 # to the GPL from your modified version.
48 # Written by David MacKenzie, with help from
49 # Franc,ois Pinard, Karl Berry, Richard Pixley, Ian Lance Taylor,
50 # Roland McGrath, Noah Friedman, david d zuhn, and many others.
52 # Table of contents
54 # 1. Generic tests for libraries
55 # 2. Tests for specific libraries
58 ## --------------------------------- ##
59 ## 1. Generic tests for libraries.## ##
60 ## --------------------------------- ##
64 # AC_SEARCH_LIBS(FUNCTION, SEARCH-LIBS,
65 #                [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND],
66 #                [OTHER-LIBRARIES])
67 # --------------------------------------------------------
68 # Search for a library defining FUNC, if it's not already available.
69 AC_DEFUN([AC_SEARCH_LIBS],
70 [AC_CACHE_CHECK([for library containing $1], [ac_cv_search_$1],
71 [ac_func_search_save_LIBS=$LIBS
72 ac_cv_search_$1=no
73 AC_LINK_IFELSE([AC_LANG_CALL([], [$1])],
74                [ac_cv_search_$1="none required"])
75 if test "$ac_cv_search_$1" = no; then
76   for ac_lib in $2; do
77     LIBS="-l$ac_lib $5 $ac_func_search_save_LIBS"
78     AC_LINK_IFELSE([AC_LANG_CALL([], [$1])],
79                    [ac_cv_search_$1="-l$ac_lib"
80 break])
81   done
83 LIBS=$ac_func_search_save_LIBS])
84 AS_IF([test "$ac_cv_search_$1" != no],
85   [test "$ac_cv_search_$1" = "none required" || LIBS="$ac_cv_search_$1 $LIBS"
86   $3],
87       [$4])dnl
92 # AC_CHECK_LIB(LIBRARY, FUNCTION,
93 #              [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND],
94 #              [OTHER-LIBRARIES])
95 # ------------------------------------------------------
97 # Use a cache variable name containing both the library and function name,
98 # because the test really is for library $1 defining function $2, not
99 # just for library $1.  Separate tests with the same $1 and different $2s
100 # may have different results.
102 # Note that using directly AS_VAR_PUSHDEF([ac_Lib], [ac_cv_lib_$1_$2])
103 # is asking for troubles, since AC_CHECK_LIB($lib, fun) would give
104 # ac_cv_lib_$lib_fun, which is definitely not what was meant.  Hence
105 # the AS_LITERAL_IF indirection.
107 # FIXME: This macro is extremely suspicious.  It DEFINEs unconditionally,
108 # whatever the FUNCTION, in addition to not being a *S macro.  Note
109 # that the cache does depend upon the function we are looking for.
111 # It is on purpose we used `ac_check_lib_save_LIBS' and not just
112 # `ac_save_LIBS': there are many macros which don't want to see `LIBS'
113 # changed but still want to use AC_CHECK_LIB, so they save `LIBS'.
114 # And ``ac_save_LIBS' is too tempting a name, so let's leave them some
115 # freedom.
116 AC_DEFUN([AC_CHECK_LIB],
117 [m4_ifval([$3], , [AH_CHECK_LIB([$1])])dnl
118 AS_LITERAL_IF([$1],
119               [AS_VAR_PUSHDEF([ac_Lib], [ac_cv_lib_$1_$2])],
120               [AS_VAR_PUSHDEF([ac_Lib], [ac_cv_lib_$1''_$2])])dnl
121 AC_CACHE_CHECK([for $2 in -l$1], ac_Lib,
122 [ac_check_lib_save_LIBS=$LIBS
123 LIBS="-l$1 $5 $LIBS"
124 AC_LINK_IFELSE([AC_LANG_CALL([], [$2])],
125                [AS_VAR_SET(ac_Lib, yes)],
126                [AS_VAR_SET(ac_Lib, no)])
127 LIBS=$ac_check_lib_save_LIBS])
128 AS_IF([test AS_VAR_GET(ac_Lib) = yes],
129       [m4_default([$3], [AC_DEFINE_UNQUOTED(AS_TR_CPP(HAVE_LIB$1))
130   LIBS="-l$1 $LIBS"
131 ])],
132       [$4])dnl
133 AS_VAR_POPDEF([ac_Lib])dnl
134 ])# AC_CHECK_LIB
137 # AH_CHECK_LIB(LIBNAME)
138 # ---------------------
139 m4_define([AH_CHECK_LIB],
140 [AH_TEMPLATE(AS_TR_CPP(HAVE_LIB$1),
141              [Define to 1 if you have the `]$1[' library (-l]$1[).])])
144 # AC_HAVE_LIBRARY(LIBRARY,
145 #                 [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND],
146 #                 [OTHER-LIBRARIES])
147 # ---------------------------------------------------------
149 # This macro is equivalent to calling `AC_CHECK_LIB' with a FUNCTION
150 # argument of `main'.  In addition, LIBRARY can be written as any of
151 # `foo', `-lfoo', or `libfoo.a'.  In all of those cases, the compiler
152 # is passed `-lfoo'.  However, LIBRARY cannot be a shell variable;
153 # it must be a literal name.
154 AU_DEFUN([AC_HAVE_LIBRARY],
155 [m4_pushdef([AC_Lib_Name],
156             m4_bpatsubst(m4_bpatsubst([[$1]],
157                                     [lib\([^\.]*\)\.a], [\1]),
158                         [-l], []))dnl
159 AC_CHECK_LIB(AC_Lib_Name, main, [$2], [$3], [$4])dnl
160 ac_cv_lib_[]AC_Lib_Name()=ac_cv_lib_[]AC_Lib_Name()_main
161 m4_popdef([AC_Lib_Name])dnl
167 ## --------------------------------- ##
168 ## 2. Tests for specific libraries.  ##
169 ## --------------------------------- ##
173 # --------------------- #
174 # Checks for X window.  #
175 # --------------------- #
178 # _AC_PATH_X_XMKMF
179 # ----------------
180 # Internal subroutine of _AC_PATH_X.
181 # Set ac_x_includes and/or ac_x_libraries.
182 m4_define([_AC_PATH_X_XMKMF],
183 [rm -fr conftest.dir
184 if mkdir conftest.dir; then
185   cd conftest.dir
186   # Make sure to not put "make" in the Imakefile rules, since we grep it out.
187   cat >Imakefile <<'_ACEOF'
188 acfindx:
189         @echo 'ac_im_incroot="${INCROOT}"; ac_im_usrlibdir="${USRLIBDIR}"; ac_im_libdir="${LIBDIR}"'
190 _ACEOF
191   if (xmkmf) >/dev/null 2>/dev/null && test -f Makefile; then
192     # GNU make sometimes prints "make[1]: Entering...", which would confuse us.
193     eval `${MAKE-make} acfindx 2>/dev/null | grep -v make`
194     # Open Windows xmkmf reportedly sets LIBDIR instead of USRLIBDIR.
195     for ac_extension in a so sl; do
196       if test ! -f $ac_im_usrlibdir/libX11.$ac_extension &&
197          test -f $ac_im_libdir/libX11.$ac_extension; then
198         ac_im_usrlibdir=$ac_im_libdir; break
199       fi
200     done
201     # Screen out bogus values from the imake configuration.  They are
202     # bogus both because they are the default anyway, and because
203     # using them would break gcc on systems where it needs fixed includes.
204     case $ac_im_incroot in
205         /usr/include) ;;
206         *) test -f "$ac_im_incroot/X11/Xos.h" && ac_x_includes=$ac_im_incroot;;
207     esac
208     case $ac_im_usrlibdir in
209         /usr/lib | /lib) ;;
210         *) test -d "$ac_im_usrlibdir" && ac_x_libraries=$ac_im_usrlibdir ;;
211     esac
212   fi
213   cd ..
214   rm -fr conftest.dir
216 ])# _AC_PATH_X_XMKMF
219 # _AC_PATH_X_DIRECT
220 # -----------------
221 # Internal subroutine of _AC_PATH_X.
222 # Set ac_x_includes and/or ac_x_libraries.
223 m4_define([_AC_PATH_X_DIRECT],
224 [# Standard set of common directories for X headers.
225 # Check X11 before X11Rn because it is often a symlink to the current release.
226 ac_x_header_dirs='
227 /usr/X11/include
228 /usr/X11R6/include
229 /usr/X11R5/include
230 /usr/X11R4/include
232 /usr/include/X11
233 /usr/include/X11R6
234 /usr/include/X11R5
235 /usr/include/X11R4
237 /usr/local/X11/include
238 /usr/local/X11R6/include
239 /usr/local/X11R5/include
240 /usr/local/X11R4/include
242 /usr/local/include/X11
243 /usr/local/include/X11R6
244 /usr/local/include/X11R5
245 /usr/local/include/X11R4
247 /usr/X386/include
248 /usr/x386/include
249 /usr/XFree86/include/X11
251 /usr/include
252 /usr/local/include
253 /usr/unsupported/include
254 /usr/athena/include
255 /usr/local/x11r5/include
256 /usr/lpp/Xamples/include
258 /usr/openwin/include
259 /usr/openwin/share/include'
261 if test "$ac_x_includes" = no; then
262   # Guess where to find include files, by looking for Intrinsic.h.
263   # First, try using that file with no special directory specified.
264   AC_PREPROC_IFELSE([AC_LANG_SOURCE([@%:@include <X11/Intrinsic.h>])],
265 [# We can compile using X headers with no special include directory.
266 ac_x_includes=],
267 [for ac_dir in $ac_x_header_dirs; do
268   if test -r "$ac_dir/X11/Intrinsic.h"; then
269     ac_x_includes=$ac_dir
270     break
271   fi
272 done])
273 fi # $ac_x_includes = no
275 if test "$ac_x_libraries" = no; then
276   # Check for the libraries.
277   # See if we find them without any special options.
278   # Don't add to $LIBS permanently.
279   ac_save_LIBS=$LIBS
280   LIBS="-lXt $LIBS"
281   AC_LINK_IFELSE([AC_LANG_PROGRAM([@%:@include <X11/Intrinsic.h>],
282                                   [XtMalloc (0)])],
283                  [LIBS=$ac_save_LIBS
284 # We can link X programs with no special library path.
285 ac_x_libraries=],
286                  [LIBS=$ac_save_LIBS
287 for ac_dir in `echo "$ac_x_includes $ac_x_header_dirs" | sed s/include/lib/g`
289   # Don't even attempt the hair of trying to link an X program!
290   for ac_extension in a so sl; do
291     if test -r $ac_dir/libXt.$ac_extension; then
292       ac_x_libraries=$ac_dir
293       break 2
294     fi
295   done
296 done])
297 fi # $ac_x_libraries = no
298 ])# _AC_PATH_X_DIRECT
301 # _AC_PATH_X
302 # ----------
303 # Compute ac_cv_have_x.
304 AC_DEFUN([_AC_PATH_X],
305 [AC_CACHE_VAL(ac_cv_have_x,
306 [# One or both of the vars are not set, and there is no cached value.
307 ac_x_includes=no ac_x_libraries=no
308 _AC_PATH_X_XMKMF
309 _AC_PATH_X_DIRECT
310 if test "$ac_x_includes" = no || test "$ac_x_libraries" = no; then
311   # Didn't find X anywhere.  Cache the known absence of X.
312   ac_cv_have_x="have_x=no"
313 else
314   # Record where we found X for the cache.
315   ac_cv_have_x="have_x=yes \
316                 ac_x_includes=$ac_x_includes ac_x_libraries=$ac_x_libraries"
317 fi])dnl
321 # AC_PATH_X
322 # ---------
323 # If we find X, set shell vars x_includes and x_libraries to the
324 # paths, otherwise set no_x=yes.
325 # Uses ac_ vars as temps to allow command line to override cache and checks.
326 # --without-x overrides everything else, but does not touch the cache.
327 AN_HEADER([X11/Xlib.h],  [AC_PATH_X])
328 AC_DEFUN([AC_PATH_X],
329 [dnl Document the X abnormal options inherited from history.
330 m4_divert_once([HELP_BEGIN], [
331 X features:
332   --x-includes=DIR    X include files are in DIR
333   --x-libraries=DIR   X library files are in DIR])dnl
334 AC_MSG_CHECKING([for X])
336 AC_ARG_WITH(x, [  --with-x                use the X Window System])
337 # $have_x is `yes', `no', `disabled', or empty when we do not yet know.
338 if test "x$with_x" = xno; then
339   # The user explicitly disabled X.
340   have_x=disabled
341 else
342   if test "x$x_includes" != xNONE && test "x$x_libraries" != xNONE; then
343     # Both variables are already set.
344     have_x=yes
345   else
346     _AC_PATH_X
347   fi
348   eval "$ac_cv_have_x"
349 fi # $with_x != no
351 if test "$have_x" != yes; then
352   AC_MSG_RESULT([$have_x])
353   no_x=yes
354 else
355   # If each of the values was on the command line, it overrides each guess.
356   test "x$x_includes" = xNONE && x_includes=$ac_x_includes
357   test "x$x_libraries" = xNONE && x_libraries=$ac_x_libraries
358   # Update the cache value to reflect the command line values.
359   ac_cv_have_x="have_x=yes \
360                 ac_x_includes=$x_includes ac_x_libraries=$x_libraries"
361   AC_MSG_RESULT([libraries $x_libraries, headers $x_includes])
363 ])# AC_PATH_X
367 # AC_PATH_XTRA
368 # ------------
369 # Find additional X libraries, magic flags, etc.
370 AC_DEFUN([AC_PATH_XTRA],
371 [AC_REQUIRE([AC_PATH_X])dnl
372 if test "$no_x" = yes; then
373   # Not all programs may use this symbol, but it does not hurt to define it.
374   AC_DEFINE([X_DISPLAY_MISSING], 1,
375             [Define to 1 if the X Window System is missing or not being used.])
376   X_CFLAGS= X_PRE_LIBS= X_LIBS= X_EXTRA_LIBS=
377 else
378   if test -n "$x_includes"; then
379     X_CFLAGS="$X_CFLAGS -I$x_includes"
380   fi
382   # It would also be nice to do this for all -L options, not just this one.
383   if test -n "$x_libraries"; then
384     X_LIBS="$X_LIBS -L$x_libraries"
385 dnl FIXME: banish uname from this macro!
386     # For Solaris; some versions of Sun CC require a space after -R and
387     # others require no space.  Words are not sufficient . . . .
388     case `(uname -sr) 2>/dev/null` in
389     "SunOS 5"*)
390       AC_MSG_CHECKING([whether -R must be followed by a space])
391       ac_xsave_LIBS=$LIBS; LIBS="$LIBS -R$x_libraries"
392       AC_LINK_IFELSE([AC_LANG_PROGRAM()], ac_R_nospace=yes, ac_R_nospace=no)
393       if test $ac_R_nospace = yes; then
394         AC_MSG_RESULT([no])
395         X_LIBS="$X_LIBS -R$x_libraries"
396       else
397         LIBS="$ac_xsave_LIBS -R $x_libraries"
398         AC_LINK_IFELSE([AC_LANG_PROGRAM()], ac_R_space=yes, ac_R_space=no)
399         if test $ac_R_space = yes; then
400           AC_MSG_RESULT([yes])
401           X_LIBS="$X_LIBS -R $x_libraries"
402         else
403           AC_MSG_RESULT([neither works])
404         fi
405       fi
406       LIBS=$ac_xsave_LIBS
407     esac
408   fi
410   # Check for system-dependent libraries X programs must link with.
411   # Do this before checking for the system-independent R6 libraries
412   # (-lICE), since we may need -lsocket or whatever for X linking.
414   if test "$ISC" = yes; then
415     X_EXTRA_LIBS="$X_EXTRA_LIBS -lnsl_s -linet"
416   else
417     # Martyn Johnson says this is needed for Ultrix, if the X
418     # libraries were built with DECnet support.  And Karl Berry says
419     # the Alpha needs dnet_stub (dnet does not exist).
420     ac_xsave_LIBS="$LIBS"; LIBS="$LIBS $X_LIBS -lX11"
421     AC_LINK_IFELSE([AC_LANG_CALL([], [XOpenDisplay])],
422                    [],
423     [AC_CHECK_LIB(dnet, dnet_ntoa, [X_EXTRA_LIBS="$X_EXTRA_LIBS -ldnet"])
424     if test $ac_cv_lib_dnet_dnet_ntoa = no; then
425       AC_CHECK_LIB(dnet_stub, dnet_ntoa,
426         [X_EXTRA_LIBS="$X_EXTRA_LIBS -ldnet_stub"])
427     fi])
428     LIBS="$ac_xsave_LIBS"
430     # msh@cis.ufl.edu says -lnsl (and -lsocket) are needed for his 386/AT,
431     # to get the SysV transport functions.
432     # Chad R. Larson says the Pyramis MIS-ES running DC/OSx (SVR4)
433     # needs -lnsl.
434     # The nsl library prevents programs from opening the X display
435     # on Irix 5.2, according to T.E. Dickey.
436     # The functions gethostbyname, getservbyname, and inet_addr are
437     # in -lbsd on LynxOS 3.0.1/i386, according to Lars Hecking.
438     AC_CHECK_FUNC(gethostbyname)
439     if test $ac_cv_func_gethostbyname = no; then
440       AC_CHECK_LIB(nsl, gethostbyname, X_EXTRA_LIBS="$X_EXTRA_LIBS -lnsl")
441       if test $ac_cv_lib_nsl_gethostbyname = no; then
442         AC_CHECK_LIB(bsd, gethostbyname, X_EXTRA_LIBS="$X_EXTRA_LIBS -lbsd")
443       fi
444     fi
446     # lieder@skyler.mavd.honeywell.com says without -lsocket,
447     # socket/setsockopt and other routines are undefined under SCO ODT
448     # 2.0.  But -lsocket is broken on IRIX 5.2 (and is not necessary
449     # on later versions), says Simon Leinen: it contains gethostby*
450     # variants that don't use the name server (or something).  -lsocket
451     # must be given before -lnsl if both are needed.  We assume that
452     # if connect needs -lnsl, so does gethostbyname.
453     AC_CHECK_FUNC(connect)
454     if test $ac_cv_func_connect = no; then
455       AC_CHECK_LIB(socket, connect, X_EXTRA_LIBS="-lsocket $X_EXTRA_LIBS", ,
456         $X_EXTRA_LIBS)
457     fi
459     # Guillermo Gomez says -lposix is necessary on A/UX.
460     AC_CHECK_FUNC(remove)
461     if test $ac_cv_func_remove = no; then
462       AC_CHECK_LIB(posix, remove, X_EXTRA_LIBS="$X_EXTRA_LIBS -lposix")
463     fi
465     # BSDI BSD/OS 2.1 needs -lipc for XOpenDisplay.
466     AC_CHECK_FUNC(shmat)
467     if test $ac_cv_func_shmat = no; then
468       AC_CHECK_LIB(ipc, shmat, X_EXTRA_LIBS="$X_EXTRA_LIBS -lipc")
469     fi
470   fi
472   # Check for libraries that X11R6 Xt/Xaw programs need.
473   ac_save_LDFLAGS=$LDFLAGS
474   test -n "$x_libraries" && LDFLAGS="$LDFLAGS -L$x_libraries"
475   # SM needs ICE to (dynamically) link under SunOS 4.x (so we have to
476   # check for ICE first), but we must link in the order -lSM -lICE or
477   # we get undefined symbols.  So assume we have SM if we have ICE.
478   # These have to be linked with before -lX11, unlike the other
479   # libraries we check for below, so use a different variable.
480   # John Interrante, Karl Berry
481   AC_CHECK_LIB(ICE, IceConnectionNumber,
482     [X_PRE_LIBS="$X_PRE_LIBS -lSM -lICE"], , $X_EXTRA_LIBS)
483   LDFLAGS=$ac_save_LDFLAGS
486 AC_SUBST(X_CFLAGS)dnl
487 AC_SUBST(X_PRE_LIBS)dnl
488 AC_SUBST(X_LIBS)dnl
489 AC_SUBST(X_EXTRA_LIBS)dnl
490 ])# AC_PATH_XTRA