Prepare for lua 5.1
[obnox/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$
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, 1, [Define if sa_len field exists in struct sockaddr])
92 fi
93 ])
94
95
96 dnl
97 dnl Check whether a given format can be used to print 64-bit integers
98 dnl
99 AC_DEFUN([AC_ETHEREAL_CHECK_64BIT_FORMAT],
100 [
101   AC_MSG_CHECKING([whether %$1x can be used to format 64-bit integers])
102   AC_RUN_IFELSE(
103     [
104       AC_LANG_SOURCE(
105         [[
106 #         ifdef HAVE_INTTYPES_H
107           #include <inttypes.h>
108 #         endif
109           #include <glibconfig.h>
110           #include <stdio.h>
111           #include <sys/types.h>
112
113           main()
114           {
115             guint64 t = 1;
116             char strbuf[16+1];
117             sprintf(strbuf, "%016$1x", t << 32);
118             if (strcmp(strbuf, "0000000100000000") == 0)
119               exit(0);
120             else
121               exit(1);
122           }
123         ]])
124     ],
125     [
126       AC_DEFINE(PRId64, "$1d", [Format for printing 64-bit signed decimal numbers])
127       AC_DEFINE(PRIo64, "$1o", [Format for printing 64-bit unsigned octal numbers])
128       AC_DEFINE(PRIx64, "$1x", [Format for printing 64-bit unsigned hexadecimal numbers (lower-case)])
129       AC_DEFINE(PRIX64, "$1X", [Format for printing 64-bit unsigned hexadecimal numbers (upper-case)])
130       AC_DEFINE(PRIu64, "$1u", [Format for printing 64-bit unsigned decimal numbers])
131       AC_MSG_RESULT(yes)
132     ],
133     [
134       AC_MSG_RESULT(no)
135       $2
136     ])
137 ])
138
139 #
140 # AC_ETHEREAL_IPV6_STACK
141 #
142 # By Jun-ichiro "itojun" Hagino, <itojun@iijlab.net>
143 #
144 AC_DEFUN([AC_ETHEREAL_IPV6_STACK],
145 [
146         v6type=unknown
147         v6lib=none
148
149         AC_MSG_CHECKING([ipv6 stack type])
150         for i in v6d toshiba kame inria zeta linux linux-glibc solaris8; do
151                 case $i in
152                 v6d)
153                         AC_EGREP_CPP(yes, [
154 #include </usr/local/v6/include/sys/types.h>
155 #ifdef __V6D__
156 yes
157 #endif],
158                                 [v6type=$i; v6lib=v6;
159                                 v6libdir=/usr/local/v6/lib;
160                                 CFLAGS="-I/usr/local/v6/include $CFLAGS"])
161                         ;;
162                 toshiba)
163                         AC_EGREP_CPP(yes, [
164 #include <sys/param.h>
165 #ifdef _TOSHIBA_INET6
166 yes
167 #endif],
168                                 [v6type=$i; v6lib=inet6;
169                                 v6libdir=/usr/local/v6/lib;
170                                 CFLAGS="-DINET6 $CFLAGS"])
171                         ;;
172                 kame)
173                         AC_EGREP_CPP(yes, [
174 #include <netinet/in.h>
175 #ifdef __KAME__
176 yes
177 #endif],
178                                 [v6type=$i; v6lib=inet6;
179                                 v6libdir=/usr/local/v6/lib;
180                                 CFLAGS="-DINET6 $CFLAGS"])
181                         ;;
182                 inria)
183                         AC_EGREP_CPP(yes, [
184 #include <netinet/in.h>
185 #ifdef IPV6_INRIA_VERSION
186 yes
187 #endif],
188                                 [v6type=$i; CFLAGS="-DINET6 $CFLAGS"])
189                         ;;
190                 zeta)
191                         AC_EGREP_CPP(yes, [
192 #include <sys/param.h>
193 #ifdef _ZETA_MINAMI_INET6
194 yes
195 #endif],
196                                 [v6type=$i; v6lib=inet6;
197                                 v6libdir=/usr/local/v6/lib;
198                                 CFLAGS="-DINET6 $CFLAGS"])
199                         ;;
200                 linux)
201                         if test -d /usr/inet6; then
202                                 v6type=$i
203                                 v6lib=inet6
204                                 v6libdir=/usr/inet6
205                                 CFLAGS="-DINET6 $CFLAGS"
206                         fi
207                         ;;
208                 linux-glibc)
209                         AC_EGREP_CPP(yes, [
210 #include <features.h>
211 #if defined(__GLIBC__) && defined(__GLIBC_MINOR__)
212 #if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 1) || __GLIBC__ > 2
213 yes
214 #endif
215 #endif],
216                         [v6type=$i; v6lib=inet6; CFLAGS="-DINET6 $CFLAGS"])
217                         ;;
218                 solaris8)
219                         if test "`uname -s`" = "SunOS" && test "`uname -r`" = "5.8"; then
220                                 v6type=$i
221                                 v6lib=inet6
222                                 [CFLAGS="-DINET6 -DSOLARIS8_INET6 $CFLAGS"]
223                         fi
224                         ;; 
225                 esac
226                 if test "$v6type" != "unknown"; then
227                         break
228                 fi
229         done
230
231         if test "$v6lib" != "none"; then
232                 for dir in $v6libdir /usr/local/v6/lib /usr/local/lib; do
233                         if test -d $dir -a -f $dir/lib$v6lib.a; then
234                                 LIBS="-L$dir $LIBS -l$v6lib"
235                                 break
236                         fi
237                 done
238                 enable_ipv6="yes"
239         else
240                 enable_ipv6="no"
241         fi
242         AC_MSG_RESULT(["$v6type, $v6lib"])
243 ])
244
245 #
246 # AC_ETHEREAL_GETHOSTBY_LIB_CHECK
247 #
248 # Checks whether we need "-lnsl" to get "gethostby*()", which we use
249 # in "resolv.c".
250 #
251 # Adapted from stuff in the AC_PATH_XTRA macro in "acspecific.m4" in
252 # GNU Autoconf 2.13; the comment came from there.
253 # Done by Guy Harris <guy@alum.mit.edu> on 2000-01-14. 
254 #
255 AC_DEFUN([AC_ETHEREAL_GETHOSTBY_LIB_CHECK],
256 [
257     # msh@cis.ufl.edu says -lnsl (and -lsocket) are needed for his 386/AT,
258     # to get the SysV transport functions.
259     # chad@anasazi.com says the Pyramid MIS-ES running DC/OSx (SVR4)
260     # needs -lnsl.
261     # The nsl library prevents programs from opening the X display
262     # on Irix 5.2, according to dickey@clark.net.
263     AC_CHECK_FUNC(gethostbyname, ,
264         AC_CHECK_LIB(nsl, gethostbyname, NSL_LIBS="-lnsl"))
265     AC_SUBST(NSL_LIBS)
266 ])
267
268 #
269 # AC_ETHEREAL_SOCKET_LIB_CHECK
270 #
271 # Checks whether we need "-lsocket" to get "socket()", which is used
272 # by libpcap on some platforms - and, in effect, "gethostby*()" on
273 # most if not all platforms (so that it can use NIS or DNS or...
274 # to look up host names).
275 #
276 # Adapted from stuff in the AC_PATH_XTRA macro in "acspecific.m4" in
277 # GNU Autoconf 2.13; the comment came from there.
278 # Done by Guy Harris <guy@alum.mit.edu> on 2000-01-14. 
279 #
280 # We use "connect" because that's what AC_PATH_XTRA did.
281 #
282 AC_DEFUN([AC_ETHEREAL_SOCKET_LIB_CHECK],
283 [
284     # lieder@skyler.mavd.honeywell.com says without -lsocket,
285     # socket/setsockopt and other routines are undefined under SCO ODT
286     # 2.0.  But -lsocket is broken on IRIX 5.2 (and is not necessary
287     # on later versions), says simon@lia.di.epfl.ch: it contains
288     # gethostby* variants that don't use the nameserver (or something).
289     # -lsocket must be given before -lnsl if both are needed.
290     # We assume that if connect needs -lnsl, so does gethostbyname.
291     AC_CHECK_FUNC(connect, ,
292       AC_CHECK_LIB(socket, connect, SOCKET_LIBS="-lsocket",
293                 AC_MSG_ERROR(Function 'socket' not found.), $NSL_LIBS))
294     AC_SUBST(SOCKET_LIBS)
295 ])
296
297 #
298 # AC_ETHEREAL_PCAP_CHECK
299 #
300 AC_DEFUN([AC_ETHEREAL_PCAP_CHECK],
301 [
302         if test -z "$pcap_dir"
303         then
304           # Pcap header checks
305           # XXX need to set a var AC_CHECK_HEADER(pcap.h,,)
306
307           #
308           # The user didn't specify a directory in which libpcap resides;
309           # we assume that the current library search path will work,
310           # but we may have to look for the header in a "pcap"
311           # subdirectory of "/usr/include" or "/usr/local/include",
312           # as some systems apparently put "pcap.h" in a "pcap"
313           # subdirectory, and we also check "$prefix/include" - and
314           # "$prefix/include/pcap", in case $prefix is set to
315           # "/usr/include" or "/usr/local/include".
316           #
317           # XXX - should we just add "$prefix/include" to the include
318           # search path and "$prefix/lib" to the library search path?
319           #
320           AC_MSG_CHECKING(for extraneous pcap header directories)
321           found_pcap_dir=""
322           pcap_dir_list="/usr/include/pcap $prefix/include/pcap $prefix/include"
323           if test "x$ac_cv_enable_usr_local" = "xyes" ; then
324             pcap_dir_list="$pcap_dir_list /usr/local/include/pcap"
325           fi
326           for pcap_dir in $pcap_dir_list
327           do
328             if test -d $pcap_dir ; then
329                 if test x$pcap_dir != x/usr/include -a x$pcap_dir != x/usr/local/include ; then
330                     CFLAGS="$CFLAGS -I$pcap_dir"
331                     CPPFLAGS="$CPPFLAGS -I$pcap_dir"
332                 fi
333                 found_pcap_dir=" $found_pcap_dir -I$pcap_dir"
334                 break
335             fi
336           done
337
338           if test "$found_pcap_dir" != "" ; then
339             AC_MSG_RESULT(found --$found_pcap_dir added to CFLAGS)
340           else
341             AC_MSG_RESULT(not found)
342           fi
343         else
344           #
345           # The user specified a directory in which libpcap resides,
346           # so add the "include" subdirectory of that directory to
347           # the include file search path and the "lib" subdirectory
348           # of that directory to the library search path.
349           #
350           # XXX - if there's also a libpcap in a directory that's
351           # already in CFLAGS, CPPFLAGS, or LDFLAGS, this won't
352           # make us find the version in the specified directory,
353           # as the compiler and/or linker will search that other
354           # directory before it searches the specified directory.
355           #
356           CFLAGS="$CFLAGS -I$pcap_dir/include"
357           CPPFLAGS="$CPPFLAGS -I$pcap_dir/include"
358           AC_ETHEREAL_ADD_DASH_L(LDFLAGS, $pcap_dir/lib)
359         fi
360
361         # Pcap header check
362         AC_CHECK_HEADER(pcap.h,, 
363             AC_MSG_ERROR([[Header file pcap.h not found; if you installed libpcap
364 from source, did you also do \"make install-incl\", and if you installed a
365 binary package of libpcap, is there also a developer's package of libpcap,
366 and did you also install that package?]]))
367
368         #
369         # Check to see if we find "pcap_open_live" in "-lpcap".
370         #
371         AC_CHECK_LIB(pcap, pcap_open_live,
372           [
373             PCAP_LIBS=-lpcap
374             AC_DEFINE(HAVE_LIBPCAP, 1, [Define to use libpcap library])
375           ], [
376             AC_MSG_CHECKING([for pcap_open_live in -lpcap -lcfg -lodm])
377             ac_save_LIBS="$LIBS"
378             LIBS="-lpcap -lcfg -lodm"
379             AC_TRY_LINK(
380                 [
381 #       include <pcap.h>
382                 ],
383                 [
384         pcap_open_live(NULL, 0, 0, 0, NULL);
385                 ],
386                 [
387                 AC_MSG_RESULT([yes])
388                 PCAP_LIBS="-lpcap -lcfg -lodm"
389                 AC_DEFINE(HAVE_LIBPCAP, 1, [Define to use libpcap library])
390                 ],
391                 [
392                 AC_MSG_RESULT([no])
393                 AC_MSG_ERROR([Library libpcap not found.])
394                 ])
395             LIBS=$ac_save_LIBS
396           ], $SOCKET_LIBS $NSL_LIBS)
397         AC_SUBST(PCAP_LIBS)
398
399         #
400         # Check whether various variables and functions are defined by
401         # libpcap.
402         #
403         ac_save_LIBS="$LIBS"
404         AC_MSG_CHECKING(whether pcap_version is defined by libpcap)
405         LIBS="$PCAP_LIBS $SOCKET_LIBS $NSL_LIBS $LIBS"
406         AC_TRY_LINK(
407            [
408 #       include <stdio.h>
409         extern char *pcap_version;
410            ],
411            [
412         printf ("%s\n", pcap_version);
413            ],
414            ac_cv_pcap_version_defined=yes,
415            ac_cv_pcap_version_defined=no,
416            [echo $ac_n "cross compiling; assumed OK... $ac_c"])
417         if test "$ac_cv_pcap_version_defined" = yes ; then
418                 AC_MSG_RESULT(yes)
419                 AC_DEFINE(HAVE_PCAP_VERSION, 1, [Define if libpcap version is known])
420         else
421                 AC_MSG_RESULT(no)
422         fi
423         AC_CHECK_FUNCS(pcap_open_dead pcap_freecode)
424         #
425         # Later versions of Mac OS X 10.3[.x] ship a pcap.h that
426         # doesn't define pcap_if_t but ship an 0.8[.x] libpcap,
427         # so the library has "pcap_findalldevs()", but pcap.h
428         # doesn't define "pcap_if_t" so you can't actually *use*
429         # "pcap_findalldevs()".
430         #
431         # That even appears to be true of systems shipped with
432         # 10.3.4, so it doesn't appear only to be a case of
433         # Software Update not updating header files.
434         #
435         # (You can work around this by installing the 0.8 header
436         # files.)
437         #
438         AC_CACHE_CHECK([whether pcap_findalldevs is present and usable],
439           [ac_cv_func_pcap_findalldevs],
440           [
441             AC_LINK_IFELSE(
442               [
443                 AC_LANG_SOURCE(
444                   [[
445                     #include <pcap.h>
446                     main()
447                     {
448                       pcap_if_t *devpointer;
449                       char errbuf[1];
450
451                       pcap_findalldevs(&devpointer, errbuf);
452                     }
453                   ]])
454               ],
455               [
456                 ac_cv_func_pcap_findalldevs=yes
457               ],
458               [
459                 ac_cv_func_pcap_findalldevs=no
460               ])
461           ])
462         #
463         # Don't check for other new routines that showed up after
464         # "pcap_findalldevs()" if we don't have a usable
465         # "pcap_findalldevs()", so we don't end up using them if the
466         # "pcap.h" is crufty and old and doesn't declare them.
467         #
468         if test $ac_cv_func_pcap_findalldevs = "yes" ; then
469           AC_DEFINE(HAVE_PCAP_FINDALLDEVS, 1,
470            [Define to 1 if you have the `pcap_findalldevs' function and a pcap.h that declares pcap_if_t.])
471           AC_CHECK_FUNCS(pcap_datalink_val_to_name pcap_datalink_name_to_val)
472           AC_CHECK_FUNCS(pcap_list_datalinks pcap_set_datalink pcap_lib_version)
473           AC_CHECK_FUNCS(pcap_get_selectable_fd)
474         fi
475         LIBS="$ac_save_LIBS"
476 ])
477
478 #
479 # AC_ETHEREAL_ZLIB_CHECK
480 #
481 AC_DEFUN([AC_ETHEREAL_ZLIB_CHECK],
482 [
483         if test "x$zlib_dir" != "x"
484         then
485           #
486           # The user specified a directory in which zlib resides,
487           # so add the "include" subdirectory of that directory to
488           # the include file search path and the "lib" subdirectory
489           # of that directory to the library search path.
490           #
491           # XXX - if there's also a zlib in a directory that's
492           # already in CFLAGS, CPPFLAGS, or LDFLAGS, this won't
493           # make us find the version in the specified directory,
494           # as the compiler and/or linker will search that other
495           # directory before it searches the specified directory.
496           #
497           ethereal_save_CFLAGS="$CFLAGS"
498           CFLAGS="$CFLAGS -I$zlib_dir/include"
499           ethereal_save_CPPFLAGS="$CPPFLAGS"
500           CPPFLAGS="$CPPFLAGS -I$zlib_dir/include"
501           ethereal_save_LIBS="$LIBS"
502           AC_ETHEREAL_ADD_DASH_L(LIBS, $zlib_dir/lib)
503         fi
504
505         #
506         # Make sure we have "zlib.h".  If we don't, it means we probably
507         # don't have zlib, so don't use it.
508         #
509         AC_CHECK_HEADER(zlib.h,,
510           [
511             if test "x$zlib_dir" != "x"
512             then
513               #
514               # The user used "--with-zlib=" to specify a directory
515               # containing zlib, but we didn't find the header file
516               # there; that either means they didn't specify the
517               # right directory or are confused about whether zlib
518               # is, in fact, installed.  Report the error and give up.
519               #
520               AC_MSG_ERROR([zlib header not found in directory specified in --with-zlib])
521             else
522               if test "x$want_zlib" = "xyes"
523               then
524                 #
525                 # The user tried to force us to use the library, but we
526                 # couldn't find the header file; report an error.
527                 #
528                 AC_MSG_ERROR(Header file zlib.h not found.)
529               else
530                 #
531                 # We couldn't find the header file; don't use the
532                 # library, as it's probably not present.
533                 #
534                 want_zlib=no
535               fi
536             fi
537           ])
538
539         if test "x$want_zlib" != "xno"
540         then
541                 #
542                 # Well, we at least have the zlib header file.
543                 #
544                 # Check for "gzgets()" in zlib, because we need it, but
545                 # some older versions of zlib don't have it.  It appears
546                 # from the zlib ChangeLog that any released version of zlib
547                 # with "gzgets()" should have the other routines we
548                 # depend on, such as "gzseek()", "gztell()", and "zError()".
549                 #
550                 # Another reason why we require "gzgets()" is that
551                 # some versions of zlib that didn't have it, such
552                 # as 1.0.8, had a bug in "gzseek()" that meant that it
553                 # doesn't work correctly on uncompressed files; this
554                 # means we cannot use version 1.0.8.  (Unfortunately,
555                 # that's the version that comes with recent X11 source,
556                 # and many people who install XFree86 on their Slackware
557                 # boxes don't realize that they should configure it to
558                 # use the native zlib rather than building and installing
559                 # the crappy old version that comes with XFree86.)
560                 #
561                 # I.e., we can't just avoid using "gzgets()", as
562                 # versions of zlib without "gzgets()" are likely to have
563                 # a broken "gzseek()".
564                 #
565                 AC_CHECK_LIB(z, gzgets,
566                 [
567                         if test "x$zlib_dir" != "x"
568                         then
569                                 #
570                                 # Put the "-I" and "-L" flags for zlib at
571                                 # the beginning of CFLAGS, CPPFLAGS, and
572                                 # LIBS.
573                                 #
574                                 LIBS=""
575                                 AC_ETHEREAL_ADD_DASH_L(LIBS, $zlib_dir/lib)
576                                 LIBS="$LIBS -lz $ethereal_save_LIBS"
577                         else
578                                 LIBS="-lz $LIBS"
579                         fi
580                         AC_DEFINE(HAVE_LIBZ, 1, [Define to use libz library])
581                 ],[
582                         if test "x$zlib_dir" != "x"
583                         then
584                                 #
585                                 # Restore the versions of CFLAGS, CPPFLAGS,
586                                 # and LIBS before we added the "-with-zlib="
587                                 # directory, as we didn't actually find
588                                 # zlib there, or didn't find a zlib that
589                                 # contains gzgets there.
590                                 #
591                                 CFLAGS="$ethereal_save_CFLAGS"
592                                 CPPFLAGS="$ethereal_save_CPPFLAGS"
593                                 LIBS="$ethereal_save_LIBS"
594                         fi
595                         want_zlib=no
596                 ])
597         fi
598
599         if test "x$want_zlib" != "xno"
600         then
601                 #
602                 # Well, we at least have the zlib header file and a zlib
603                 # with "gzgets()".
604                 #
605                 # Now check for "gzgets()" in zlib when linking with the
606                 # linker flags for GTK+ applications; people often grab
607                 # XFree86 source and build and install it on their systems,
608                 # and they appear sometimes to misconfigure XFree86 so that,
609                 # even on systems with zlib, it assumes there is no zlib,
610                 # so the XFree86 build process builds and installs its
611                 # own zlib in the X11 library directory.
612                 #
613                 # The XFree86 zlib is an older version that lacks
614                 # "gzgets()", and that's the zlib with which Ethereal
615                 # gets linked, so the build of Ethereal fails.
616                 #
617                 ac_save_CFLAGS="$CFLAGS"
618                 ac_save_LIBS="$LIBS"
619                 CFLAGS="$CFLAGS $GTK_CFLAGS"
620                 LIBS="$GTK_LIBS -lz $LIBS"
621                 AC_MSG_CHECKING([for gzgets missing when linking with X11])
622                 AC_TRY_LINK_FUNC(gzgets, AC_MSG_RESULT(no),
623                   [
624                     AC_MSG_RESULT(yes)
625                     AC_MSG_ERROR(old zlib found when linking with X11 - get rid of old zlib.)
626                   ])
627                 CFLAGS="$ac_save_CFLAGS"
628                 LIBS="$ac_save_LIBS"
629         fi
630 ])
631
632 #
633 # AC_ETHEREAL_LIBPCRE_CHECK
634 #
635 AC_DEFUN([AC_ETHEREAL_LIBPCRE_CHECK],
636 [
637         if test "x$pcre_dir" != "x"
638         then
639           #
640           # The user specified a directory in which libpcre resides,
641           # so add the "include" subdirectory of that directory to
642           # the include file search path and the "lib" subdirectory
643           # of that directory to the library search path.
644           #
645           # XXX - if there's also a libpcre in a directory that's
646           # already in CFLAGS, CPPFLAGS, or LDFLAGS, this won't
647           # make us find the version in the specified directory,
648           # as the compiler and/or linker will search that other
649           # directory before it searches the specified directory.
650           #
651           ethereal_save_CFLAGS="$CFLAGS"
652           CFLAGS="$CFLAGS -I$pcre_dir/include"
653           ethereal_save_CPPFLAGS="$CPPFLAGS"
654           CPPFLAGS="$CPPFLAGS -I$pcre_dir/include"
655           ethereal_save_LIBS="$LIBS"
656           LIBS="$LIBS -lpcre"
657           ethereal_save_LDFLAGS="$LDFLAGS"
658           LDFLAGS="$LDFLAGS -L$pcre_dir/lib"
659         fi
660
661         #
662         # Make sure we have "pcre.h".  If we don't, it means we probably
663         # don't have libpcre, so don't use it.
664         #
665         AC_CHECK_HEADER(pcre.h,,
666           [
667             if test "x$pcre_dir" != "x"
668             then
669               #
670               # The user used "--with-pcre=" to specify a directory
671               # containing libpcre, but we didn't find the header file
672               # there; that either means they didn't specify the
673               # right directory or are confused about whether libpcre
674               # is, in fact, installed.  Report the error and give up.
675               #
676               AC_MSG_ERROR([libpcre header not found in directory specified in --with-pcre])
677             else
678               if test "x$want_pcre" = "xyes"
679               then
680                 #
681                 # The user tried to force us to use the library, but we
682                 # couldn't find the header file; report an error.
683                 #
684                 AC_MSG_ERROR(Header file pcre.h not found.)
685               else
686                 #
687                 # We couldn't find the header file; don't use the
688                 # library, as it's probably not present.
689                 #
690                 want_pcre=no
691               fi
692             fi
693           ])
694
695         if test "x$want_pcre" != "xno"
696         then
697                 #
698                 # Well, we at least have the pcre header file.
699                 #
700                 # We're only using standard functions from libpcre,
701                 # so we don't need to perform extra checks.
702                 #
703                 AC_CHECK_LIB(pcre, pcre_compile,
704                 [
705                         if test "x$pcre_dir" != "x"
706                         then
707                                 #
708                                 # Put the "-I" and "-L" flags for pcre at
709                                 # the beginning of CFLAGS, CPPFLAGS,
710                                 # LDFLAGS, and LIBS.
711                                 #
712                                 PCRE_LIBS="-L$pcre_dir/lib -lpcre $ethereal_save_LIBS"
713                         else
714                                 PCRE_LIBS="-lpcre"
715                         fi
716                         AC_DEFINE(HAVE_LIBPCRE, 1, [Define to use libpcre library])
717                 ],[
718                         if test "x$pcre_dir" != "x"
719                         then
720                                 #
721                                 # Restore the versions of CFLAGS, CPPFLAGS,
722                                 # LDFLAGS, and LIBS before we added the
723                                 # "--with-pcre=" directory, as we didn't
724                                 # actually find pcre there.
725                                 #
726                                 CFLAGS="$ethereal_save_CFLAGS"
727                                 CPPFLAGS="$ethereal_save_CPPFLAGS"
728                                 LDFLAGS="$ethereal_save_LDFLAGS"
729                                 LIBS="$ethereal_save_LIBS"
730                                 PCRE_LIBS=""
731                         fi
732                         want_pcre=no
733                 ])
734                 AC_SUBST(PCRE_LIBS)
735         fi
736 ])
737
738 #
739 # AC_ETHEREAL_LIBLUA_CHECK
740 #
741 AC_DEFUN([AC_ETHEREAL_LIBLUA_CHECK],[
742
743         if test "x$lua_dir" != "x"
744         then
745                 #
746                 # The user specified a directory in which liblua resides,
747                 # so add the "include" subdirectory of that directory to
748                 # the include file search path and the "lib" subdirectory
749                 # of that directory to the library search path.
750                 #
751                 # XXX - if there's also a liblua in a directory that's
752                 # already in CFLAGS, CPPFLAGS, or LDFLAGS, this won't
753                 # make us find the version in the specified directory,
754                 # as the compiler and/or linker will search that other
755                 # directory before it searches the specified directory.
756                 #
757                 ethereal_save_CFLAGS="$CFLAGS"
758                 CFLAGS="$CFLAGS -I$lua_dir/include"
759                 ethereal_save_CPPFLAGS="$CPPFLAGS"
760                 CPPFLAGS="$CPPFLAGS -I$lua_dir/include"
761                 ethereal_save_LIBS="$LIBS"
762                 LIBS="$LIBS -L$lua_dir/lib -llua"
763                 ethereal_save_LDFLAGS="$LDFLAGS"
764                 LDFLAGS="$LDFLAGS -L$lua_dir/lib"
765         else 
766                 #
767                 # The user specified no directory in which liblua resides,
768                 # so just add "-llua -lliblua" to the used libs.
769                 #
770                 ethereal_save_CFLAGS="$CFLAGS"
771                 ethereal_save_CPPFLAGS="$CPPFLAGS"
772                 ethereal_save_LDFLAGS="$LDFLAGS"
773                 ethereal_save_LIBS="$LIBS"
774                 LIBS="$LIBS -llua"
775         fi
776
777         #
778         # Make sure we have "lua.h", "lualib.h" and "lauxlib.h".  If we don't, it means we probably
779         # don't have liblua, so don't use it.
780         #
781         AC_CHECK_HEADERS(lua.h lualib.h lauxlib.h,,
782         [
783                 if test "x$lua_dir" != "x"
784                 then
785                         #
786                         # The user used "--with-lua=" to specify a directory
787                         # containing liblua, but we didn't find the header file
788                         # there; that either means they didn't specify the
789                         # right directory or are confused about whether liblua
790                         # is, in fact, installed.  Report the error and give up.
791                         #
792                         AC_MSG_ERROR([liblua header not found in directory specified in --with-lua])
793                 else
794                         if test "x$want_lua" = "xyes"
795                         then
796                                 #
797                                 # The user tried to force us to use the library, but we
798                                 # couldn't find the header file; report an error.
799                                 #
800                                 AC_MSG_ERROR(Header file lua.h not found.)
801                         else
802                                 #
803                                 # We couldn't find the header file; don't use the
804                                 # library, as it's probably not present.
805                                 #
806                                 want_lua=no
807                         fi
808                 fi
809         ])
810
811         if test "x$want_lua" != "xno"
812         then
813                 #
814                 # Well, we at least have the lua header file.
815                 #
816                 # let's check if the libs are there
817                 #
818                 AC_CHECK_LIB(lua, lua_call,
819                 [
820                         if test "x$lua_dir" != "x"
821                         then
822                                 #
823                                 # Put the "-I" and "-L" flags for lua at
824                                 # the beginning of CFLAGS, CPPFLAGS,
825                                 # LDFLAGS, and LIBS.
826                                 #
827                                 LUA_LIBS="-L$lua_dir/lib -llua"
828                                 LUA_INCLUDES="-I$lua_dir/include"
829                         else
830                                 LUA_LIBS="-llua"
831                                 LUA_INCLUDES=""
832                         fi
833
834                         #
835                         # we got lua, now look for lualib
836                         #
837                         AC_CHECK_LIB(lualib, luaL_openlib,
838                         [
839                                 #
840                                 # we have 5.0
841                                 #
842                                 LUA_LIBS="$LUA_LIBS -llualib"
843                         ],[
844                                 #
845                                 # no lualib, in 5.1 there's only liblua
846                                 # do we have 5.1?
847                                 #
848                                 
849                                 LIBS="$ethereal_save_LIBS $LUA_LIBS"
850
851                                 AC_CHECK_LIB(lua, luaL_register,
852                                 [
853                                     #
854                                     #  Lua 5.1 found
855                                     #
856                                     AC_DEFINE(HAVE_LUA_5_1, 1, [Define to use Lua 5.1])
857                                 ],[
858                                     #
859                                     # No, it is not 5.1
860                                     #
861                                     if test "x$lua_dir" != "x"
862                                     then
863                                         #
864                                         # Restore the versions of CFLAGS, CPPFLAGS,
865                                         # LDFLAGS, and LIBS before we added the
866                                         # "--with-lua=" directory, as we didn't
867                                         # actually find lua there.
868                                         #
869                                         CFLAGS="$ethereal_save_CFLAGS"
870                                         CPPFLAGS="$ethereal_save_CPPFLAGS"
871                                         LDFLAGS="$ethereal_save_LDFLAGS"
872                                         LIBS="$ethereal_save_LIBS"
873                                         LUA_LIBS=""
874                                     fi
875                                     # User requested --with-lua but it isn't available
876                                     if test "x$want_lua" = "xyes"
877                                     then
878                                         AC_MSG_ERROR(Linking with liblualib failed.)
879                                     fi
880                                     want_lua=no
881                                 ])
882                         ])
883                 ],[  
884                         #
885                         # Restore the versions of CFLAGS, CPPFLAGS,
886                         # LDFLAGS, and LIBS before we added the
887                         # "--with-lua=" directory, as we didn't
888                         # actually find lua there.
889                         #
890                         CFLAGS="$ethereal_save_CFLAGS"
891                         CPPFLAGS="$ethereal_save_CPPFLAGS"
892                         LDFLAGS="$ethereal_save_LDFLAGS"
893                         LIBS="$ethereal_save_LIBS"
894                         LUA_LIBS=""
895                         # User requested --with-lua but it isn't available
896                         if test "x$want_lua" = "xyes"
897                         then
898                                 AC_MSG_ERROR(Linking with liblua failed.)
899                         fi
900                         want_lua=no
901                 ])
902
903         CFLAGS="$ethereal_save_CFLAGS"
904         CPPFLAGS="$ethereal_save_CPPFLAGS"
905         LDFLAGS="$ethereal_save_LDFLAGS"
906         LIBS="$ethereal_save_LIBS"
907         AC_SUBST(LUA_LIBS)
908         AC_SUBST(LUA_INCLUDES)
909
910         fi
911 ])
912
913 #
914 # AC_ETHEREAL_NETSNMP_CHECK
915 #
916 AC_DEFUN([AC_ETHEREAL_NETSNMP_CHECK],
917 [
918         dnl get the net-snmp-config binary
919         if test "x$netsnmpconfig" = "x" ; then
920                 #
921                 # The user didn't specify where net-snmp-config is
922                 # located; search for it.
923                 #
924                 AC_PATH_PROG(NETSNMPCONFIG, net-snmp-config)
925         else
926                 NETSNMPCONFIG=$netsnmpconfig
927                 if test ! -x $NETSNMPCONFIG -o ! -f $NETSNMPCONFIG ; then
928                         NETSNMPCONFIG=$netsnmpconfig/bin/net-snmp-config
929                         if test ! -x $NETSNMPCONFIG -o ! -f $NETSNMPCONFIG ; then
930                                 AC_MSG_ERROR(Invalid net-snmp-config: $netsnmpconfig)
931                         fi
932                 fi
933         fi
934
935         #
936         # XXX - check whether $NETSNMPCONFIG is executable?
937         # if test "x$NETSNMPCONFIG" != "xno" -a "x$NETSNMPCONFIG" != "x" -a -x "$NETSNMPCONFIG" ; then
938         # We already did that if it was set; presumably AC_PATH_PROG
939         # will fail if it doesn't find an executable version.
940         #
941         if test "x$NETSNMPCONFIG" != "x" ; then
942                 dnl other choices for flags to use here: could also use
943                 dnl --prefix or --exec-prefix if you don't want the full list.
944
945                 #
946                 # Save the current settings of CFLAGS and CPPFLAGS, and add
947                 # the output of "$NETSNMPCONFIG --cflags" to it, so that when
948                 # searching for the Net-SNMP headers, we look in whatever
949                 # directory that output specifies.
950                 #
951                 ethereal_save_CFLAGS="$CFLAGS"
952                 ethereal_save_CPPFLAGS="$CPPFLAGS"
953                 CFLAGS="$CFLAGS `$NETSNMPCONFIG --cflags`"
954                 CPPFLAGS="$CPPFLAGS `$NETSNMPCONFIG --cflags`"
955
956                 AC_CHECK_HEADERS(net-snmp/net-snmp-config.h net-snmp/library/default_store.h)
957                 if test "x$ac_cv_header_net_snmp_net_snmp_config_h" = "xyes" -a "x$ac_cv_header_net_snmp_library_default_store_h" = "xyes" ; then
958                         SNMP_LIBS=`$NETSNMPCONFIG --libs`
959                         if echo "$SNMP_LIBS" | grep crypto >/dev/null  && test "x$SSL_LIBS" = "x"; then
960                                 if test "x$want_netsnmp" = "xyes" ; then
961                                         AC_MSG_ERROR(Net-SNMP requires openssl but ssl not enabled)
962                                 else
963                                         AC_MSG_RESULT(Net-SNMP requires openssl but ssl not enabled - disabling Net-SNMP)
964                                 fi
965                                 CFLAGS="$ethereal_save_CFLAGS"
966                                 CPPFLAGS="$ethereal_save_CPPFLAGS"
967                                 SNMP_LIBS=
968                         else
969                                 AC_DEFINE(HAVE_NET_SNMP, 1, [Define to enable support for Net-SNMP])
970                                 have_net_snmp="yes"
971                         fi
972                 else
973                         if test "x$want_netsnmp" = "xyes" ; then
974                                 AC_MSG_ERROR(Net-SNMP not found)
975                         else
976                                 #
977                                 # Restore the versions of CFLAGS and
978                                 # CPPFLAGS before we added the output
979                                 # of '$NETSNMPCONFIG --cflags", as we
980                                 # didn't actually find Net-SNMP there.
981                                 #
982                                 CFLAGS="$ethereal_save_CFLAGS"
983                                 CPPFLAGS="$ethereal_save_CPPFLAGS"
984                         fi
985                 fi
986         fi      
987 ])
988
989 #
990 # AC_ETHEREAL_UCDSNMP_CHECK
991 #
992 AC_DEFUN([AC_ETHEREAL_UCDSNMP_CHECK],
993 [
994         if test "x$ucdsnmp_dir" != "x"
995         then
996                 #
997                 # The user specified a directory in which UCD SNMP resides,
998                 # so add the "include" subdirectory of that directory to
999                 # the include file search path and the "lib" subdirectory
1000                 # of that directory to the library search path.
1001                 #
1002                 # XXX - if there's also a libpcap in a directory that's
1003                 # already in CFLAGS, CPPFLAGS, or LDFLAGS, this won't
1004                 # make us find the version in the specified directory,
1005                 # as the compiler and/or linker will search that other
1006                 # directory before it searches the specified directory.
1007                 #
1008                 CFLAGS="$CFLAGS -I$ucdsnmp_dir/include"
1009                 CPPFLAGS="$CPPFLAGS -I$ucdsnmp_dir/include"
1010                 AC_ETHEREAL_ADD_DASH_L(LDFLAGS, $ucdsnmp_dir/lib)
1011         fi
1012
1013         #
1014         # Check for one of the UCD SNMP header files we include,
1015         # to see whether we have UCD SNMP installed.
1016         #
1017         AC_CHECK_HEADER(ucd-snmp/ucd-snmp-config.h,
1018         [
1019                 #
1020                 # UCD SNMP or Net-SNMP might require various helper
1021                 # libraries on various platforms, such as "-ldes425"
1022                 # in "/usr/kerberos/lib" on some versions of Red
1023                 # Hat Linux, or "-lkstat" on Solaris.
1024                 #
1025                 # It might also require "-lcrypto" on some platforms;
1026                 # if the user didn't specify --with-ssl, we check
1027                 # whether it would have made a difference and, if so,
1028                 # we tell the user that they needed to request it.
1029                 # (There are annoying licensing issues with it and
1030                 # GPL'ed code, so we don't include it by default.)
1031                 #
1032                 # XXX - autoconf really needs a way to test for
1033                 # a given routine in a given library *and* to test
1034                 # whether additional "-L"/"-R"/whatever flags are
1035                 # needed *before* the "-l" flag for the library
1036                 # and to test whether additional libraries are
1037                 # needed after the library *and* to cache all that
1038                 # information.
1039                 #
1040                 ethereal_save_LIBS="$LIBS"
1041                 found_sprint_realloc_objid=no
1042                 for extras in "" "-L/usr/kerberos/lib -ldes425" "-lkstat"
1043                 do
1044                         LIBS="-lsnmp $extras $SOCKET_LIBS $NSL_LIBS $SSL_LIBS"
1045                         if test -z "$extras"
1046                         then
1047                                 AC_MSG_CHECKING([whether UCD SNMP includes sprint_realloc_objid])
1048                         else
1049                                 AC_MSG_CHECKING([whether UCD SNMP includes sprint_realloc_objid (linking with $extras)])
1050                         fi
1051                         AC_TRY_LINK(
1052                             [
1053                             ],
1054                             [
1055                                 sprint_realloc_objid();
1056                             ],
1057                             [
1058                                 #
1059                                 # We found "sprint_realloc_objid()",
1060                                 # and required the libraries in
1061                                 # extras as well.
1062                                 #
1063                                 AC_MSG_RESULT(yes)
1064                                 SNMP_LIBS="-lsnmp $extras"; break;
1065                                 found_sprint_realloc_objid=yes
1066                                 break
1067                             ],
1068                             [
1069                                 #
1070                                 # The link failed.  If they didn't ask
1071                                 # for SSL, try linking with -lcrypto
1072                                 # as well, and if *that* succeeds,
1073                                 # tell them they'll need to specify
1074                                 # --want-ssl.
1075                                 #
1076                                 AC_MSG_RESULT(no)
1077                                 if test "x$want_ssl" = "xno"
1078                                 then
1079                                         LIBS="$LIBS -lcrypto"
1080                                         AC_TRY_LINK(
1081                                             [
1082                                             ],
1083                                             [
1084                                                 sprint_realloc_objid();
1085                                             ],
1086                                             [
1087                                                 #
1088                                                 # It worked with -lcrypto; tell
1089                                                 # them they'll need to specify
1090                                                 # --with-ssl.
1091                                                 #
1092                                                 AC_MSG_ERROR([UCD SNMP requires -lcrypto but --with-ssl not specified])
1093                                             ])
1094                                 fi
1095                             ])
1096                 done
1097                 LIBS="$ethereal_save_LIBS"
1098
1099                 #
1100                 # If we didn't find "sprint_realloc_objid()", fail.
1101                 # Either the user needs a newer version of UCD SNMP
1102                 # with "sprint_realloc_objid()", or they may need to
1103                 # specify "--with-ssl".
1104                 #
1105                 if test "$found_snmp_sprint_realloc_objid" = no; then
1106                     AC_MSG_ERROR([UCD SNMP header files found, but sprint_realloc_objid not found in SNMP library.])
1107                 fi
1108
1109                 #
1110                 # We found it, so we have UCD SNMP.
1111                 #
1112                 AC_DEFINE(HAVE_UCD_SNMP, 1, [Define to enable support for UCD-SNMP])
1113                 have_ucd_snmp="yes"
1114         ],[
1115                 #
1116                 # No, we don't have it.
1117                 # If the user explicitly asked for UCD SNMP, fail,
1118                 # otherwise just don't use the UCD SNMP library.
1119                 #
1120                 if test "x$want_ucdsnmp" = "xyes" ; then
1121                         AC_MSG_ERROR(Header file ucd-snmp/snmp.h not found.)
1122                 fi
1123         ])
1124 ])
1125
1126 #
1127 # AC_ETHEREAL_RPM_CHECK
1128 # Looks for the rpm program, and checks to see if we can redefine "_topdir".
1129 #
1130 AC_DEFUN([AC_ETHEREAL_RPM_CHECK],
1131 [
1132         AC_CHECK_PROG(ac_cv_ethereal_have_rpm, rpm, "yes", "no")
1133         if test "x$ac_cv_ethereal_have_rpm" = "xyes"; then
1134                 rpm --define '_topdir /tmp' > /dev/null 2>&1
1135                 AC_MSG_CHECKING(to see if we can redefine _topdir)
1136                 if test $? -eq 0 ; then
1137                         AC_MSG_RESULT(yes)
1138                         HAVE_RPM=yes
1139                 else
1140                         AC_MSG_RESULT(no.  You'll have to build packages manually.)
1141                         HAVE_RPM=no
1142                 fi
1143         fi
1144 ])
1145
1146 #
1147 # AC_ETHEREAL_GNU_SED_CHECK
1148 # Checks if GNU sed is the first sed in PATH.
1149 #
1150 AC_DEFUN([AC_ETHEREAL_GNU_SED_CHECK],
1151 [
1152         AC_MSG_CHECKING(for GNU sed as first sed in PATH)
1153         if  ( sh -c "sed --version" </dev/null 2> /dev/null | grep "GNU sed" 2>&1 > /dev/null ) ;  then
1154                 AC_MSG_RESULT(yes)
1155                 HAVE_GNU_SED=yes
1156         else
1157                 AC_MSG_RESULT(no)
1158                 HAVE_GNU_SED=no
1159         fi
1160 ])
1161
1162 #
1163 # AC_ETHEREAL_ADNS_CHECK
1164 #
1165 AC_DEFUN([AC_ETHEREAL_ADNS_CHECK],
1166 [
1167         want_adns=defaultyes
1168
1169         if test "x$want_adns" = "xdefaultyes"; then
1170                 want_adns=yes
1171                 withval=/usr/local
1172                 if test -d "$withval"; then
1173                         AC_ETHEREAL_ADD_DASH_L(LDFLAGS, ${withval}/lib)
1174                 fi
1175         fi
1176
1177         if test "x$want_adns" = "xyes"; then
1178                 AC_CHECK_LIB(adns, adns_init,
1179                   [
1180                     ADNS_LIBS=-ladns
1181                 AC_DEFINE(HAVE_GNU_ADNS, 1, [Define to use GNU ADNS library])
1182                 have_good_adns=yes
1183                   ],, $SOCKET_LIBS $NSL_LIBS
1184                 )
1185         else
1186                 AC_MSG_RESULT(not required)
1187         fi
1188 ])
1189
1190
1191 #
1192 # AC_ETHEREAL_KRB5_CHECK
1193 #
1194 AC_DEFUN([AC_ETHEREAL_KRB5_CHECK],
1195 [
1196         ethereal_save_CFLAGS="$CFLAGS"
1197         ethereal_save_CPPFLAGS="$CPPFLAGS"
1198         if test "x$krb5_dir" != "x"
1199         then
1200           #
1201           # The user specified a directory in which kerberos resides,
1202           # so add the "include" subdirectory of that directory to
1203           # the include file search path and the "lib" subdirectory
1204           # of that directory to the library search path.
1205           #
1206           # XXX - if there's also a kerberos in a directory that's
1207           # already in CFLAGS, CPPFLAGS, or LDFLAGS, this won't
1208           # make us find the version in the specified directory,
1209           # as the compiler and/or linker will search that other
1210           # directory before it searches the specified directory.
1211           #
1212           CFLAGS="$CFLAGS -I$krb5_dir/include"
1213           CPPFLAGS="$CPPFLAGS -I$krb5_dir/include"
1214           ac_heimdal_version=`grep heimdal $krb5_dir/include/krb5.h | head -n 1 | sed 's/^.*heimdal.*$/HEIMDAL/'`
1215           ac_mit_version=`grep 'Massachusetts Institute of Technology' $krb5_dir/include/krb5.h | head -n 1 | sed 's/^.*Massachusetts Institute of Technology.*$/MIT/'`
1216           ac_krb5_version="$ac_heimdal_version$ac_mit_version"
1217           if test "x$ac_krb5_version" = "xHEIMDAL"
1218               KRB5_LIBS="-L$krb5_dir/lib -lkrb5 -lasn1 $SSL_LIBS -lroken -lcrypt"
1219           then
1220               KRB5_LIBS="-L$krb5_dir/lib -lkrb5 -lk5crypto -lcom_err"
1221           fi
1222           if test "x$ac_krb5_version" = "xMIT"
1223           then
1224             AC_DEFINE(HAVE_MIT_KERBEROS, 1, [Define to use MIT kerberos])
1225           fi
1226         else
1227           AC_PATH_PROG(KRB5_CONFIG, krb5-config) 
1228           if test -x "$KRB5_CONFIG"
1229           then
1230             KRB5_FLAGS=`"$KRB5_CONFIG" --cflags`
1231             KRB5_LIBS=`"$KRB5_CONFIG" --libs`
1232             CFLAGS="$CFLAGS $KRB5_FLAGS"
1233             CPPFLAGS="$CPPFLAGS $KRB5_FLAGS"
1234             #
1235             # If -lcrypto is in KRB5_FLAGS, we require it to build
1236             # with Heimdal/MIT.  We don't want to built with it by
1237             # default, due to annoying license incompatibilities
1238             # between the OpenSSL license and the GPL, so:
1239             #
1240             #   if SSL_LIBS is set to a non-empty string, we
1241             #   remove -lcrypto from KRB5_LIBS and replace
1242             #   it with SSL_LIBS;
1243             #
1244             #   if SSL_LIBS is not set to a non-empty string
1245             #   we fail with an appropriate error message.
1246             #
1247             case "$KRB5_LIBS" in
1248             *-lcrypto*)
1249                 if test ! -z "$SSL_LIBS"
1250                 then
1251                     KRB5_LIBS=`echo $KRB5_LIBS | sed 's/-lcrypto//'`
1252                     KRB5_LIBS="$KRB5_LIBS $SSL_LIBS"
1253                 else
1254                     AC_MSG_ERROR([Kerberos library requires -lcrypto but --with-ssl not specified])
1255                 fi
1256                 ;;
1257             esac
1258             ac_krb5_version=`"$KRB5_CONFIG" --version | head -n 1 | sed -e 's/^.*heimdal.*$/HEIMDAL/' -e 's/^Kerberos .*$/MIT/'`
1259           fi
1260         fi
1261
1262         #
1263         # Make sure we have "krb5.h".  If we don't, it means we probably
1264         # don't have kerberos, so don't use it.
1265         #
1266         AC_CHECK_HEADER(krb5.h,,
1267           [
1268             if test "x$krb5_dir" != "x"
1269             then
1270               #
1271               # The user used "--with-krb5=" to specify a directory
1272               # containing kerberos, but we didn't find the header file
1273               # there; that either means they didn't specify the
1274               # right directory or are confused about whether kerberos
1275               # is, in fact, installed.  Report the error and give up.
1276               #
1277               AC_MSG_ERROR([kerberos header not found in directory specified in --with-krb5])
1278             else
1279               if test "x$want_krb5" = "xyes"
1280               then
1281                 #
1282                 # The user tried to force us to use the library, but we
1283                 # couldn't find the header file; report an error.
1284                 #
1285                 AC_MSG_ERROR(Header file krb5.h not found.)
1286               else
1287                 #
1288                 # We couldn't find the header file; don't use the
1289                 # library, as it's probably not present.
1290                 #
1291                 want_krb5=no
1292                 AC_MSG_RESULT(No Heimdal or MIT header found - disabling dissection for some kerberos data in packet decoding)
1293               fi
1294             fi
1295           ])
1296
1297         if test "x$want_krb5" != "xno"
1298         then
1299             #
1300             # Well, we at least have the krb5 header file.
1301             # Check whether this is Heimdal or MIT.
1302             #
1303             AC_MSG_CHECKING(whether the Kerberos library is Heimdal or MIT)
1304             if test "x$ac_krb5_version" = "xHEIMDAL" -o "x$ac_krb5_version" = "xMIT"
1305             then
1306                 #
1307                 # Yes.
1308                 # Check whether we have krb5_kt_resolve - and whether
1309                 # we need to link with -lresolv when linking with
1310                 # the Kerberos library.
1311                 #
1312                 AC_MSG_RESULT($ac_krb5_version)
1313                 ethereal_save_LIBS="$LIBS"
1314                 found_krb5_kt_resolve=no
1315                 for extras in "" "-lresolv"
1316                 do
1317                     LIBS="$KRB5_LIBS $extras"
1318                     if test -z "$extras"
1319                     then
1320                         AC_MSG_CHECKING([whether $ac_krb5_version includes krb5_kt_resolve])
1321                     else
1322                         AC_MSG_CHECKING([whether $ac_krb5_version includes krb5_kt_resolve (linking with $extras)])
1323                     fi
1324                     AC_TRY_LINK(
1325                         [
1326                         ],
1327                         [
1328                             krb5_kt_resolve();
1329                         ],
1330                         [
1331                             #
1332                             # We found "krb5_kt_resolve()", and required
1333                             # the libraries in extras as well.
1334                             #
1335                             AC_MSG_RESULT(yes)
1336                             KRB5_LIBS="$LIBS"
1337                             AC_DEFINE(HAVE_KERBEROS, 1, [Define to use kerberos])
1338                             if test "x$ac_krb5_version" = "xHEIMDAL"
1339                             then
1340                                 AC_DEFINE(HAVE_HEIMDAL_KERBEROS, 1, [Define to use heimdal kerberos])
1341                             elif test "x$ac_krb5_version" = "xMIT"
1342                             then
1343                                 AC_DEFINE(HAVE_MIT_KERBEROS, 1, [Define to use MIT kerberos])
1344                             fi
1345                             found_krb5_kt_resolve=yes
1346                             break
1347                         ],
1348                         [
1349                             AC_MSG_RESULT(no)
1350                         ])
1351                 done
1352                 if test "$found_krb5_kt_resolve" = no
1353                 then
1354                     #
1355                     # We didn't find "krb5_kt_resolve()" in the
1356                     # Kerberos library, even when we tried linking
1357                     # with -lresolv; we can't link with kerberos.
1358                     #
1359                     if test "x$want_krb5" = "xyes"
1360                     then
1361                         #
1362                         # The user tried to force us to use the library,
1363                         # but we can't do so; report an error.
1364                         #
1365                         AC_MSG_ERROR(Usable $ac_krb5_version not found)
1366                     else
1367                         #
1368                         # Restore the versions of CFLAGS and CPPFLAGS
1369                         # from before we added the flags for Kerberos.
1370                         #
1371                         AC_MSG_RESULT(Usable $ac_krb5_version not found - disabling dissection for some kerberos data in packet decoding)
1372                         CFLAGS="$ethereal_save_CFLAGS"
1373                         CPPFLAGS="$ethereal_save_CPPFLAGS"
1374                         KRB5_LIBS=""
1375                         want_krb5=no
1376                     fi
1377                 else
1378                     #
1379                     # We can link with Kerberos; see whether krb5.h
1380                     # defines KEYTYPE_ARCFOUR_56 (where "defines" means
1381                     # "as a #define or as an enum member).
1382                     #
1383                     AC_MSG_CHECKING([whether krb5.h defines KEYTYPE_ARCFOUR_56])
1384                     AC_COMPILE_IFELSE(
1385                       [
1386                         AC_LANG_SOURCE(
1387                           [[
1388                             #include <krb5.h>
1389                             #include <stdio.h>
1390
1391                             main()
1392                             {
1393                               printf("%u\n", KEYTYPE_ARCFOUR_56);
1394                             }
1395                           ]])
1396                       ],
1397                       [
1398                         AC_MSG_RESULT(yes)
1399                         AC_DEFINE(HAVE_KEYTYPE_ARCFOUR_56, 1, [Define if krb5.h defines KEYTYPE_ARCFOUR_56])
1400                       ],
1401                       [
1402                         AC_MSG_RESULT(no)
1403                       ])
1404                 fi
1405                 LIBS="$ethereal_save_LIBS"
1406             else
1407                 #
1408                 # It's not Heimdal or MIT.
1409                 #
1410                 AC_MSG_RESULT(no)
1411                 if test "x$want_krb5" = "xyes"
1412                 then
1413                     #
1414                     # The user tried to force us to use the library,
1415                     # but we can't do so; report an error.
1416                     #
1417                     AC_MSG_ERROR(Kerberos not found)
1418                 else
1419                     #
1420                     # Restore the versions of CFLAGS and CPPFLAGS
1421                     # from before we added the flags for Kerberos.
1422                     #
1423                     AC_MSG_RESULT(Kerberos not found - disabling dissection for some kerberos data in packet decoding)
1424                     CFLAGS="$ethereal_save_CFLAGS"
1425                     CPPFLAGS="$ethereal_save_CPPFLAGS"
1426                     KRB5_LIBS=""
1427                     want_krb5=no
1428                 fi
1429             fi
1430         else
1431             #
1432             # The user asked us not to use Kerberos, or they didn't
1433             # say whether they wanted us to use it but we found
1434             # that we couldn't.
1435             #
1436             # Restore the versions of CFLAGS and CPPFLAGS
1437             # from before we added the flags for Kerberos.
1438             #
1439             CFLAGS="$ethereal_save_CFLAGS"
1440             CPPFLAGS="$ethereal_save_CPPFLAGS"
1441             KRB5_LIBS=""
1442             want_krb5=no
1443         fi
1444         AC_SUBST(KRB5_LIBS)
1445 ])
1446
1447 dnl Autoconf macros for libgnutls
1448
1449 # Modified for LIBGNUTLS -- nmav
1450 # Configure paths for LIBGCRYPT
1451 # Shamelessly stolen from the one of XDELTA by Owen Taylor
1452 # Werner Koch   99-12-09
1453
1454 dnl AM_PATH_LIBGNUTLS([MINIMUM-VERSION, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND ]]])
1455 dnl Test for libgnutls, and define LIBGNUTLS_CFLAGS and LIBGNUTLS_LIBS
1456 dnl
1457 AC_DEFUN([AM_PATH_LIBGNUTLS],
1458 [dnl
1459 dnl Get the cflags and libraries from the libgnutls-config script
1460 dnl
1461 AC_ARG_WITH(libgnutls-prefix,
1462           [  --with-libgnutls-prefix=PFX   Prefix where libgnutls is installed (optional)],
1463           libgnutls_config_prefix="$withval", libgnutls_config_prefix="")
1464
1465   if test x$libgnutls_config_prefix != x ; then
1466      if test x${LIBGNUTLS_CONFIG+set} != xset ; then
1467         LIBGNUTLS_CONFIG=$libgnutls_config_prefix/bin/libgnutls-config
1468      fi
1469   fi
1470
1471   AC_PATH_PROG(LIBGNUTLS_CONFIG, libgnutls-config, no)
1472   min_libgnutls_version=ifelse([$1], ,0.1.0,$1)
1473   AC_MSG_CHECKING(for libgnutls - version >= $min_libgnutls_version)
1474   no_libgnutls=""
1475   if test "$LIBGNUTLS_CONFIG" = "no" ; then
1476     no_libgnutls=yes
1477   else
1478     LIBGNUTLS_CFLAGS=`$LIBGNUTLS_CONFIG $libgnutls_config_args --cflags`
1479     LIBGNUTLS_LIBS=`$LIBGNUTLS_CONFIG $libgnutls_config_args --libs`
1480     libgnutls_config_version=`$LIBGNUTLS_CONFIG $libgnutls_config_args --version`
1481
1482       ac_save_CFLAGS="$CFLAGS"
1483       ac_save_LIBS="$LIBS"
1484       CFLAGS="$CFLAGS $LIBGNUTLS_CFLAGS"
1485       LIBS="$LIBS $LIBGNUTLS_LIBS"
1486 dnl
1487 dnl Now check if the installed libgnutls is sufficiently new. Also sanity
1488 dnl checks the results of libgnutls-config to some extent
1489 dnl
1490       rm -f conf.libgnutlstest
1491       AC_TRY_RUN([
1492 #include <stdio.h>
1493 #include <stdlib.h>
1494 #include <string.h>
1495 #include <gnutls/gnutls.h>
1496
1497 int
1498 main ()
1499 {
1500     system ("touch conf.libgnutlstest");
1501
1502     if( strcmp( gnutls_check_version(NULL), "$libgnutls_config_version" ) )
1503     {
1504       printf("\n*** 'libgnutls-config --version' returned %s, but LIBGNUTLS (%s)\n",
1505              "$libgnutls_config_version", gnutls_check_version(NULL) );
1506       printf("*** was found! If libgnutls-config was correct, then it is best\n");
1507       printf("*** to remove the old version of LIBGNUTLS. You may also be able to fix the error\n");
1508       printf("*** by modifying your LD_LIBRARY_PATH enviroment variable, or by editing\n");
1509       printf("*** /etc/ld.so.conf. Make sure you have run ldconfig if that is\n");
1510       printf("*** required on your system.\n");
1511       printf("*** If libgnutls-config was wrong, set the environment variable LIBGNUTLS_CONFIG\n");
1512       printf("*** to point to the correct copy of libgnutls-config, and remove the file config.cache\n");
1513       printf("*** before re-running configure\n");
1514     }
1515     else if ( strcmp(gnutls_check_version(NULL), LIBGNUTLS_VERSION ) )
1516     {
1517       printf("\n*** LIBGNUTLS header file (version %s) does not match\n", LIBGNUTLS_VERSION);
1518       printf("*** library (version %s)\n", gnutls_check_version(NULL) );
1519     }
1520     else
1521     {
1522       if ( gnutls_check_version( "$min_libgnutls_version" ) )
1523       {
1524         return 0;
1525       }
1526      else
1527       {
1528         printf("no\n*** An old version of LIBGNUTLS (%s) was found.\n",
1529                 gnutls_check_version(NULL) );
1530         printf("*** You need a version of LIBGNUTLS newer than %s. The latest version of\n",
1531                "$min_libgnutls_version" );
1532         printf("*** LIBGNUTLS is always available from ftp://gnutls.hellug.gr/pub/gnutls.\n");
1533         printf("*** \n");
1534         printf("*** If you have already installed a sufficiently new version, this error\n");
1535         printf("*** probably means that the wrong copy of the libgnutls-config shell script is\n");
1536         printf("*** being found. The easiest way to fix this is to remove the old version\n");
1537         printf("*** of LIBGNUTLS, but you can also set the LIBGNUTLS_CONFIG environment to point to the\n");
1538         printf("*** correct copy of libgnutls-config. (In this case, you will have to\n");
1539         printf("*** modify your LD_LIBRARY_PATH enviroment variable, or edit /etc/ld.so.conf\n");
1540         printf("*** so that the correct libraries are found at run-time))\n");
1541       }
1542     }
1543   return 1;
1544 }
1545 ],, no_libgnutls=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"])
1546        CFLAGS="$ac_save_CFLAGS"
1547        LIBS="$ac_save_LIBS"
1548   fi
1549
1550   if test "x$no_libgnutls" = x ; then
1551      AC_MSG_RESULT(yes)
1552      ifelse([$2], , :, [$2])
1553   else
1554      if test -f conf.libgnutlstest ; then
1555         :
1556      else
1557         AC_MSG_RESULT(no)
1558      fi
1559      if test "$LIBGNUTLS_CONFIG" = "no" ; then
1560        echo "*** The libgnutls-config script installed by LIBGNUTLS could not be found"
1561        echo "*** If LIBGNUTLS was installed in PREFIX, make sure PREFIX/bin is in"
1562        echo "*** your path, or set the LIBGNUTLS_CONFIG environment variable to the"
1563        echo "*** full path to libgnutls-config."
1564      else
1565        if test -f conf.libgnutlstest ; then
1566         :
1567        else
1568           echo "*** Could not run libgnutls test program, checking why..."
1569           CFLAGS="$CFLAGS $LIBGNUTLS_CFLAGS"
1570           LIBS="$LIBS $LIBGNUTLS_LIBS"
1571           AC_TRY_LINK([
1572 #include <stdio.h>
1573 #include <stdlib.h>
1574 #include <string.h>
1575 #include <gnutls/gnutls.h>
1576 ],      [ return !!gnutls_check_version(NULL); ],
1577         [ echo "*** The test program compiled, but did not run. This usually means"
1578           echo "*** that the run-time linker is not finding LIBGNUTLS or finding the wrong"
1579           echo "*** version of LIBGNUTLS. If it is not finding LIBGNUTLS, you'll need to set your"
1580           echo "*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point"
1581           echo "*** to the installed location  Also, make sure you have run ldconfig if that"
1582           echo "*** is required on your system"
1583           echo "***"
1584           echo "*** If you have an old version installed, it is best to remove it, although"
1585           echo "*** you may also be able to get things to work by modifying LD_LIBRARY_PATH"
1586           echo "***" ],
1587         [ echo "*** The test program failed to compile or link. See the file config.log for the"
1588           echo "*** exact error that occured. This usually means LIBGNUTLS was incorrectly installed"
1589           echo "*** or that you have moved LIBGNUTLS since it was installed. In the latter case, you"
1590           echo "*** may want to edit the libgnutls-config script: $LIBGNUTLS_CONFIG" ])
1591           CFLAGS="$ac_save_CFLAGS"
1592           LIBS="$ac_save_LIBS"
1593        fi
1594      fi
1595      LIBGNUTLS_CFLAGS=""
1596      LIBGNUTLS_LIBS=""
1597      ifelse([$3], , :, [$3])
1598   fi
1599   rm -f conf.libgnutlstest
1600   AC_SUBST(LIBGNUTLS_CFLAGS)
1601   AC_SUBST(LIBGNUTLS_LIBS)
1602 ])