Don't reuse lua_dir in a for loop.
[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 Wireshark.
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_WIRESHARK_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_WIRESHARK_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_WIRESHARK_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_WIRESHARK_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_WIRESHARK_STRUCT_SA_LEN],
86 [AC_CACHE_CHECK([for sa_len in struct sockaddr], ac_cv_wireshark_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_wireshark_struct_sa_len=yes, ac_cv_wireshark_struct_sa_len=no)])
90 if test $ac_cv_wireshark_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 #
97 # AC_WIRESHARK_IPV6_STACK
98 #
99 # By Jun-ichiro "itojun" Hagino, <itojun@iijlab.net>
100 #
101 AC_DEFUN([AC_WIRESHARK_IPV6_STACK],
102 [
103         v6type=unknown
104         v6lib=none
105
106         AC_MSG_CHECKING([ipv6 stack type])
107         for i in v6d toshiba kame inria zeta linux linux-glibc solaris8; do
108                 case $i in
109                 v6d)
110                         AC_EGREP_CPP(yes, [
111 #include </usr/local/v6/include/sys/types.h>
112 #ifdef __V6D__
113 yes
114 #endif],
115                                 [v6type=$i; v6lib=v6;
116                                 v6libdir=/usr/local/v6/lib;
117                                 CFLAGS="-I/usr/local/v6/include $CFLAGS"])
118                         ;;
119                 toshiba)
120                         AC_EGREP_CPP(yes, [
121 #include <sys/param.h>
122 #ifdef _TOSHIBA_INET6
123 yes
124 #endif],
125                                 [v6type=$i; v6lib=inet6;
126                                 v6libdir=/usr/local/v6/lib;
127                                 CFLAGS="-DINET6 $CFLAGS"])
128                         ;;
129                 kame)
130                         AC_EGREP_CPP(yes, [
131 #include <netinet/in.h>
132 #ifdef __KAME__
133 yes
134 #endif],
135                                 [v6type=$i; v6lib=inet6;
136                                 v6libdir=/usr/local/v6/lib;
137                                 CFLAGS="-DINET6 $CFLAGS"])
138                         ;;
139                 inria)
140                         AC_EGREP_CPP(yes, [
141 #include <netinet/in.h>
142 #ifdef IPV6_INRIA_VERSION
143 yes
144 #endif],
145                                 [v6type=$i; CFLAGS="-DINET6 $CFLAGS"])
146                         ;;
147                 zeta)
148                         AC_EGREP_CPP(yes, [
149 #include <sys/param.h>
150 #ifdef _ZETA_MINAMI_INET6
151 yes
152 #endif],
153                                 [v6type=$i; v6lib=inet6;
154                                 v6libdir=/usr/local/v6/lib;
155                                 CFLAGS="-DINET6 $CFLAGS"])
156                         ;;
157                 linux)
158                         if test -d /usr/inet6; then
159                                 v6type=$i
160                                 v6lib=inet6
161                                 v6libdir=/usr/inet6
162                                 CFLAGS="-DINET6 $CFLAGS"
163                         fi
164                         ;;
165                 linux-glibc)
166                         AC_EGREP_CPP(yes, [
167 #include <features.h>
168 #if defined(__GLIBC__) && defined(__GLIBC_MINOR__)
169 #if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 1) || __GLIBC__ > 2
170 yes
171 #endif
172 #endif],
173                         [v6type=$i; v6lib=inet6; CFLAGS="-DINET6 $CFLAGS"])
174                         ;;
175                 solaris8)
176                         if test "`uname -s`" = "SunOS" && test "`uname -r`" = "5.8"; then
177                                 v6type=$i
178                                 v6lib=inet6
179                                 [CFLAGS="-DINET6 -DSOLARIS8_INET6 $CFLAGS"]
180                         fi
181                         ;;
182                 esac
183                 if test "$v6type" != "unknown"; then
184                         break
185                 fi
186         done
187
188         if test "$v6lib" != "none"; then
189                 for dir in $v6libdir /usr/local/v6/lib /usr/local/lib; do
190                         if test -d $dir -a -f $dir/lib$v6lib.a; then
191                                 LIBS="-L$dir $LIBS -l$v6lib"
192                                 break
193                         fi
194                 done
195                 enable_ipv6="yes"
196         else
197                 enable_ipv6="no"
198         fi
199         AC_MSG_RESULT(["$v6type, $v6lib"])
200 ])
201
202 #
203 # AC_WIRESHARK_GETHOSTBY_LIB_CHECK
204 #
205 # Checks whether we need "-lnsl" to get "gethostby*()", which we use
206 # in "resolv.c".
207 #
208 # Adapted from stuff in the AC_PATH_XTRA macro in "acspecific.m4" in
209 # GNU Autoconf 2.13; the comment came from there.
210 # Done by Guy Harris <guy@alum.mit.edu> on 2000-01-14.
211 #
212 AC_DEFUN([AC_WIRESHARK_GETHOSTBY_LIB_CHECK],
213 [
214     # msh@cis.ufl.edu says -lnsl (and -lsocket) are needed for his 386/AT,
215     # to get the SysV transport functions.
216     # chad@anasazi.com says the Pyramid MIS-ES running DC/OSx (SVR4)
217     # needs -lnsl.
218     # The nsl library prevents programs from opening the X display
219     # on Irix 5.2, according to dickey@clark.net.
220     AC_CHECK_FUNC(gethostbyname, ,
221         AC_CHECK_LIB(nsl, gethostbyname, NSL_LIBS="-lnsl"))
222     AC_SUBST(NSL_LIBS)
223 ])
224
225 #
226 # AC_WIRESHARK_SOCKET_LIB_CHECK
227 #
228 # Checks whether we need "-lsocket" to get "socket()", which is used
229 # by libpcap on some platforms - and, in effect, "gethostby*()" on
230 # most if not all platforms (so that it can use NIS or DNS or...
231 # to look up host names).
232 #
233 # Adapted from stuff in the AC_PATH_XTRA macro in "acspecific.m4" in
234 # GNU Autoconf 2.13; the comment came from there.
235 # Done by Guy Harris <guy@alum.mit.edu> on 2000-01-14.
236 #
237 # We use "connect" because that's what AC_PATH_XTRA did.
238 #
239 AC_DEFUN([AC_WIRESHARK_SOCKET_LIB_CHECK],
240 [
241     # lieder@skyler.mavd.honeywell.com says without -lsocket,
242     # socket/setsockopt and other routines are undefined under SCO ODT
243     # 2.0.  But -lsocket is broken on IRIX 5.2 (and is not necessary
244     # on later versions), says simon@lia.di.epfl.ch: it contains
245     # gethostby* variants that don't use the nameserver (or something).
246     # -lsocket must be given before -lnsl if both are needed.
247     # We assume that if connect needs -lnsl, so does gethostbyname.
248     AC_CHECK_FUNC(connect, ,
249       AC_CHECK_LIB(socket, connect, SOCKET_LIBS="-lsocket",
250                 AC_MSG_ERROR(Function 'socket' not found.), $NSL_LIBS))
251     AC_SUBST(SOCKET_LIBS)
252 ])
253
254 #
255 # AC_WIRESHARK_BREAKLOOP_TRY_LINK
256 #
257 AC_DEFUN([AC_WIRESHARK_PCAP_BREAKLOOP_TRY_LINK],
258 [
259   AC_LINK_IFELSE(
260   [
261       AC_LANG_SOURCE(
262       [[
263 #       include <pcap.h>
264         int main(void)
265         {
266           pcap_t  *pct = NULL;
267           pcap_breakloop(pct);
268           return 0;
269         }
270       ]])
271   ],
272   [
273     ws_breakloop_compiled=yes
274   ],
275   [
276     ws_breakloop_compiled=no
277   ])
278 ])
279
280
281
282 #
283 # AC_WIRESHARK_PCAP_CHECK
284 #
285 AC_DEFUN([AC_WIRESHARK_PCAP_CHECK],
286 [
287         if test -z "$pcap_dir"
288         then
289           # Pcap header checks
290           # XXX need to set a var AC_CHECK_HEADER(pcap.h,,)
291
292           #
293           # The user didn't specify a directory in which libpcap resides;
294           # we assume that the current library search path will work,
295           # but we may have to look for the header in a "pcap"
296           # subdirectory of "/usr/include" or "/usr/local/include",
297           # as some systems apparently put "pcap.h" in a "pcap"
298           # subdirectory, and we also check "$prefix/include" - and
299           # "$prefix/include/pcap", in case $prefix is set to
300           # "/usr/include" or "/usr/local/include".
301           #
302           # XXX - should we just add "$prefix/include" to the include
303           # search path and "$prefix/lib" to the library search path?
304           #
305           AC_MSG_CHECKING(for extraneous pcap header directories)
306           found_pcap_dir=""
307           pcap_dir_list="/usr/include/pcap $prefix/include/pcap $prefix/include"
308           if test "x$ac_cv_enable_usr_local" = "xyes" ; then
309             pcap_dir_list="$pcap_dir_list /usr/local/include/pcap"
310           fi
311           for pcap_dir in $pcap_dir_list
312           do
313             if test -d $pcap_dir ; then
314                 if test x$pcap_dir != x/usr/include -a x$pcap_dir != x/usr/local/include ; then
315                     CFLAGS="$CFLAGS -I$pcap_dir"
316                     CPPFLAGS="$CPPFLAGS -I$pcap_dir"
317                 fi
318                 found_pcap_dir=" $found_pcap_dir -I$pcap_dir"
319                 break
320             fi
321           done
322
323           if test "$found_pcap_dir" != "" ; then
324             AC_MSG_RESULT(found --$found_pcap_dir added to CFLAGS)
325           else
326             AC_MSG_RESULT(not found)
327           fi
328         else
329           #
330           # The user specified a directory in which libpcap resides,
331           # so add the "include" subdirectory of that directory to
332           # the include file search path and the "lib" subdirectory
333           # of that directory to the library search path.
334           #
335           # XXX - if there's also a libpcap in a directory that's
336           # already in CFLAGS, CPPFLAGS, or LDFLAGS, this won't
337           # make us find the version in the specified directory,
338           # as the compiler and/or linker will search that other
339           # directory before it searches the specified directory.
340           #
341           CFLAGS="$CFLAGS -I$pcap_dir/include"
342           CPPFLAGS="$CPPFLAGS -I$pcap_dir/include"
343           AC_WIRESHARK_ADD_DASH_L(LDFLAGS, $pcap_dir/lib)
344         fi
345
346         # Pcap header check
347         AC_CHECK_HEADER(pcap.h,,
348             AC_MSG_ERROR([[Header file pcap.h not found; if you installed libpcap
349 from source, did you also do \"make install-incl\", and if you installed a
350 binary package of libpcap, is there also a developer's package of libpcap,
351 and did you also install that package?]]))
352
353         #
354         # Check to see if we find "pcap_open_live" in "-lpcap".
355         # Also check for various additional libraries that libpcap might
356         # require.
357         #
358         AC_CHECK_LIB(pcap, pcap_open_live,
359           [
360             PCAP_LIBS=-lpcap
361             AC_DEFINE(HAVE_LIBPCAP, 1, [Define to use libpcap library])
362           ], [
363             ac_wireshark_extras_found=no
364             ac_save_LIBS="$LIBS"
365             for extras in "-lcfg -lodm" "-lpfring"
366             do
367                 AC_MSG_CHECKING([for pcap_open_live in -lpcap with $extras])
368                 LIBS="-lpcap $extras"
369                 #
370                 # XXX - can't we use AC_CHECK_LIB here?
371                 #
372                 AC_TRY_LINK(
373                     [
374 #       include <pcap.h>
375                     ],
376                     [
377         pcap_open_live(NULL, 0, 0, 0, NULL);
378                     ],
379                     [
380                         ac_wireshark_extras_found=yes
381                         AC_MSG_RESULT([yes])
382                         PCAP_LIBS="-lpcap $extras"
383                         AC_DEFINE(HAVE_LIBPCAP, 1, [Define to use libpcap library])
384                     ],
385                     [
386                         AC_MSG_RESULT([no])
387                     ])
388                 if test x$ac_wireshark_extras_found = xyes
389                 then
390                     break
391                 fi
392             done
393             if test x$ac_wireshark_extras_found = xno
394             then
395                 AC_MSG_ERROR([Can't link with library libpcap.])
396             fi
397             LIBS=$ac_save_LIBS
398           ], $SOCKET_LIBS $NSL_LIBS)
399         AC_SUBST(PCAP_LIBS)
400
401         #
402         # Check whether various variables and functions are defined by
403         # libpcap.
404         #
405         ac_save_LIBS="$LIBS"
406         AC_MSG_CHECKING(whether pcap_version is defined by libpcap)
407         LIBS="$PCAP_LIBS $SOCKET_LIBS $NSL_LIBS $LIBS"
408         AC_TRY_LINK(
409            [
410 #       include <stdio.h>
411         extern char *pcap_version;
412            ],
413            [
414         printf ("%s\n", pcap_version);
415            ],
416            ac_cv_pcap_version_defined=yes,
417            ac_cv_pcap_version_defined=no,
418            [echo $ac_n "cross compiling; assumed OK... $ac_c"])
419         if test "$ac_cv_pcap_version_defined" = yes ; then
420                 AC_MSG_RESULT(yes)
421                 AC_DEFINE(HAVE_PCAP_VERSION, 1, [Define if libpcap version is known])
422         else
423                 AC_MSG_RESULT(no)
424         fi
425         AC_CHECK_FUNCS(pcap_open_dead pcap_freecode)
426         #
427         # pcap_breakloop may be present in the library but not declared
428         # in the pcap.h header file.  If it's not declared in the header
429         # file, attempts to use it will get warnings, and, if we're
430         # building with warnings treated as errors, that warning will
431         # cause compilation to fail.
432         #
433         # We are therefore first testing whether the function is present
434         # and then, if we're compiling with warnings as errors, testing
435         # whether it is usable.  It is usable if it compiles without
436         # a -Wimplicit warning (the "compile with warnings as errors"
437         # option requires GCC). If it is not usable, we fail and tell
438         # the user that the pcap.h header needs to be updated.
439         #
440         # Ceteris paribus, this should only happen with Mac OS X 10.3[.x] which
441         # can have an up-to-date pcap library without the corresponding pcap
442         # header.
443         #
444         # However, it might also happen on some others OSes with some erroneous
445         # system manipulations where multiple versions of libcap might co-exist
446         # e.g. hand made symbolic link from libpcap.so -> libpcap.so.0.8 but
447         # having the pcap header version 0.7.
448         #
449         AC_MSG_CHECKING([whether pcap_breakloop is present])
450         ac_CFLAGS_saved="$CFLAGS"
451         AC_WIRESHARK_PCAP_BREAKLOOP_TRY_LINK
452         if test "x$ws_breakloop_compiled" = "xyes"; then
453           AC_MSG_RESULT(yes)
454           AC_DEFINE(HAVE_PCAP_BREAKLOOP, 1, [Define if pcap_breakloop is known])
455           if test "x$with_warnings_as_errors" = "xyes"; then
456             AC_MSG_CHECKING([whether pcap_breakloop is usable])
457             CFLAGS="$CFLAGS -Werror -Wimplicit"
458             AC_WIRESHARK_PCAP_BREAKLOOP_TRY_LINK
459             if test "x$ws_breakloop_compiled" = "xyes"; then
460               AC_MSG_RESULT(yes)
461             else
462               AC_MSG_RESULT(no)
463               AC_MSG_ERROR(
464 [Your pcap library is more recent than your pcap header.
465 As you are building with compiler warnings treated as errors, Wireshark
466 won't be able to use functions not declared in that header.
467 If you wish to build with compiler warnings treated as errors, You should
468 install a newer version of the header file.])
469             fi
470             CFLAGS="$ac_CFLAGS_saved"
471           fi
472         else
473           AC_MSG_RESULT(no)
474         fi
475
476         #
477         # Later versions of Mac OS X 10.3[.x] ship a pcap.h that
478         # doesn't define pcap_if_t but ship an 0.8[.x] libpcap,
479         # so the library has "pcap_findalldevs()", but pcap.h
480         # doesn't define "pcap_if_t" so you can't actually *use*
481         # "pcap_findalldevs()".
482         #
483         # That even appears to be true of systems shipped with
484         # 10.3.4, so it doesn't appear only to be a case of
485         # Software Update not updating header files.
486         #
487         # (You can work around this by installing the 0.8 header
488         # files.)
489         #
490         AC_CACHE_CHECK([whether pcap_findalldevs is present and usable],
491           [ac_cv_func_pcap_findalldevs],
492           [
493             AC_LINK_IFELSE(
494               [
495                 AC_LANG_SOURCE(
496                   [[
497                     #include <pcap.h>
498                     main()
499                     {
500                       pcap_if_t *devpointer;
501                       char errbuf[1];
502
503                       pcap_findalldevs(&devpointer, errbuf);
504                     }
505                   ]])
506               ],
507               [
508                 ac_cv_func_pcap_findalldevs=yes
509               ],
510               [
511                 ac_cv_func_pcap_findalldevs=no
512               ])
513           ])
514         #
515         # Don't check for other new routines that showed up after
516         # "pcap_findalldevs()" if we don't have a usable
517         # "pcap_findalldevs()", so we don't end up using them if the
518         # "pcap.h" is crufty and old and doesn't declare them.
519         #
520         if test $ac_cv_func_pcap_findalldevs = "yes" ; then
521           AC_DEFINE(HAVE_PCAP_FINDALLDEVS, 1,
522            [Define to 1 if you have the `pcap_findalldevs' function and a pcap.h that declares pcap_if_t.])
523           AC_CHECK_FUNCS(pcap_datalink_val_to_name pcap_datalink_name_to_val)
524           AC_CHECK_FUNCS(pcap_datalink_val_to_description)
525           AC_CHECK_FUNCS(pcap_list_datalinks pcap_set_datalink pcap_lib_version)
526           AC_CHECK_FUNCS(pcap_get_selectable_fd pcap_free_datalinks)
527         fi
528         LIBS="$ac_save_LIBS"
529 ])
530
531 AC_DEFUN([AC_WIRESHARK_PCAP_REMOTE_CHECK],
532 [
533     ac_save_LIBS="$LIBS"
534     LIBS="$PCAP_LIBS $SOCKET_LIBS $NSL_LIBS $LIBS"
535     AC_DEFINE(HAVE_REMOTE, 1, [Define to 1 to enable remote
536               capturing feature in WinPcap library])
537     AC_CHECK_FUNCS(pcap_open pcap_findalldevs_ex pcap_createsrcstr)
538     if test $ac_cv_func_pcap_open = "yes" -a \
539             $ac_cv_func_pcap_findalldevs_ex = "yes" -a \
540             $ac_cv_func_pcap_createsrcstr = "yes" ; then
541         AC_DEFINE(HAVE_PCAP_REMOTE, 1,
542             [Define to 1 if you have WinPcap remote capturing support and prefer to use these new API features.])
543     fi
544     AC_CHECK_FUNCS(pcap_setsampling)
545     LIBS="$ac_save_LIBS"
546 ])
547
548 #
549 # AC_WIRESHARK_ZLIB_CHECK
550 #
551 AC_DEFUN([AC_WIRESHARK_ZLIB_CHECK],
552 [
553         if test "x$zlib_dir" != "x"
554         then
555           #
556           # The user specified a directory in which zlib resides,
557           # so add the "include" subdirectory of that directory to
558           # the include file search path and the "lib" subdirectory
559           # of that directory to the library search path.
560           #
561           # XXX - if there's also a zlib in a directory that's
562           # already in CFLAGS, CPPFLAGS, or LDFLAGS, this won't
563           # make us find the version in the specified directory,
564           # as the compiler and/or linker will search that other
565           # directory before it searches the specified directory.
566           #
567           wireshark_save_CFLAGS="$CFLAGS"
568           CFLAGS="$CFLAGS -I$zlib_dir/include"
569           wireshark_save_CPPFLAGS="$CPPFLAGS"
570           CPPFLAGS="$CPPFLAGS -I$zlib_dir/include"
571           wireshark_save_LIBS="$LIBS"
572           AC_WIRESHARK_ADD_DASH_L(LIBS, $zlib_dir/lib)
573         fi
574
575         #
576         # Make sure we have "zlib.h".  If we don't, it means we probably
577         # don't have zlib, so don't use it.
578         #
579         AC_CHECK_HEADER(zlib.h,,
580           [
581             if test "x$zlib_dir" != "x"
582             then
583               #
584               # The user used "--with-zlib=" to specify a directory
585               # containing zlib, but we didn't find the header file
586               # there; that either means they didn't specify the
587               # right directory or are confused about whether zlib
588               # is, in fact, installed.  Report the error and give up.
589               #
590               AC_MSG_ERROR([zlib header not found in directory specified in --with-zlib])
591             else
592               if test "x$want_zlib" = "xyes"
593               then
594                 #
595                 # The user tried to force us to use the library, but we
596                 # couldn't find the header file; report an error.
597                 #
598                 AC_MSG_ERROR(Header file zlib.h not found.)
599               else
600                 #
601                 # We couldn't find the header file; don't use the
602                 # library, as it's probably not present.
603                 #
604                 want_zlib=no
605               fi
606             fi
607           ])
608
609         if test "x$want_zlib" != "xno"
610         then
611                 #
612                 # Well, we at least have the zlib header file.
613                 #
614                 # Check for "gzgets()" in zlib, because we need it, but
615                 # some older versions of zlib don't have it.  It appears
616                 # from the zlib ChangeLog that any released version of zlib
617                 # with "gzgets()" should have the other routines we
618                 # depend on, such as "gzseek()", "gztell()", and "zError()".
619                 #
620                 # Another reason why we require "gzgets()" is that
621                 # some versions of zlib that didn't have it, such
622                 # as 1.0.8, had a bug in "gzseek()" that meant that it
623                 # doesn't work correctly on uncompressed files; this
624                 # means we cannot use version 1.0.8.  (Unfortunately,
625                 # that's the version that comes with recent X11 source,
626                 # and many people who install XFree86 on their Slackware
627                 # boxes don't realize that they should configure it to
628                 # use the native zlib rather than building and installing
629                 # the crappy old version that comes with XFree86.)
630                 #
631                 # I.e., we can't just avoid using "gzgets()", as
632                 # versions of zlib without "gzgets()" are likely to have
633                 # a broken "gzseek()".
634                 #
635                 AC_CHECK_LIB(z, gzgets,
636                 [
637                         if test "x$zlib_dir" != "x"
638                         then
639                                 #
640                                 # Put the "-I" and "-L" flags for zlib at
641                                 # the beginning of CFLAGS, CPPFLAGS, and
642                                 # LIBS.
643                                 #
644                                 LIBS=""
645                                 AC_WIRESHARK_ADD_DASH_L(LIBS, $zlib_dir/lib)
646                                 LIBS="$LIBS -lz $wireshark_save_LIBS"
647                         else
648                                 LIBS="-lz $LIBS"
649                         fi
650                         AC_DEFINE(HAVE_LIBZ, 1, [Define to use libz library])
651                 ],[
652                         if test "x$zlib_dir" != "x"
653                         then
654                                 #
655                                 # Restore the versions of CFLAGS, CPPFLAGS,
656                                 # and LIBS before we added the "-with-zlib="
657                                 # directory, as we didn't actually find
658                                 # zlib there, or didn't find a zlib that
659                                 # contains gzgets there.
660                                 #
661                                 CFLAGS="$wireshark_save_CFLAGS"
662                                 CPPFLAGS="$wireshark_save_CPPFLAGS"
663                                 LIBS="$wireshark_save_LIBS"
664                         fi
665                         want_zlib=no
666                 ])
667         fi
668
669         if test "x$want_zlib" != "xno"
670         then
671                 #
672                 # Well, we at least have the zlib header file and a zlib
673                 # with "gzgets()".
674                 #
675                 # Now check for "gzgets()" in zlib when linking with the
676                 # linker flags for GTK+ applications; people often grab
677                 # XFree86 source and build and install it on their systems,
678                 # and they appear sometimes to misconfigure XFree86 so that,
679                 # even on systems with zlib, it assumes there is no zlib,
680                 # so the XFree86 build process builds and installs its
681                 # own zlib in the X11 library directory.
682                 #
683                 # The XFree86 zlib is an older version that lacks
684                 # "gzgets()", and that's the zlib with which Wireshark
685                 # gets linked, so the build of Wireshark fails.
686                 #
687                 ac_save_CFLAGS="$CFLAGS"
688                 ac_save_LIBS="$LIBS"
689                 CFLAGS="$CFLAGS $GTK_CFLAGS"
690                 LIBS="$GTK_LIBS -lz $LIBS"
691                 AC_MSG_CHECKING([for gzgets missing when linking with X11])
692                 AC_TRY_LINK_FUNC(gzgets, AC_MSG_RESULT(no),
693                   [
694                     AC_MSG_RESULT(yes)
695                     AC_MSG_ERROR(old zlib found when linking with X11 - get rid of old zlib.)
696                   ])
697                 CFLAGS="$ac_save_CFLAGS"
698                 LIBS="$ac_save_LIBS"
699         fi
700 ])
701
702 #
703 # AC_WIRESHARK_LIBPCRE_CHECK
704 #
705 AC_DEFUN([AC_WIRESHARK_LIBPCRE_CHECK],
706 [
707         if test "x$pcre_dir" != "x"
708         then
709           #
710           # The user specified a directory in which libpcre resides,
711           # so add the "include" subdirectory of that directory to
712           # the include file search path and the "lib" subdirectory
713           # of that directory to the library search path.
714           #
715           # XXX - if there's also a libpcre in a directory that's
716           # already in CFLAGS, CPPFLAGS, or LDFLAGS, this won't
717           # make us find the version in the specified directory,
718           # as the compiler and/or linker will search that other
719           # directory before it searches the specified directory.
720           #
721           wireshark_save_CFLAGS="$CFLAGS"
722           CFLAGS="$CFLAGS -I$pcre_dir/include"
723           wireshark_save_CPPFLAGS="$CPPFLAGS"
724           CPPFLAGS="$CPPFLAGS -I$pcre_dir/include"
725           wireshark_save_LIBS="$LIBS"
726           LIBS="$LIBS -lpcre"
727           wireshark_save_LDFLAGS="$LDFLAGS"
728           LDFLAGS="$LDFLAGS -L$pcre_dir/lib"
729         fi
730
731         #
732         # Make sure we have "pcre.h".  If we don't, it means we probably
733         # don't have libpcre, so don't use it.
734         #
735         AC_CHECK_HEADER(pcre.h,,
736           [
737             if test "x$pcre_dir" != "x"
738             then
739               #
740               # The user used "--with-pcre=" to specify a directory
741               # containing libpcre, but we didn't find the header file
742               # there; that either means they didn't specify the
743               # right directory or are confused about whether libpcre
744               # is, in fact, installed.  Report the error and give up.
745               #
746               AC_MSG_ERROR([libpcre header not found in directory specified in --with-pcre])
747             else
748               if test "x$want_pcre" = "xyes"
749               then
750                 #
751                 # The user tried to force us to use the library, but we
752                 # couldn't find the header file; report an error.
753                 #
754                 AC_MSG_ERROR(Header file pcre.h not found.)
755               else
756                 #
757                 # We couldn't find the header file; don't use the
758                 # library, as it's probably not present.
759                 #
760                 want_pcre=no
761               fi
762             fi
763           ])
764
765         if test "x$want_pcre" != "xno"
766         then
767                 #
768                 # Well, we at least have the pcre header file.
769                 #
770                 # We're only using standard functions from libpcre,
771                 # so we don't need to perform extra checks.
772                 #
773                 AC_CHECK_LIB(pcre, pcre_compile,
774                 [
775                         if test "x$pcre_dir" != "x"
776                         then
777                                 #
778                                 # Put the "-I" and "-L" flags for pcre at
779                                 # the beginning of CFLAGS, CPPFLAGS,
780                                 # LDFLAGS, and LIBS.
781                                 #
782                                 PCRE_LIBS="-L$pcre_dir/lib -lpcre $wireshark_save_LIBS"
783                         else
784                                 PCRE_LIBS="-lpcre"
785                         fi
786                         AC_DEFINE(HAVE_LIBPCRE, 1, [Define to use libpcre library])
787                 ],[
788                         if test "x$pcre_dir" != "x"
789                         then
790                                 #
791                                 # Restore the versions of CFLAGS, CPPFLAGS,
792                                 # LDFLAGS, and LIBS before we added the
793                                 # "--with-pcre=" directory, as we didn't
794                                 # actually find pcre there.
795                                 #
796                                 CFLAGS="$wireshark_save_CFLAGS"
797                                 CPPFLAGS="$wireshark_save_CPPFLAGS"
798                                 LDFLAGS="$wireshark_save_LDFLAGS"
799                                 LIBS="$wireshark_save_LIBS"
800                                 PCRE_LIBS=""
801                         fi
802                         want_pcre=no
803                 ])
804                 AC_SUBST(PCRE_LIBS)
805         fi
806 ])
807
808 #
809 # AC_WIRESHARK_LIBLUA_CHECK
810 #
811 AC_DEFUN([AC_WIRESHARK_LIBLUA_CHECK],[
812
813         if test "x$lua_dir" != "x"
814         then
815                 #
816                 # The user specified a directory in which liblua resides,
817                 # so add the "include" subdirectory of that directory to
818                 # the include file search path and the "lib" subdirectory
819                 # of that directory to the library search path.
820                 #
821                 # XXX - if there's also a liblua in a directory that's
822                 # already in CFLAGS, CPPFLAGS, or LDFLAGS, this won't
823                 # make us find the version in the specified directory,
824                 # as the compiler and/or linker will search that other
825                 # directory before it searches the specified directory.
826                 #
827                 wireshark_save_CFLAGS="$CFLAGS"
828                 CFLAGS="$CFLAGS -I$lua_dir/include"
829                 wireshark_save_CPPFLAGS="$CPPFLAGS"
830                 CPPFLAGS="$CPPFLAGS -I$lua_dir/include"
831                 wireshark_save_LIBS="$LIBS"
832                 LIBS="$LIBS -L$lua_dir/lib -llua -lm"
833                 wireshark_save_LDFLAGS="$LDFLAGS"
834                 LDFLAGS="$LDFLAGS -L$lua_dir/lib"
835         else
836                 #
837                 # The user specified no directory in which liblua resides,
838                 # so just add "-llua -lliblua" to the used libs.
839                 #
840                 wireshark_save_CFLAGS="$CFLAGS"
841                 wireshark_save_CPPFLAGS="$CPPFLAGS"
842                 wireshark_save_LDFLAGS="$LDFLAGS"
843                 wireshark_save_LIBS="$LIBS"
844                 LIBS="$LIBS -llua -lm"
845         fi
846
847         #
848         # Make sure we have "lua.h", "lualib.h" and "lauxlib.h".  If we don't, it means we probably
849         # don't have liblua, so don't use it.
850         #
851         AC_CHECK_HEADERS(lua.h lualib.h lauxlib.h,,
852         [
853                 AC_CHECK_HEADERS(lua5.1/lua.h lua5.1/lualib.h lua5.1/lauxlib.h,
854                 [
855                         if test "x$lua_dir" != "x"
856                         then
857                                 LUA_INCLUDES="-I$lua_dir/include/lua5.1"
858                         else
859                                 #
860                                 # The user didn't specify a directory in which liblua resides;
861                                 # we must look for the headers in a "lua5.1" subdirectory of
862                                 # "/usr/include", "/usr/local/include", or "$prefix/include"
863                                 # as some systems apparently put the headers in a "lua5.1"
864                                 # subdirectory.
865                                 AC_MSG_CHECKING(for extraneous lua header directories)
866                                 found_lua_dir=""
867                                 lua_dir_list="/usr/include/lua5.1 $prefix/include/lua5.1"
868                                 if test "x$ac_cv_enable_usr_local" = "xyes"
869                                 then
870                                         lua_dir_list="$lua_dir_list /usr/local/include/lua5.1"
871                                 fi
872                                 for lua_dir_ent in $lua_dir_list
873                                 do
874                                         if test -d $lua_dir_ent
875                                         then
876                                                 LUA_INCLUDES="-I$lua_dir_ent"
877                                                 found_lua_dir="$lua_dir_ent"
878                                                 break
879                                         fi
880                                 done
881
882                                 if test "x$found_lua_dir" != "x"
883                                 then
884                                         AC_MSG_RESULT(found -- $found_lua_dir)
885                                 else
886                                         AC_MSG_RESULT(not found)
887                                         #
888                                         # Restore the versions of CFLAGS, CPPFLAGS,
889                                         # LDFLAGS, and LIBS before we added the
890                                         # "--with-lua=" directory, as we didn't
891                                         # actually find lua there.
892                                         #
893                                         CFLAGS="$wireshark_save_CFLAGS"
894                                         CPPFLAGS="$wireshark_save_CPPFLAGS"
895                                         LDFLAGS="$wireshark_save_LDFLAGS"
896                                         LIBS="$wireshark_save_LIBS"
897                                         LUA_LIBS=""
898                                         if test "x$want_lua" = "xyes"
899                                         then
900                                                 # we found lua5.1/lua.h, but we don't know which include dir contains it
901                                                 AC_MSG_ERROR(Header file lua.h was found as lua5.1/lua.h but we can't locate the include directory. Please set the DIR for the --with-lua configure parameter.)
902                                         else
903                                                 #
904                                                 # We couldn't find the header file; don't use the
905                                                 # library, as it's probably not present.
906                                                 #
907                                                 want_lua=no
908                                         fi
909                                 fi
910                         fi
911                 ],
912                 [
913                         #
914                         # Restore the versions of CFLAGS, CPPFLAGS,
915                         # LDFLAGS, and LIBS before we added the
916                         # "--with-lua=" directory, as we didn't
917                         # actually find lua there.
918                         #
919                         CFLAGS="$wireshark_save_CFLAGS"
920                         CPPFLAGS="$wireshark_save_CPPFLAGS"
921                         LDFLAGS="$wireshark_save_LDFLAGS"
922                         LIBS="$wireshark_save_LIBS"
923                         LUA_LIBS=""
924                         if test "x$lua_dir" != "x"
925                         then
926                                 #
927                                 # The user used "--with-lua=" to specify a directory
928                                 # containing liblua, but we didn't find the header file
929                                 # there; that either means they didn't specify the
930                                 # right directory or are confused about whether liblua
931                                 # is, in fact, installed.  Report the error and give up.
932                                 #
933                                 AC_MSG_ERROR([liblua header not found in directory specified in --with-lua])
934                         else
935                                 if test "x$want_lua" = "xyes"
936                                 then
937                                         #
938                                         # The user tried to force us to use the library, but we
939                                         # couldn't find the header file; report an error.
940                                         #
941                                         AC_MSG_ERROR(Header file lua.h not found.)
942                                 else
943                                         #
944                                         # We couldn't find the header file; don't use the
945                                         # library, as it's probably not present.
946                                         #
947                                         want_lua=no
948                                 fi
949                         fi
950                 ])
951         ])
952
953         if test "x$want_lua" != "xno"
954         then
955                 #
956                 # Well, we at least have the lua header file.
957                 #
958                 # let's check if the libs are there
959                 #
960
961                 # At least on Suse 9.3 systems, liblualib needs linking
962                 # against libm.
963                 LIBS="$LIBS $LUA_LIBS -lm"
964
965                 AC_CHECK_LIB(lua, luaL_register,
966                 [
967                     #
968                     #  Lua 5.1 found
969                     #
970                         if test "x$lua_dir" != "x"
971                         then
972                                 #
973                                 # Put the "-I" and "-L" flags for lua at
974                                 # the beginning of CFLAGS, CPPFLAGS,
975                                 # LDFLAGS, and LIBS.
976                                 #
977                                 LUA_LIBS="-L$lua_dir/lib -llua -lm"
978                                 LUA_INCLUDES="-I$lua_dir/include"
979                         else
980                                 LUA_LIBS="-llua -lm"
981                                 LUA_INCLUDES=""
982                         fi
983                         AC_DEFINE(HAVE_LUA_5_1, 1, [Define to use Lua 5.1])
984                         want_lua=yes
985
986                 ],[
987                         #
988                         # We could not find the libs, maybe we have version number in the lib name
989                         #
990
991                         LIBS="$wireshark_save_LIBS -llua5.1 -lm"
992
993                         AC_CHECK_LIB(lua5.1, luaL_register,
994                         [
995                             #
996                             #  Lua 5.1 found
997                             #
998                             LUA_LIBS=" -llua5.1 -lm"
999                             AC_DEFINE(HAVE_LUA_5_1, 1, [Define to use Lua 5.1])
1000                             want_lua=yes
1001                         ],[
1002                                 #
1003                                 # Restore the versions of CFLAGS, CPPFLAGS,
1004                                 # LDFLAGS, and LIBS before we added the
1005                                 # "--with-lua=" directory, as we didn't
1006                                 # actually find lua there.
1007                                 #
1008                                 CFLAGS="$wireshark_save_CFLAGS"
1009                                 CPPFLAGS="$wireshark_save_CPPFLAGS"
1010                                 LDFLAGS="$wireshark_save_LDFLAGS"
1011                                 LIBS="$wireshark_save_LIBS"
1012                                 LUA_LIBS=""
1013                                 # User requested --with-lua but it isn't available
1014                                 if test "x$want_lua" = "xyes"
1015                                 then
1016                                         AC_MSG_ERROR(Linking with liblua failed.)
1017                                 fi
1018                                 want_lua=no
1019                         ])
1020                 ])
1021
1022         CFLAGS="$wireshark_save_CFLAGS"
1023         CPPFLAGS="$wireshark_save_CPPFLAGS"
1024         LDFLAGS="$wireshark_save_LDFLAGS"
1025         LIBS="$wireshark_save_LIBS"
1026         AC_SUBST(LUA_LIBS)
1027         AC_SUBST(LUA_INCLUDES)
1028
1029         fi
1030 ])
1031
1032 #
1033 # AC_WIRESHARK_LIBPORTAUDIO_CHECK
1034 #
1035 AC_DEFUN([AC_WIRESHARK_LIBPORTAUDIO_CHECK],[
1036
1037         if test "x$portaudio_dir" != "x"
1038         then
1039                 #
1040                 # The user specified a directory in which libportaudio
1041                 # resides, so add the "include" subdirectory of that directory to
1042                 # the include file search path and the "lib" subdirectory
1043                 # of that directory to the library search path.
1044                 #
1045                 # XXX - if there's also a libportaudio in a directory that's
1046                 # already in CFLAGS, CPPFLAGS, or LDFLAGS, this won't
1047                 # make us find the version in the specified directory,
1048                 # as the compiler and/or linker will search that other
1049                 # directory before it searches the specified directory.
1050                 #
1051                 wireshark_save_CFLAGS="$CFLAGS"
1052                 CFLAGS="$CFLAGS -I$portaudio_dir/include"
1053                 wireshark_save_CPPFLAGS="$CPPFLAGS"
1054                 CPPFLAGS="$CPPFLAGS -I$portaudio_dir/include"
1055                 wireshark_save_LIBS="$LIBS"
1056                 LIBS="$LIBS -L$portaudio_dir/lib -lportaudio"
1057                 wireshark_save_LDFLAGS="$LDFLAGS"
1058                 LDFLAGS="$LDFLAGS -L$portaudio_dir/lib"
1059         else
1060                 #
1061                 # The user specified no directory in which libportaudio resides,
1062                 # so just add "-lportaudio" to the used libs.
1063                 #
1064                 wireshark_save_CFLAGS="$CFLAGS"
1065                 wireshark_save_CPPFLAGS="$CPPFLAGS"
1066                 wireshark_save_LDFLAGS="$LDFLAGS"
1067                 wireshark_save_LIBS="$LIBS"
1068                 LIBS="$LIBS -lportaudio"
1069         fi
1070
1071         #
1072         # Make sure we have "portaudio.h".  If we don't, it means we probably
1073         # don't have libportaudio, so don't use it.
1074         #
1075         AC_CHECK_HEADERS(portaudio.h,,
1076         [
1077                 if test "x$portaudio_dir" != "x"
1078                 then
1079                         #
1080                         # The user used "--with-portaudio=" to specify a directory
1081                         # containing libportaudio, but we didn't find the header file
1082                         # there; that either means they didn't specify the
1083                         # right directory or are confused about whether libportaudio
1084                         # is, in fact, installed.  Report the error and give up.
1085                         #
1086                         AC_MSG_ERROR([libportaudio header not found in directory specified in --with-portaudio])
1087                 else
1088                         CFLAGS="$wireshark_save_CFLAGS"
1089                         CPPFLAGS="$wireshark_save_CPPFLAGS"
1090                         LDFLAGS="$wireshark_save_LDFLAGS"
1091                         LIBS="$wireshark_save_LIBS"
1092                         PORTAUDIO_LIBS=""
1093                         if test "x$want_portaudio" = "xyes"
1094                         then
1095                                 #
1096                                 # The user tried to force us to use the library, but we
1097                                 # couldn't find the header file; report an error.
1098                                 #
1099                                 AC_MSG_ERROR(Header file portaudio.h not found.)
1100                         else
1101                                 #
1102                                 # We couldn't find the header file; don't use the
1103                                 # library, as it's probably not present.
1104                                 #
1105                                 want_portaudio=no
1106                         fi
1107                 fi
1108         ])
1109
1110         #
1111         # Check whether we have the right version of portaudio
1112         #
1113         if test "x$want_portaudio" != "xno"
1114         then
1115                 AC_CHECK_TYPE(PortAudioStream,
1116                 AC_DEFINE(PORTAUDIO_API_1, 1, [Define if we are using version of of the Portaudio library API]),
1117                 ,
1118                 [#include <portaudio.h>])
1119         fi
1120
1121         if test "x$want_portaudio" != "xno"
1122         then
1123                 #
1124                 # Well, we at least have the portaudio header file.
1125                 #
1126                 # let's check if the libs are there
1127                 #
1128
1129                 AC_CHECK_LIB(portaudio, Pa_Initialize,
1130                 [
1131                         if test "x$portaudio_dir" != "x"
1132                         then
1133                                 #
1134                                 # Put the "-I" and "-L" flags for portaudio at
1135                                 # the beginning of CFLAGS, CPPFLAGS,
1136                                 # LDFLAGS, and LIBS.
1137                                 #
1138                                 PORTAUDIO_LIBS="-L$portaudio_dir/lib -lportaudio"
1139                                 PORTAUDIO_INCLUDES="-I$portaudio_dir/include"
1140                         else
1141                                 PORTAUDIO_LIBS="-lportaudio"
1142                                 PORTAUDIO_INCLUDES=""
1143                         fi
1144                         AC_DEFINE(HAVE_LIBPORTAUDIO, 1, [Define to use libportaudio library])
1145                         want_portaudio=yes
1146                 ],[
1147                         #
1148                         # Restore the versions of CFLAGS, CPPFLAGS,
1149                         # LDFLAGS, and LIBS before we added the
1150                         # "--with-portaudio=" directory, as we didn't
1151                         # actually find portaudio there.
1152                         #
1153                         CFLAGS="$wireshark_save_CFLAGS"
1154                         CPPFLAGS="$wireshark_save_CPPFLAGS"
1155                         LDFLAGS="$wireshark_save_LDFLAGS"
1156                         LIBS="$wireshark_save_LIBS"
1157                         PORTAUDIO_LIBS=""
1158                         # User requested --with-portaudio but it isn't available
1159                         if test "x$want_portaudio" = "xyes"
1160                         then
1161                                 AC_MSG_ERROR(Linking with libportaudio failed.)
1162                         fi
1163                         want_portaudio=no
1164                 ])
1165
1166         CFLAGS="$wireshark_save_CFLAGS"
1167         CPPFLAGS="$wireshark_save_CPPFLAGS"
1168         LDFLAGS="$wireshark_save_LDFLAGS"
1169         LIBS="$wireshark_save_LIBS"
1170         AC_SUBST(PORTAUDIO_LIBS)
1171         AC_SUBST(PORTAUDIO_INCLUDES)
1172
1173         fi
1174 ])
1175
1176 #
1177 # AC_WIRESHARK_RPM_CHECK
1178 # Looks for the rpm program, and checks to see if we can redefine "_topdir".
1179 #
1180 AC_DEFUN([AC_WIRESHARK_RPM_CHECK],
1181 [
1182         AC_CHECK_PROG(ac_cv_wireshark_have_rpm, rpm, "yes", "no")
1183         if test "x$ac_cv_wireshark_have_rpm" = "xyes"; then
1184                 rpm --define '_topdir /tmp' > /dev/null 2>&1
1185                 AC_MSG_CHECKING(to see if we can redefine _topdir)
1186                 if test $? -eq 0 ; then
1187                         AC_MSG_RESULT(yes)
1188                         HAVE_RPM=yes
1189                 else
1190                         AC_MSG_RESULT(no.  You'll have to build packages manually.)
1191                         HAVE_RPM=no
1192                 fi
1193         fi
1194 ])
1195
1196 #
1197 # AC_WIRESHARK_GNU_SED_CHECK
1198 # Checks if GNU sed is the first sed in PATH.
1199 #
1200 AC_DEFUN([AC_WIRESHARK_GNU_SED_CHECK],
1201 [
1202         AC_MSG_CHECKING(for GNU sed as first sed in PATH)
1203         if  ( sh -c "sed --version" </dev/null 2> /dev/null | grep "GNU sed" 2>&1 > /dev/null ) ;  then
1204                 AC_MSG_RESULT(yes)
1205                 HAVE_GNU_SED=yes
1206         else
1207                 AC_MSG_RESULT(no)
1208                 HAVE_GNU_SED=no
1209         fi
1210 ])
1211
1212 #
1213 # AC_WIRESHARK_C_ARES_CHECK
1214 #
1215 AC_DEFUN([AC_WIRESHARK_C_ARES_CHECK],
1216 [
1217         want_c_ares=defaultyes
1218
1219         if test "x$want_c_ares" = "xdefaultyes"; then
1220                 want_c_ares=yes
1221                 if test "x$ac_cv_enable_usr_local" = "xyes" ; then
1222                         withval=/usr/local
1223                         if test -d "$withval"; then
1224                                 AC_WIRESHARK_ADD_DASH_L(LDFLAGS, ${withval}/lib)
1225                         fi
1226                 fi
1227         fi
1228
1229         if test "x$want_c_ares" = "xyes"; then
1230                 AC_CHECK_LIB(cares, ares_init,
1231                   [
1232                     C_ARES_LIBS=-lcares
1233                 AC_DEFINE(HAVE_C_ARES, 1, [Define to use c-ares library])
1234                 have_good_c_ares=yes
1235                   ],, $SOCKET_LIBS $NSL_LIBS
1236                 )
1237         else
1238                 AC_MSG_RESULT(not required)
1239         fi
1240 ])
1241
1242
1243 #
1244 # AC_WIRESHARK_ADNS_CHECK
1245 #
1246 AC_DEFUN([AC_WIRESHARK_ADNS_CHECK],
1247 [
1248         want_adns=defaultyes
1249
1250         if test "x$want_adns" = "xdefaultyes"; then
1251                 want_adns=yes
1252                 if test "x$ac_cv_enable_usr_local" = "xyes" ; then
1253                         withval=/usr/local
1254                         if test -d "$withval"; then
1255                                 AC_WIRESHARK_ADD_DASH_L(LDFLAGS, ${withval}/lib)
1256                         fi
1257                 fi
1258         fi
1259
1260         if test "x$want_adns" = "xyes"; then
1261                 AC_CHECK_LIB(adns, adns_init,
1262                   [
1263                     ADNS_LIBS=-ladns
1264                 AC_DEFINE(HAVE_GNU_ADNS, 1, [Define to use GNU ADNS library])
1265                 have_good_adns=yes
1266                   ],, $SOCKET_LIBS $NSL_LIBS
1267                 )
1268         else
1269                 AC_MSG_RESULT(not required)
1270         fi
1271 ])
1272
1273
1274 #
1275 # AC_WIRESHARK_LIBCAP_CHECK
1276 #
1277 AC_DEFUN([AC_WIRESHARK_LIBCAP_CHECK],
1278 [
1279         want_libcap=defaultyes
1280
1281         if test "x$want_libcap" = "xdefaultyes"; then
1282                 want_libcap=yes
1283                 if test "x$ac_cv_enable_usr_local" = "xyes" ; then
1284                         withval=/usr/local
1285                         if test -d "$withval"; then
1286                                 AC_WIRESHARK_ADD_DASH_L(LDFLAGS, ${withval}/lib)
1287                         fi
1288                 fi
1289         fi
1290
1291         if test "x$want_libcap" = "xyes"; then
1292                 AC_CHECK_LIB(cap, cap_set_flag,
1293                   [
1294                     LIBCAP_LIBS=-lcap
1295                 AC_DEFINE(HAVE_LIBCAP, 1, [Define to use the libcap library])
1296                 have_good_libcap=yes
1297                   ],,
1298                 )
1299         else
1300                 AC_MSG_RESULT(not required)
1301         fi
1302 ])
1303
1304
1305 #
1306 # AC_WIRESHARK_KRB5_CHECK
1307 #
1308 AC_DEFUN([AC_WIRESHARK_KRB5_CHECK],
1309 [
1310         wireshark_save_CFLAGS="$CFLAGS"
1311         wireshark_save_CPPFLAGS="$CPPFLAGS"
1312         if test "x$krb5_dir" != "x"
1313         then
1314           #
1315           # The user specified a directory in which kerberos resides,
1316           # so add the "include" subdirectory of that directory to
1317           # the include file search path and the "lib" subdirectory
1318           # of that directory to the library search path.
1319           #
1320           # XXX - if there's also a kerberos in a directory that's
1321           # already in CFLAGS, CPPFLAGS, or LDFLAGS, this won't
1322           # make us find the version in the specified directory,
1323           # as the compiler and/or linker will search that other
1324           # directory before it searches the specified directory.
1325           #
1326           CFLAGS="$CFLAGS -I$krb5_dir/include"
1327           CPPFLAGS="$CPPFLAGS -I$krb5_dir/include"
1328           ac_heimdal_version=`grep heimdal $krb5_dir/include/krb5.h | head -n 1 | sed 's/^.*heimdal.*$/HEIMDAL/'`
1329           ac_mit_version=`grep 'Massachusetts Institute of Technology' $krb5_dir/include/krb5.h | head -n 1 | sed 's/^.*Massachusetts Institute of Technology.*$/MIT/'`
1330           ac_krb5_version="$ac_heimdal_version$ac_mit_version"
1331           if test "x$ac_krb5_version" = "xHEIMDAL"
1332               KRB5_LIBS="-L$krb5_dir/lib -lkrb5 -lasn1 $SSL_LIBS -lroken -lcrypt"
1333           then
1334               KRB5_LIBS="-L$krb5_dir/lib -lkrb5 -lk5crypto -lcom_err"
1335           fi
1336           if test "x$ac_krb5_version" = "xMIT"
1337           then
1338             AC_DEFINE(HAVE_MIT_KERBEROS, 1, [Define to use MIT kerberos])
1339           fi
1340         else
1341           AC_PATH_PROG(KRB5_CONFIG, krb5-config)
1342           if test -x "$KRB5_CONFIG"
1343           then
1344             KRB5_FLAGS=`"$KRB5_CONFIG" --cflags`
1345             KRB5_LIBS=`"$KRB5_CONFIG" --libs`
1346             CFLAGS="$CFLAGS $KRB5_FLAGS"
1347             CPPFLAGS="$CPPFLAGS $KRB5_FLAGS"
1348             #
1349             # If -lcrypto is in KRB5_FLAGS, we require it to build
1350             # with Heimdal/MIT.  We don't want to built with it by
1351             # default, due to annoying license incompatibilities
1352             # between the OpenSSL license and the GPL, so:
1353             #
1354             #   if SSL_LIBS is set to a non-empty string, we
1355             #   remove -lcrypto from KRB5_LIBS and replace
1356             #   it with SSL_LIBS;
1357             #
1358             #   if SSL_LIBS is not set to a non-empty string
1359             #   we fail with an appropriate error message.
1360             #
1361             case "$KRB5_LIBS" in
1362             *-lcrypto*)
1363                 if test ! -z "$SSL_LIBS"
1364                 then
1365                     KRB5_LIBS=`echo $KRB5_LIBS | sed 's/-lcrypto//'`
1366                     KRB5_LIBS="$KRB5_LIBS $SSL_LIBS"
1367                 else
1368                     AC_MSG_ERROR([Kerberos library requires -lcrypto but --with-ssl not specified])
1369                 fi
1370                 ;;
1371             esac
1372             ac_krb5_version=`"$KRB5_CONFIG" --version | head -n 1 | sed -e 's/^.*heimdal.*$/HEIMDAL/' -e 's/^Kerberos .*$/MIT/' -e 's/^Solaris Kerberos .*$/MIT/'`
1373           fi
1374         fi
1375
1376         #
1377         # Make sure we have "krb5.h".  If we don't, it means we probably
1378         # don't have kerberos, so don't use it.
1379         #
1380         AC_CHECK_HEADER(krb5.h,,
1381           [
1382             if test "x$krb5_dir" != "x"
1383             then
1384               #
1385               # The user used "--with-krb5=" to specify a directory
1386               # containing kerberos, but we didn't find the header file
1387               # there; that either means they didn't specify the
1388               # right directory or are confused about whether kerberos
1389               # is, in fact, installed.  Report the error and give up.
1390               #
1391               AC_MSG_ERROR([kerberos header not found in directory specified in --with-krb5])
1392             else
1393               if test "x$want_krb5" = "xyes"
1394               then
1395                 #
1396                 # The user tried to force us to use the library, but we
1397                 # couldn't find the header file; report an error.
1398                 #
1399                 AC_MSG_ERROR(Header file krb5.h not found.)
1400               else
1401                 #
1402                 # We couldn't find the header file; don't use the
1403                 # library, as it's probably not present.
1404                 #
1405                 want_krb5=no
1406                 AC_MSG_RESULT(No Heimdal or MIT header found - disabling dissection for some kerberos data in packet decoding)
1407               fi
1408             fi
1409           ])
1410
1411         if test "x$want_krb5" != "xno"
1412         then
1413             #
1414             # Well, we at least have the krb5 header file.
1415             # Check whether this is Heimdal or MIT.
1416             #
1417             AC_MSG_CHECKING(whether the Kerberos library is Heimdal or MIT)
1418             if test "x$ac_krb5_version" = "xHEIMDAL" -o "x$ac_krb5_version" = "xMIT"
1419             then
1420                 #
1421                 # Yes.
1422                 # Check whether we have krb5_kt_resolve - and whether
1423                 # we need to link with -lresolv when linking with
1424                 # the Kerberos library.
1425                 #
1426                 AC_MSG_RESULT($ac_krb5_version)
1427                 wireshark_save_LIBS="$LIBS"
1428                 found_krb5_kt_resolve=no
1429                 for extras in "" "-lresolv"
1430                 do
1431                     LIBS="$KRB5_LIBS $extras"
1432                     if test -z "$extras"
1433                     then
1434                         AC_MSG_CHECKING([whether $ac_krb5_version includes krb5_kt_resolve])
1435                     else
1436                         AC_MSG_CHECKING([whether $ac_krb5_version includes krb5_kt_resolve (linking with $extras)])
1437                     fi
1438                     AC_TRY_LINK(
1439                         [
1440                         ],
1441                         [
1442                             krb5_kt_resolve();
1443                         ],
1444                         [
1445                             #
1446                             # We found "krb5_kt_resolve()", and required
1447                             # the libraries in extras as well.
1448                             #
1449                             AC_MSG_RESULT(yes)
1450                             KRB5_LIBS="$LIBS"
1451                             AC_DEFINE(HAVE_KERBEROS, 1, [Define to use kerberos])
1452                             if test "x$ac_krb5_version" = "xHEIMDAL"
1453                             then
1454                                 AC_DEFINE(HAVE_HEIMDAL_KERBEROS, 1, [Define to use heimdal kerberos])
1455                             elif test "x$ac_krb5_version" = "xMIT"
1456                             then
1457                                 AC_DEFINE(HAVE_MIT_KERBEROS, 1, [Define to use MIT kerberos])
1458                             fi
1459                             found_krb5_kt_resolve=yes
1460                             break
1461                         ],
1462                         [
1463                             AC_MSG_RESULT(no)
1464                         ])
1465                 done
1466                 if test "$found_krb5_kt_resolve" = no
1467                 then
1468                     #
1469                     # We didn't find "krb5_kt_resolve()" in the
1470                     # Kerberos library, even when we tried linking
1471                     # with -lresolv; we can't link with kerberos.
1472                     #
1473                     if test "x$want_krb5" = "xyes"
1474                     then
1475                         #
1476                         # The user tried to force us to use the library,
1477                         # but we can't do so; report an error.
1478                         #
1479                         AC_MSG_ERROR(Usable $ac_krb5_version not found)
1480                     else
1481                         #
1482                         # Restore the versions of CFLAGS and CPPFLAGS
1483                         # from before we added the flags for Kerberos.
1484                         #
1485                         AC_MSG_RESULT(Usable $ac_krb5_version not found - disabling dissection for some kerberos data in packet decoding)
1486                         CFLAGS="$wireshark_save_CFLAGS"
1487                         CPPFLAGS="$wireshark_save_CPPFLAGS"
1488                         KRB5_LIBS=""
1489                         want_krb5=no
1490                     fi
1491                 else
1492                     #
1493                     # We can link with Kerberos; see whether krb5.h
1494                     # defines KEYTYPE_ARCFOUR_56 (where "defines" means
1495                     # "as a #define or as an enum member).
1496                     #
1497                     AC_MSG_CHECKING([whether krb5.h defines KEYTYPE_ARCFOUR_56])
1498                     AC_COMPILE_IFELSE(
1499                       [
1500                         AC_LANG_SOURCE(
1501                           [[
1502                             #include <krb5.h>
1503                             #include <stdio.h>
1504
1505                             main()
1506                             {
1507                               printf("%u\n", KEYTYPE_ARCFOUR_56);
1508                             }
1509                           ]])
1510                       ],
1511                       [
1512                         AC_MSG_RESULT(yes)
1513                         AC_DEFINE(HAVE_KEYTYPE_ARCFOUR_56, 1, [Define if krb5.h defines KEYTYPE_ARCFOUR_56])
1514                       ],
1515                       [
1516                         AC_MSG_RESULT(no)
1517                       ])
1518                 fi
1519                 LIBS="$wireshark_save_LIBS"
1520             else
1521                 #
1522                 # It's not Heimdal or MIT.
1523                 #
1524                 AC_MSG_RESULT(no)
1525                 if test "x$want_krb5" = "xyes"
1526                 then
1527                     #
1528                     # The user tried to force us to use the library,
1529                     # but we can't do so; report an error.
1530                     #
1531                     AC_MSG_ERROR(Kerberos not found)
1532                 else
1533                     #
1534                     # Restore the versions of CFLAGS and CPPFLAGS
1535                     # from before we added the flags for Kerberos.
1536                     #
1537                     AC_MSG_RESULT(Kerberos not found - disabling dissection for some kerberos data in packet decoding)
1538                     CFLAGS="$wireshark_save_CFLAGS"
1539                     CPPFLAGS="$wireshark_save_CPPFLAGS"
1540                     KRB5_LIBS=""
1541                     want_krb5=no
1542                 fi
1543             fi
1544         else
1545             #
1546             # The user asked us not to use Kerberos, or they didn't
1547             # say whether they wanted us to use it but we found
1548             # that we couldn't.
1549             #
1550             # Restore the versions of CFLAGS and CPPFLAGS
1551             # from before we added the flags for Kerberos.
1552             #
1553             CFLAGS="$wireshark_save_CFLAGS"
1554             CPPFLAGS="$wireshark_save_CPPFLAGS"
1555             KRB5_LIBS=""
1556             want_krb5=no
1557         fi
1558         AC_SUBST(KRB5_LIBS)
1559 ])
1560
1561 #
1562 # AC_WIRESHARK_GEOIP_CHECK
1563 #
1564 AC_DEFUN([AC_WIRESHARK_GEOIP_CHECK],
1565 [
1566         want_geoip=defaultyes
1567
1568         if test "x$want_geoip" = "xdefaultyes"; then
1569                 want_geoip=yes
1570                 if test "x$ac_cv_enable_usr_local" = "xyes" ; then
1571                         withval=/usr/local
1572                         if test -d "$withval"; then
1573                                 AC_WIRESHARK_ADD_DASH_L(LDFLAGS, ${withval}/lib)
1574                         fi
1575                 fi
1576         fi
1577
1578         if test "x$want_geoip" = "xyes"; then
1579                 AC_CHECK_LIB(GeoIP, GeoIP_new,
1580                   [
1581                     GEOIP_LIBS=-lGeoIP
1582                 AC_DEFINE(HAVE_GEOIP, 1, [Define to use GeoIP library])
1583                 have_good_geoip=yes
1584                   ],,
1585                 )
1586         else
1587                 AC_MSG_RESULT(not required)
1588         fi
1589 ])
1590
1591 #
1592 # AC_WIRESHARK_GCC_CFLAGS_CHECK
1593 #
1594 # $1 : cflags to test
1595 #
1596 # The macro first determines if the compiler is GCC. Then compile with the
1597 # defined cflags. The defined flags are added to CFLAGS only if the compilation
1598 # succeeds.
1599 #
1600 AC_DEFUN([AC_WIRESHARK_GCC_CFLAGS_CHECK],
1601 [GCC_OPTION="$1"
1602 AC_MSG_CHECKING(whether we can add $GCC_OPTION to CFLAGS)
1603 if test "x$GCC" != "x"; then
1604   CFLAGS_saved="$CFLAGS"
1605   CFLAGS="$CFLAGS $GCC_OPTION"
1606   AC_COMPILE_IFELSE([
1607     AC_LANG_SOURCE([[
1608                       int foo;
1609                   ]])],
1610                   [
1611                     AC_MSG_RESULT(yes)
1612                   ],
1613                   [
1614                     AC_MSG_RESULT(no)
1615                     CFLAGS="$CFLAGS_saved"
1616                   ])
1617 else
1618   AC_MSG_RESULT(no)
1619 fi
1620 ])
1621
1622 #
1623 # AC_WIRESHARK_IGE_MAC_INTEGRATION_CHECK
1624 #
1625 # Checks for the presence of OS X integration functions in the GTK+ framework
1626 # or as a separate library.
1627 #
1628 # http://developer.imendio.com/projects/gtk-macosx/integration
1629 #
1630 AC_DEFUN([AC_WIRESHARK_IGE_MAC_INTEGRATION_CHECK],
1631 [
1632         ac_save_CFLAGS="$CFLAGS"
1633         ac_save_LIBS="$LIBS"
1634         CFLAGS="$CFLAGS $GTK_CFLAGS"
1635         LIBS="$GTK_LIBS $LIBS"
1636         AC_CHECK_LIB(Gtk, ige_mac_menu_set_menu_bar,
1637         [
1638                 AC_DEFINE(HAVE_IGE_MAC_INTEGRATION, 1,
1639                         [Define to 1 if the the Gtk+ framework or a separate library inclues the Imendio IGE Mac OS X Integration functions.])
1640                 have_ige_mac=yes
1641                 # We don't want gtk stuff in LIBS (which is reset below) so
1642                 # manually set GTK_LIBS (which is more appropriate)
1643                 GTK_LIBS="$GTK_LIBS -lGtk"
1644         ])
1645
1646         if test x$have_ige_mac == x
1647         then
1648                 AC_CHECK_LIB(igemacintegration, ige_mac_menu_set_menu_bar,
1649                 [
1650                         AC_DEFINE(HAVE_IGE_MAC_INTEGRATION, 1,
1651                                 [Define to 1 if the the Gtk+ framework or a separate library inclues the Imendio IGE Mac OS X Integration functions.])
1652                         # We don't want gtk stuff in LIBS (which is reset below) so
1653                         # manually set GTK_LIBS (which is more appropriate)
1654                         GTK_LIBS="$GTK_LIBS -ligemacintegration"
1655                 ])
1656         fi
1657         CFLAGS="$ac_save_CFLAGS"
1658         LIBS="$ac_save_LIBS"
1659 ])
1660
1661 #
1662 # AC_WIRESHARK_PYTHON_CHECK
1663 #
1664 # Check whether python devel package is present
1665 #
1666 AC_DEFUN([AC_WIRESHARK_PYTHON_CHECK],
1667   [
1668     #
1669     # Checking whether we have a python devel environment available
1670     #
1671 #  AC_CACHE_CHECK([checking python devel package], ac_cv_wireshark_python_devel,
1672 #    [
1673     AC_CHECK_PROG([ac_ws_python_config], [python-config], "yes", "no")
1674     if test ac_ws_python_config = "no"; then
1675       ac_cv_wireshark_python_devel = "no"
1676     else
1677       AC_MSG_CHECKING([python devel])
1678       ac_save_ws_cflags=$CFLAGS
1679       ac_save_ws_libs=$LIBS
1680       CFLAGS=$(python-config --includes)
1681       LIBS=$(python-config --ldflags)
1682       AC_COMPILE_IFELSE(
1683         [
1684           AC_LANG_PROGRAM(
1685             [[#include <Python.h>]],
1686             [[Py_Initialiaze();]]
1687           )
1688         ],
1689         [
1690           #
1691           # Compilation successful, we have python devel available
1692           #
1693           ac_cv_wireshark_python_devel=yes
1694           PY_LIBS=$LIBS
1695           PY_CFLAGS=$CFLAGS
1696           AC_SUBST(PY_LIBS)
1697           AC_SUBST(PY_CFLAGS)
1698           CFLAGS="$ac_save_ws_cflags"
1699           LIBS="$ac_save_ws_libs"
1700           AC_DEFINE(HAVE_PYTHON, 1, [Define if python devel package available])
1701           AC_MSG_RESULT([yes])
1702         ],
1703         [
1704           #
1705           # Compilation unsuccessful, python devel not available
1706           #
1707           ac_cv_wireshark_python_devel=no
1708           CFLAGS=$ac_save_ws_cflags
1709           LIBS=$ac_save_ws_libs
1710           AC_MSG_RESULT([no])
1711         ])
1712     fi
1713 #    ])
1714 ])