IPv6 name resolution support on Solaris 8, from Heikki Vatiainen.
[metze/wireshark/wip.git] / acinclude.m4
1 dnl Macros that test for specific features.
2 dnl This file is part of the Autoconf packaging for Ethereal.
3 dnl Copyright (C) 1998-2000 by Gerald Combs.
4 dnl
5 dnl $Id: acinclude.m4,v 1.40 2002/01/30 08:46:27 guy Exp $
6 dnl
7 dnl This program is free software; you can redistribute it and/or modify
8 dnl it under the terms of the GNU General Public License as published by
9 dnl the Free Software Foundation; either version 2, or (at your option)
10 dnl any later version.
11 dnl
12 dnl This program is distributed in the hope that it will be useful,
13 dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
14 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 dnl GNU General Public License for more details.
16 dnl
17 dnl You should have received a copy of the GNU General Public License
18 dnl along with this program; if not, write to the Free Software
19 dnl Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
20 dnl 02111-1307, USA.
21 dnl
22 dnl As a special exception, the Free Software Foundation gives unlimited
23 dnl permission to copy, distribute and modify the configure scripts that
24 dnl are the output of Autoconf.  You need not follow the terms of the GNU
25 dnl General Public License when using or distributing such scripts, even
26 dnl though portions of the text of Autoconf appear in them.  The GNU
27 dnl General Public License (GPL) does govern all other use of the material
28 dnl that constitutes the Autoconf program.
29 dnl
30 dnl Certain portions of the Autoconf source text are designed to be copied
31 dnl (in certain cases, depending on the input) into the output of
32 dnl Autoconf.  We call these the "data" portions.  The rest of the Autoconf
33 dnl source text consists of comments plus executable code that decides which
34 dnl of the data portions to output in any given case.  We call these
35 dnl comments and executable code the "non-data" portions.  Autoconf never
36 dnl copies any of the non-data portions into its output.
37 dnl
38 dnl This special exception to the GPL applies to versions of Autoconf
39 dnl released by the Free Software Foundation.  When you make and
40 dnl distribute a modified version of Autoconf, you may extend this special
41 dnl exception to the GPL to apply to your modified version as well, *unless*
42 dnl your modified version has the potential to copy into its output some
43 dnl of the text that was the non-data portion of the version that you started
44 dnl with.  (In other words, unless your change moves or copies text from
45 dnl the non-data portions to the data portions.)  If your modification has
46 dnl such potential, you must delete any notice of this special exception
47 dnl to the GPL from your modified version.
48 dnl
49 dnl Written by David MacKenzie, with help from
50 dnl Franc,ois Pinard, Karl Berry, Richard Pixley, Ian Lance Taylor,
51 dnl Roland McGrath, Noah Friedman, david d zuhn, and many others.
52
53 #
54 # AC_ETHEREAL_ADD_DASH_L
55 #
56 # Add to the variable specified as the first argument a "-L" flag for the
57 # directory specified as the second argument, and, on Solaris, add a
58 # "-R" flag for it as well.
59 #
60 # XXX - IRIX, and other OSes, may require some flag equivalent to
61 # "-R" here.
62 #
63 AC_DEFUN(AC_ETHEREAL_ADD_DASH_L,
64 [$1="$$1 -L$2"
65 case "$host_os" in
66   solaris*)
67     $1="$$1 -R$2"
68   ;;
69 esac
70 ])
71
72
73 #
74 # AC_ETHEREAL_STRUCT_SA_LEN
75 #
76 dnl AC_STRUCT_ST_BLKSIZE extracted from the file in question,
77 dnl "acspecific.m4" in GNU Autoconf 2.12, and turned into
78 dnl AC_ETHEREAL_STRUCT_SA_LEN, which checks if "struct sockaddr"
79 dnl has the 4.4BSD "sa_len" member, and defines HAVE_SA_LEN; that's
80 dnl what's in this file.
81 dnl Done by Guy Harris <guy@alum.mit.edu> on 1998-11-14. 
82
83 dnl ### Checks for structure members
84
85 AC_DEFUN(AC_ETHEREAL_STRUCT_SA_LEN,
86 [AC_CACHE_CHECK([for sa_len in struct sockaddr], ac_cv_ethereal_struct_sa_len,
87 [AC_TRY_COMPILE([#include <sys/types.h>
88 #include <sys/socket.h>], [struct sockaddr s; s.sa_len;],
89 ac_cv_ethereal_struct_sa_len=yes, ac_cv_ethereal_struct_sa_len=no)])
90 if test $ac_cv_ethereal_struct_sa_len = yes; then
91   AC_DEFINE(HAVE_SA_LEN)
92 fi
93 ])
94
95 #
96 # AC_ETHEREAL_IPV6_STACK
97 #
98 # By Jun-ichiro "itojun" Hagino, <itojun@iijlab.net>
99 #
100 AC_DEFUN(AC_ETHEREAL_IPV6_STACK,
101 [
102         v6type=unknown
103         v6lib=none
104
105         AC_MSG_CHECKING([ipv6 stack type])
106         for i in v6d toshiba kame inria zeta linux linux-glibc solaris8; do
107                 case $i in
108                 v6d)
109                         AC_EGREP_CPP(yes, [
110 #include </usr/local/v6/include/sys/types.h>
111 #ifdef __V6D__
112 yes
113 #endif],
114                                 [v6type=$i; v6lib=v6;
115                                 v6libdir=/usr/local/v6/lib;
116                                 CFLAGS="-I/usr/local/v6/include $CFLAGS"])
117                         ;;
118                 toshiba)
119                         AC_EGREP_CPP(yes, [
120 #include <sys/param.h>
121 #ifdef _TOSHIBA_INET6
122 yes
123 #endif],
124                                 [v6type=$i; v6lib=inet6;
125                                 v6libdir=/usr/local/v6/lib;
126                                 CFLAGS="-DINET6 $CFLAGS"])
127                         ;;
128                 kame)
129                         AC_EGREP_CPP(yes, [
130 #include <netinet/in.h>
131 #ifdef __KAME__
132 yes
133 #endif],
134                                 [v6type=$i; v6lib=inet6;
135                                 v6libdir=/usr/local/v6/lib;
136                                 CFLAGS="-DINET6 $CFLAGS"])
137                         ;;
138                 inria)
139                         AC_EGREP_CPP(yes, [
140 #include <netinet/in.h>
141 #ifdef IPV6_INRIA_VERSION
142 yes
143 #endif],
144                                 [v6type=$i; CFLAGS="-DINET6 $CFLAGS"])
145                         ;;
146                 zeta)
147                         AC_EGREP_CPP(yes, [
148 #include <sys/param.h>
149 #ifdef _ZETA_MINAMI_INET6
150 yes
151 #endif],
152                                 [v6type=$i; v6lib=inet6;
153                                 v6libdir=/usr/local/v6/lib;
154                                 CFLAGS="-DINET6 $CFLAGS"])
155                         ;;
156                 linux)
157                         if test -d /usr/inet6; then
158                                 v6type=$i
159                                 v6lib=inet6
160                                 v6libdir=/usr/inet6
161                                 CFLAGS="-DINET6 $CFLAGS"
162                         fi
163                         ;;
164                 linux-glibc)
165                         AC_EGREP_CPP(yes, [
166 #include <features.h>
167 #if defined(__GLIBC__) && defined(__GLIBC_MINOR__)
168 #if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 1) || __GLIBC__ > 2
169 yes
170 #endif
171 #endif],
172                         [v6type=$i; v6lib=inet6; CFLAGS="-DINET6 $CFLAGS"])
173                         ;;
174                 solaris8)
175                         if test "`uname -s`" = "SunOS" && test "`uname -r`" = "5.8"; then
176                                 v6type=$i
177                                 v6lib=inet6
178                                 [CFLAGS="-DINET6 -DSOLARIS8_INET6 $CFLAGS"]
179                         fi
180                         ;; 
181                 esac
182                 if test "$v6type" != "unknown"; then
183                         break
184                 fi
185         done
186
187         if test "$v6lib" != "none"; then
188                 for dir in $v6libdir /usr/local/v6/lib /usr/local/lib; do
189                         if test -d $dir -a -f $dir/lib$v6lib.a; then
190                                 LIBS="-L$dir $LIBS -l$v6lib"
191                                 break
192                         fi
193                 done
194                 enable_ipv6="yes"
195         else
196                 enable_ipv6="no"
197         fi
198         AC_MSG_RESULT(["$v6type, $v6lib"])
199 ])
200
201 #
202 # AC_ETHEREAL_GETHOSTBY_LIB_CHECK
203 #
204 # Checks whether we need "-lnsl" to get "gethostby*()", which we use
205 # in "resolv.c".
206 #
207 # Adapted from stuff in the AC_PATH_XTRA macro in "acspecific.m4" in
208 # GNU Autoconf 2.13; the comment came from there.
209 # Done by Guy Harris <guy@alum.mit.edu> on 2000-01-14. 
210 #
211 AC_DEFUN(AC_ETHEREAL_GETHOSTBY_LIB_CHECK,
212 [
213     # msh@cis.ufl.edu says -lnsl (and -lsocket) are needed for his 386/AT,
214     # to get the SysV transport functions.
215     # chad@anasazi.com says the Pyramid MIS-ES running DC/OSx (SVR4)
216     # needs -lnsl.
217     # The nsl library prevents programs from opening the X display
218     # on Irix 5.2, according to dickey@clark.net.
219     AC_CHECK_FUNC(gethostbyname, ,
220         AC_CHECK_LIB(nsl, gethostbyname, NSL_LIBS="-lnsl"))
221     AC_SUBST(NSL_LIBS)
222 ])
223
224 #
225 # AC_ETHEREAL_SOCKET_LIB_CHECK
226 #
227 # Checks whether we need "-lsocket" to get "socket()", which is used
228 # by libpcap on some platforms - and, in effect, "gethostby*()" on
229 # most if not all platforms (so that it can use NIS or DNS or...
230 # to look up host names).
231 #
232 # Adapted from stuff in the AC_PATH_XTRA macro in "acspecific.m4" in
233 # GNU Autoconf 2.13; the comment came from there.
234 # Done by Guy Harris <guy@alum.mit.edu> on 2000-01-14. 
235 #
236 # We use "connect" because that's what AC_PATH_XTRA did.
237 #
238 AC_DEFUN(AC_ETHEREAL_SOCKET_LIB_CHECK,
239 [
240     # lieder@skyler.mavd.honeywell.com says without -lsocket,
241     # socket/setsockopt and other routines are undefined under SCO ODT
242     # 2.0.  But -lsocket is broken on IRIX 5.2 (and is not necessary
243     # on later versions), says simon@lia.di.epfl.ch: it contains
244     # gethostby* variants that don't use the nameserver (or something).
245     # -lsocket must be given before -lnsl if both are needed.
246     # We assume that if connect needs -lnsl, so does gethostbyname.
247     AC_CHECK_FUNC(connect, ,
248       AC_CHECK_LIB(socket, connect, SOCKET_LIBS="-lsocket",
249                 AC_MSG_ERROR(Function 'socket' not found.), $NSL_LIBS))
250     AC_SUBST(SOCKET_LIBS)
251 ])
252
253 #
254 # AC_ETHEREAL_PCAP_CHECK
255 #
256 AC_DEFUN(AC_ETHEREAL_PCAP_CHECK,
257 [
258         if test -z "$pcap_dir"
259         then
260           #
261           # The user didn't specify a directory in which libpcap resides;
262           # we assume that the current library search path will work,
263           # but we may have to look for the header in a "pcap"
264           # subdirectory of "/usr/include" or "/usr/local/include",
265           # as some systems apparently put "pcap.h" in a "pcap"
266           # subdirectory, and we also check "$prefix/include".
267           #
268           # XXX - should we just add "$prefix/include" to the include
269           # search path and "$prefix/lib" to the library search path?
270           #
271           AC_MSG_CHECKING(for extraneous pcap header directories)
272           found_pcap_dir=""
273           for pcap_dir in /usr/include/pcap /usr/local/include/pcap $prefix/include
274           do
275             if test -d $pcap_dir ; then
276                 CFLAGS="$CFLAGS -I$pcap_dir"
277                 CPPFLAGS="$CPPFLAGS -I$pcap_dir"
278                 found_pcap_dir=" $found_pcap_dir -I$pcap_dir"
279             fi
280           done
281
282           if test "$found_pcap_dir" != "" ; then
283             AC_MSG_RESULT(found --$found_pcap_dir added to CFLAGS)
284           else
285             AC_MSG_RESULT(not found)
286           fi
287         else
288           #
289           # The user specified a directory in which libpcap resides,
290           # so add the "include" subdirectory of that directory to
291           # the include file search path and the "lib" subdirectory
292           # of that directory to the library search path.
293           #
294           # XXX - if there's also a libpcap in a directory that's
295           # already in CFLAGS, CPPFLAGS, or LDFLAGS, this won't
296           # make us find the version in the specified directory,
297           # as the compiler and/or linker will search that other
298           # directory before it searches the specified directory.
299           #
300           CFLAGS="$CFLAGS -I$pcap_dir/include"
301           CPPFLAGS="$CPPFLAGS -I$pcap_dir/include"
302           AC_ETHEREAL_ADD_DASH_L(LDFLAGS, $pcap_dir/lib)
303         fi
304
305         # Pcap header checks
306         AC_CHECK_HEADER(net/bpf.h,,
307             AC_MSG_ERROR([[Header file net/bpf.h not found; if you installed libpcap from source, did you also do \"make install-incl\"?]]))
308         AC_CHECK_HEADER(pcap.h,, AC_MSG_ERROR(Header file pcap.h not found.))
309
310         #
311         # Check to see if we find "pcap_open_live" in "-lpcap".
312         #
313         AC_CHECK_LIB(pcap, pcap_open_live,
314           [
315             PCAP_LIBS=-lpcap
316             AC_DEFINE(HAVE_LIBPCAP)
317           ], AC_MSG_ERROR(Library libpcap not found.),
318           $SOCKET_LIBS $NSL_LIBS)
319         AC_SUBST(PCAP_LIBS)
320 ])
321
322 #
323 # AC_ETHEREAL_PCAP_VERSION_CHECK
324 #
325 # Check whether "pcap_version" is defined by libpcap.
326 #
327 AC_DEFUN(AC_ETHEREAL_PCAP_VERSION_CHECK,
328 [
329         AC_MSG_CHECKING(whether pcap_version is defined by libpcap)
330         ac_save_LIBS="$LIBS"
331         LIBS="$PCAP_LIBS $SOCKET_LIBS $NSL_LIBS $LIBS"
332         AC_TRY_LINK([],
333            [
334 char *
335 return_pcap_version(void)
336 {
337         extern char pcap_version[];
338
339         return pcap_version;
340 }
341            ],
342            ac_cv_pcap_version_defined=yes,
343            ac_cv_pcap_version_defined=no,
344            [echo $ac_n "cross compiling; assumed OK... $ac_c"])
345         LIBS="$ac_save_LIBS"
346         if test "$ac_cv_pcap_version_defined" = yes ; then
347                 AC_MSG_RESULT(yes)
348                 AC_DEFINE(HAVE_PCAP_VERSION)
349         else
350                 AC_MSG_RESULT(no)
351         fi
352 ])
353
354 #
355 # AC_ETHEREAL_ZLIB_CHECK
356 #
357 AC_DEFUN(AC_ETHEREAL_ZLIB_CHECK,
358 [
359         #
360         # Make sure we have "zlib.h".  If we don't, it means we probably
361         # don't have zlib, so don't use it.
362         #
363         AC_CHECK_HEADER(zlib.h,,enable_zlib=no)
364
365         if test x$enable_zlib != xno
366         then
367                 #
368                 # Well, we at least have the zlib header file.
369                 #
370                 # Check for "gzseek()" in zlib, because we need it, but
371                 # some older versions of zlib don't have it.  It appears
372                 # from the zlib ChangeLog that any released version of zlib
373                 # with "gzseek()" should have the other routines we
374                 # depend on, such as "gztell()", and "zError()".
375                 # (I think they may also get "gzgets()", in which case
376                 # we can get rid of our own private "gzgets()"
377                 # implementation, as any zlib that's adequate for our
378                 # purposes will have "gzgets()".)
379                 #
380                 AC_CHECK_LIB(z, gzseek,,enable_zlib=no)
381         fi
382
383         if test x$enable_zlib != xno
384         then
385                 #
386                 # Well, we at least have the zlib header file and a zlib
387                 # with "gzseek()".
388                 #
389                 # Now check for "gzseek()" in zlib when linking with the
390                 # linker flags for GTK+ applications; people often grab
391                 # XFree86 source and build and install it on their systems,
392                 # and they appear sometimes to misconfigure XFree86 so that,
393                 # even on systems with zlib, it assumes there is no zlib,
394                 # so the XFree86 build process builds and installs its
395                 # own zlib in the X11 library directory.
396                 #
397                 # The XFree86 zlib is an older version that lacks
398                 # "gzseek()", and that's the zlib with which Ethereal
399                 # gets linked, so the build of Ethereal fails.
400                 #
401                 ac_save_CFLAGS="$CFLAGS"
402                 ac_save_LIBS="$LIBS"
403                 CFLAGS="$CFLAGS $GTK_CFLAGS"
404                 LIBS="$GTK_LIBS -lz $LIBS"
405                 AC_MSG_CHECKING([for gzseek missing when linking with X11])
406                 AC_TRY_LINK_FUNC(gzseek, AC_MSG_RESULT(no),
407                   [
408                     AC_MSG_RESULT(yes)
409                     AC_MSG_ERROR(old zlib found when linking with X11 - get rid of old zlib.)
410                   ])
411                 CFLAGS="$ac_save_CFLAGS"
412                 LIBS="$ac_save_LIBS"
413         fi
414 ])
415
416 #
417 # AC_ETHEREAL_UCDSNMP_CHECK
418 #
419 AC_DEFUN(AC_ETHEREAL_UCDSNMP_CHECK,
420 [
421         want_ucdsnmp=yes
422
423         AC_ARG_WITH(ucdsnmp,
424         [  --with-ucdsnmp=DIR      use UCD SNMP client library, located in directory DIR.], [
425         if test $withval = no
426         then
427                 want_ucdsnmp=no
428         else
429                 want_ucdsnmp=yes
430                 ucdsnmp_user_dir=$withval
431         fi
432         ])
433
434         if test $want_ucdsnmp = yes
435         then
436                 ucdsnmpdir=""
437
438                 for d in $ucdsnmp_user_dir $prefix
439                 do
440                         if test x$d != xNONE 
441                         then
442                                 AC_MSG_CHECKING($d for ucd-snmp)
443
444                                 if test x$d != x/usr/local && test -f $d/include/ucd-snmp/snmp.h
445                                 then
446                                         AC_MSG_RESULT(found)
447                                         ucdsnmpdir=$d
448                                         break
449                                 else
450                                         AC_MSG_RESULT(not found)
451                                 fi
452                         fi
453                 done
454
455                 if test x$ucdsnmpdir != x
456                 then
457                         AC_MSG_RESULT(added $d to paths)
458                         CFLAGS="$CFLAGS -I${ucdsnmpdir}/include"
459                         CPPFLAGS="$CPPFLAGS -I${ucdsnmpdir}/include"
460                         AC_ETHEREAL_ADD_DASH_L(LDFLAGS, ${ucdsnmpdir}/lib)
461                 fi
462         fi
463 ])
464
465 #
466 # AC_ETHEREAL_SSL_CHECK
467 #
468 AC_DEFUN(AC_ETHEREAL_SSL_CHECK,
469 [
470         want_ssl=defaultyes
471
472         AC_ARG_WITH(ssl,
473         [  --with-ssl=DIR          use SSL crypto library, located in directory DIR.], [
474         if   test "x$withval" = "xno";  then
475                 want_ssl=no
476         elif test "x$withval" = "xyes"; then
477                 want_ssl=yes
478         elif test -d "$withval"; then
479                 want_ssl=yes
480                 AC_ETHEREAL_ADD_DASH_L(LDFLAGS, ${withval}/lib)
481         fi
482         ])
483
484         if test "x$want_ssl" = "xdefaultyes"; then
485                 want_ssl=yes
486                 withval=/usr/local/ssl
487                 if test -d "$withval"; then
488                         AC_ETHEREAL_ADD_DASH_L(LDFLAGS, ${withval}/lib)
489                 fi
490         fi
491
492         if test "x$want_ssl" = "xyes"; then
493                 AC_CHECK_LIB(crypto, EVP_md5,
494                   [
495                     SSL_LIBS=-lcrypto
496                   ],,
497                 )
498         else
499                 AC_MSG_RESULT(not required)
500         fi
501 ])
502
503 #
504 # AC_ETHEREAL_RPM_CHECK
505 # Looks for the rpm program, and checks to see if we can redefine "_topdir".
506 #
507 AC_DEFUN(AC_ETHEREAL_RPM_CHECK,
508 [
509         AC_CHECK_PROG(ac_cv_ethereal_have_rpm, rpm, "yes", "no")
510         if test "x$ac_cv_ethereal_have_rpm" = "xyes"; then
511                 rpm --define '_topdir /tmp' > /dev/null 2>&1
512                 AC_MSG_CHECKING(to see if we can redefine _topdir)
513                 if test $? -eq 0 ; then
514                         AC_MSG_RESULT(yes)
515                         HAVE_RPM=yes
516                 else
517                         AC_MSG_RESULT(no.  You'll have to build packages manually.)
518                         HAVE_RPM=no
519                 fi
520         fi
521 ])