cigi: if the packet is not cigi, just return
[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 # AC_WIRESHARK_TIMEZONE_ABBREV
74 #
75
76 AC_DEFUN([AC_WIRESHARK_TIMEZONE_ABBREV],
77 [
78   AC_CACHE_CHECK([for tm_zone in struct tm],
79     ac_cv_wireshark_have_tm_zone,
80     [
81       AC_TRY_COMPILE(
82         [#include <time.h>],
83         [struct tm t; t.tm_zone;],
84         ac_cv_wireshark_have_tm_zone=yes,
85         ac_cv_wireshark_have_tm_zone=no)
86     ])
87   if test $ac_cv_wireshark_have_tm_zone = yes; then
88     AC_DEFINE(HAVE_TM_ZONE, 1, [Define if tm_zone field exists in struct tm])
89   else
90     AC_CACHE_CHECK([for tzname],
91       ac_cv_wireshark_have_tzname,
92       [
93         AC_TRY_LINK(
94 [#include <time.h>
95 #include <stdio.h>],
96           [printf("%s", tzname[0]);],
97           ac_cv_wireshark_have_tzname=yes,
98           ac_cv_wireshark_have_tzname=no)
99       ])
100     if test $ac_cv_wireshark_have_tzname = yes; then
101       AC_DEFINE(HAVE_TZNAME, 1, [Define if tzname array exists])
102     fi
103   fi
104 ])
105
106
107 #
108 # AC_WIRESHARK_STRUCT_ST_FLAGS
109 #
110 dnl AC_STRUCT_ST_BLKSIZE extracted from the file in question,
111 dnl "acspecific.m4" in GNU Autoconf 2.12, and turned into
112 dnl AC_WIRESHARK_STRUCT_ST_FLAGS, which checks if "struct stat"
113 dnl has the 4.4BSD "st_flags" member, and defines HAVE_ST_FLAGS; that's
114 dnl what's in this file.
115 dnl Done by Guy Harris <guy@alum.mit.edu> on 2012-06-02.
116
117 dnl ### Checks for structure members
118
119 AC_DEFUN([AC_WIRESHARK_STRUCT_ST_FLAGS],
120 [AC_CACHE_CHECK([for st_flags in struct stat], ac_cv_wireshark_struct_st_flags,
121 [AC_TRY_COMPILE([#include <sys/stat.h>], [struct stat s; s.st_flags;],
122 ac_cv_wireshark_struct_st_flags=yes, ac_cv_wireshark_struct_st_flags=no)])
123 if test $ac_cv_wireshark_struct_st_flags = yes; then
124   AC_DEFINE(HAVE_ST_FLAGS, 1, [Define if st_flags field exists in struct stat])
125 fi
126 ])
127
128
129 #
130 # AC_WIRESHARK_STRUCT_SA_LEN
131 #
132 dnl AC_STRUCT_ST_BLKSIZE extracted from the file in question,
133 dnl "acspecific.m4" in GNU Autoconf 2.12, and turned into
134 dnl AC_WIRESHARK_STRUCT_SA_LEN, which checks if "struct sockaddr"
135 dnl has the 4.4BSD "sa_len" member, and defines HAVE_SA_LEN; that's
136 dnl what's in this file.
137 dnl Done by Guy Harris <guy@alum.mit.edu> on 1998-11-14.
138
139 dnl ### Checks for structure members
140
141 AC_DEFUN([AC_WIRESHARK_STRUCT_SA_LEN],
142 [AC_CACHE_CHECK([for sa_len in struct sockaddr], ac_cv_wireshark_struct_sa_len,
143 [AC_TRY_COMPILE([#include <sys/types.h>
144 #include <sys/socket.h>], [struct sockaddr s; s.sa_len;],
145 ac_cv_wireshark_struct_sa_len=yes, ac_cv_wireshark_struct_sa_len=no)])
146 if test $ac_cv_wireshark_struct_sa_len = yes; then
147   AC_DEFINE(HAVE_SA_LEN, 1, [Define if sa_len field exists in struct sockaddr])
148 fi
149 ])
150
151
152 #
153 # AC_WIRESHARK_IPV6_STACK
154 #
155 # By Jun-ichiro "itojun" Hagino, <itojun@iijlab.net>
156 #
157 AC_DEFUN([AC_WIRESHARK_IPV6_STACK],
158 [
159         v6type=unknown
160         v6lib=none
161
162         AC_MSG_CHECKING([ipv6 stack type])
163         for i in v6d toshiba kame inria zeta linux linux-glibc solaris; do
164                 case $i in
165                 v6d)
166                         AC_EGREP_CPP(yes, [
167 #include </usr/local/v6/include/sys/types.h>
168 #ifdef __V6D__
169 yes
170 #endif],
171                                 [v6type=$i; v6lib=v6;
172                                 v6libdir=/usr/local/v6/lib;
173                                 #
174                                 # XXX - this doesn't define INET6;
175                                 # is that a mistake?
176                                 #
177                                 CPPFLAGS="-I/usr/local/v6/include $CPPFLAGS"])
178                         ;;
179                 toshiba)
180                         AC_EGREP_CPP(yes, [
181 #include <sys/param.h>
182 #ifdef _TOSHIBA_INET6
183 yes
184 #endif],
185                                 [v6type=$i; v6lib=inet6;
186                                 v6libdir=/usr/local/v6/lib;
187                                 AC_DEFINE(INET6, 1, [Define if the platform supports IPv6])])
188                         ;;
189                 kame)
190                         AC_EGREP_CPP(yes, [
191 #include <netinet/in.h>
192 #ifdef __KAME__
193 yes
194 #endif],
195                                 [v6type=$i; v6lib=inet6;
196                                 v6libdir=/usr/local/v6/lib;
197                                 AC_DEFINE(INET6, 1, [Define if the platform supports IPv6])])
198                         ;;
199                 inria)
200                         AC_EGREP_CPP(yes, [
201 #include <netinet/in.h>
202 #ifdef IPV6_INRIA_VERSION
203 yes
204 #endif],
205                                 [v6type=$i;
206                                 AC_DEFINE(INET6, 1, [Define if the platform supports IPv6])])
207                         ;;
208                 zeta)
209                         AC_EGREP_CPP(yes, [
210 #include <sys/param.h>
211 #ifdef _ZETA_MINAMI_INET6
212 yes
213 #endif],
214                                 [v6type=$i; v6lib=inet6;
215                                 v6libdir=/usr/local/v6/lib;
216                                 AC_DEFINE(INET6, 1, [Define if the platform supports IPv6])])
217                         ;;
218                 linux)
219                         if test -d /usr/inet6; then
220                                 v6type=$i
221                                 v6lib=inet6
222                                 v6libdir=/usr/inet6
223                                 AC_DEFINE(INET6, 1, [Define if the platform supports IPv6])
224                         fi
225                         ;;
226                 linux-glibc)
227                         AC_EGREP_CPP(yes, [
228 #include <features.h>
229 #if defined(__GLIBC__) && defined(__GLIBC_MINOR__)
230 #if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 1) || __GLIBC__ > 2
231 yes
232 #endif
233 #endif],
234                         [v6type=$i; v6lib=inet6;
235                         AC_DEFINE(INET6, 1, [Define if the platform supports IPv6])])
236                         ;;
237                 solaris)
238                         #
239                         # There's nothing we can check for in the header
240                         # file, so we just check for SunOS (pre-SunOS 5
241                         # versions didn't include IPv6 support, so we
242                         # just check the OS, not the version).
243                         #
244                         if test "`uname -s`" = "SunOS"; then
245                                 v6type=$i
246                                 v6lib=inet6
247                                 AC_DEFINE(INET6, 1, [Define if the platform supports IPv6])
248                         fi
249                         ;;
250                 esac
251                 if test "$v6type" != "unknown"; then
252                         break
253                 fi
254         done
255
256         if test "$v6lib" != "none"; then
257                 for dir in $v6libdir /usr/local/v6/lib /usr/local/lib; do
258                         if test -d $dir -a -f $dir/lib$v6lib.a; then
259                                 LIBS="-L$dir $LIBS -l$v6lib"
260                                 break
261                         fi
262                 done
263                 enable_ipv6="yes"
264         else
265                 enable_ipv6="no"
266         fi
267         AC_MSG_RESULT(["$v6type, $v6lib"])
268 ])
269
270 #
271 # AC_WIRESHARK_GETADDRINFO_LIB_CHECK
272 #
273 # Checks whether we have "getaddrinfo()" and whether we need "-lnsl" to get it.
274 AC_DEFUN([AC_WIRESHARK_GETADDRINFO_LIB_CHECK],
275 [
276     AC_CHECK_FUNCS(getaddrinfo, ,
277         AC_CHECK_LIB(nsl, getaddrinfo,
278                      [
279                          NSL_LIBS="-lnsl"
280                          AC_DEFINE(HAVE_GETADDRINFO, 1, [Defined if we have getaddrinfo])
281                      ]))
282     AC_SUBST(NSL_LIBS)
283 ])
284
285 #
286 # AC_WIRESHARK_GETHOSTBY_LIB_CHECK
287 #
288 # Checks whether we need "-lnsl" to get "gethostby*()", which we use
289 # in "resolv.c".
290 #
291 # Adapted from stuff in the AC_PATH_XTRA macro in "acspecific.m4" in
292 # GNU Autoconf 2.13; the comment came from there.
293 # Done by Guy Harris <guy@alum.mit.edu> on 2000-01-14.
294 #
295 AC_DEFUN([AC_WIRESHARK_GETHOSTBY_LIB_CHECK],
296 [
297     # msh@cis.ufl.edu says -lnsl (and -lsocket) are needed for his 386/AT,
298     # to get the SysV transport functions.
299     # chad@anasazi.com says the Pyramid MIS-ES running DC/OSx (SVR4)
300     # needs -lnsl.
301     # The nsl library prevents programs from opening the X display
302     # on Irix 5.2, according to dickey@clark.net.
303     AC_CHECK_FUNCS(gethostbyname, ,
304         AC_CHECK_LIB(nsl, gethostbyname,
305                      [
306                         NSL_LIBS="-lnsl"
307                         AC_DEFINE(HAVE_GETHOSTBYNAME, 1, [Defined if we have gethostbyname])
308                      ]))
309     AC_SUBST(NSL_LIBS)
310 ])
311
312 #
313 # AC_WIRESHARK_SOCKET_LIB_CHECK
314 #
315 # Checks whether we need "-lsocket" to get "socket()", which is used
316 # by libpcap on some platforms - and, in effect, "gethostbyname()" or
317 # "getaddrinfo()" on most if not all platforms (so that it can use NIS or
318 # DNS or... to look up host names).
319 #
320 # Adapted from stuff in the AC_PATH_XTRA macro in "acspecific.m4" in
321 # GNU Autoconf 2.13; the comment came from there.
322 # Done by Guy Harris <guy@alum.mit.edu> on 2000-01-14.
323 #
324 # We use "connect" because that's what AC_PATH_XTRA did.
325 #
326 AC_DEFUN([AC_WIRESHARK_SOCKET_LIB_CHECK],
327 [
328     # lieder@skyler.mavd.honeywell.com says without -lsocket,
329     # socket/setsockopt and other routines are undefined under SCO ODT
330     # 2.0.  But -lsocket is broken on IRIX 5.2 (and is not necessary
331     # on later versions), says simon@lia.di.epfl.ch: it contains
332     # gethostby* variants that don't use the nameserver (or something).
333     # -lsocket must be given before -lnsl if both are needed.
334     # We assume that if connect needs -lnsl, so does gethostbyname.
335     AC_CHECK_FUNC(connect, ,
336       AC_CHECK_LIB(socket, connect, SOCKET_LIBS="-lsocket",
337                 AC_MSG_ERROR(Function 'socket' not found.), $NSL_LIBS))
338     AC_SUBST(SOCKET_LIBS)
339 ])
340
341 #
342 # AC_WIRESHARK_BREAKLOOP_TRY_LINK
343 #
344 AC_DEFUN([AC_WIRESHARK_PCAP_BREAKLOOP_TRY_LINK],
345 [
346   AC_LINK_IFELSE(
347   [
348       AC_LANG_SOURCE(
349       [[
350 #       include <pcap.h>
351         int main(void)
352         {
353           pcap_t  *pct = NULL;
354           pcap_breakloop(pct);
355           return 0;
356         }
357       ]])
358   ],
359   [
360     ws_breakloop_compiled=yes
361   ],
362   [
363     ws_breakloop_compiled=no
364   ])
365 ])
366
367
368
369 #
370 # AC_WIRESHARK_PCAP_CHECK
371 #
372 AC_DEFUN([AC_WIRESHARK_PCAP_CHECK],
373 [
374         if test -z "$pcap_dir"
375         then
376           # Pcap header checks
377           # XXX need to set a var AC_CHECK_HEADER(pcap.h,,)
378
379           #
380           # The user didn't specify a directory in which libpcap resides.
381           # First, look for a pcap-config script.
382           #
383           AC_PATH_TOOL(PCAP_CONFIG, pcap-config)
384
385           if test -n "$PCAP_CONFIG" ; then
386             #
387             # Found it.
388             #
389             # Now check whether it's the libpcap 1.0 version, which
390             # put a space after "-L" - on some platforms, that doesn't
391             # work.
392             #
393             AC_MSG_CHECKING(for broken pcap-config)
394             case "`\"$PCAP_CONFIG\" --libs`" in
395
396             "-L "*)
397               #
398               # Space after -L.  Pretend pcap-config doesn't exist.
399               #
400               AC_MSG_RESULT(yes)
401               PCAP_CONFIG=""
402               ;;
403
404             *)
405               #
406               # No space after -L.
407               #
408               AC_MSG_RESULT(no)
409               ;;
410             esac
411           fi
412           if test -n "$PCAP_CONFIG" ; then
413             #
414             # Found it, and it's usable; use it to get the include flags
415             # for libpcap.
416             #
417             CPPFLAGS="$CPPFLAGS `\"$PCAP_CONFIG\" --cflags`"
418           else
419             #
420             # Didn't find it; we have to look for libpcap ourselves.
421             # We assume that the current library search path will work,
422             # but we may have to look for the header in a "pcap"
423             # subdirectory of "/usr/include" or "/usr/local/include",
424             # as some systems apparently put "pcap.h" in a "pcap"
425             # subdirectory, and we also check "$prefix/include" - and
426             # "$prefix/include/pcap", in case $prefix is set to
427             # "/usr/include" or "/usr/local/include".
428             #
429             # XXX - should we just add "$prefix/include" to the include
430             # search path and "$prefix/lib" to the library search path?
431             #
432             AC_MSG_CHECKING(for extraneous pcap header directories)
433             found_pcap_dir=""
434             pcap_dir_list="/usr/include/pcap $prefix/include/pcap $prefix/include"
435             if test "x$ac_cv_enable_usr_local" = "xyes" ; then
436               pcap_dir_list="$pcap_dir_list /usr/local/include/pcap"
437             fi
438             for pcap_dir in $pcap_dir_list
439             do
440               if test -d $pcap_dir ; then
441                 if test x$pcap_dir != x/usr/include -a x$pcap_dir != x/usr/local/include ; then
442                     CPPFLAGS="$CPPFLAGS -I$pcap_dir"
443                 fi
444                 found_pcap_dir=" $found_pcap_dir -I$pcap_dir"
445                 break
446               fi
447             done
448
449             if test "$found_pcap_dir" != "" ; then
450               AC_MSG_RESULT(found --$found_pcap_dir added to CFLAGS)
451             else
452               AC_MSG_RESULT(not found)
453             fi
454           fi
455         else
456           #
457           # The user specified a directory in which libpcap resides,
458           # so add the "include" subdirectory of that directory to
459           # the include file search path and the "lib" subdirectory
460           # of that directory to the library search path.
461           #
462           # XXX - if there's also a libpcap in a directory that's
463           # already in CPPFLAGS or LDFLAGS, this won't make us find
464           # the version in the specified directory, as the compiler
465           # and/or linker will search that other directory before it
466           # searches the specified directory.
467           #
468           CPPFLAGS="$CPPFLAGS -I$pcap_dir/include"
469           AC_WIRESHARK_ADD_DASH_L(LDFLAGS, $pcap_dir/lib)
470         fi
471
472         # Pcap header check
473         AC_CHECK_HEADER(pcap.h,,
474             AC_MSG_ERROR([[Header file pcap.h not found; if you installed libpcap
475 from source, did you also do \"make install-incl\", and if you installed a
476 binary package of libpcap, is there also a developer's package of libpcap,
477 and did you also install that package?]]))
478
479         if test -n "$PCAP_CONFIG" ; then
480           #
481           # We have pcap-config; we assume that means we have libpcap
482           # installed and that pcap-config will tell us whatever
483           # libraries libpcap needs.
484           #
485           if test x$enable_static = xyes; then
486             PCAP_LIBS="`\"$PCAP_CONFIG\" --libs --static`"
487           else
488             PCAP_LIBS="`\"$PCAP_CONFIG\" --libs`"
489           fi
490           AC_DEFINE(HAVE_LIBPCAP, 1, [Define to use libpcap library])
491         else
492           #
493           # Check to see if we find "pcap_open_live" in "-lpcap".
494           # Also check for various additional libraries that libpcap might
495           # require.
496           #
497           AC_CHECK_LIB(pcap, pcap_open_live,
498             [
499               PCAP_LIBS=-lpcap
500               AC_DEFINE(HAVE_LIBPCAP, 1, [Define to use libpcap library])
501             ], [
502               ac_wireshark_extras_found=no
503               ac_save_LIBS="$LIBS"
504               for extras in "-lcfg -lodm" "-lpfring"
505               do
506                 AC_MSG_CHECKING([for pcap_open_live in -lpcap with $extras])
507                 LIBS="-lpcap $extras"
508                 #
509                 # XXX - can't we use AC_CHECK_LIB here?
510                 #
511                 AC_TRY_LINK(
512                     [
513 #       include <pcap.h>
514                     ],
515                     [
516         pcap_open_live(NULL, 0, 0, 0, NULL);
517                     ],
518                     [
519                         ac_wireshark_extras_found=yes
520                         AC_MSG_RESULT([yes])
521                         PCAP_LIBS="-lpcap $extras"
522                         AC_DEFINE(HAVE_LIBPCAP, 1, [Define to use libpcap library])
523                     ],
524                     [
525                         AC_MSG_RESULT([no])
526                     ])
527                 if test x$ac_wireshark_extras_found = xyes
528                 then
529                     break
530                 fi
531               done
532               if test x$ac_wireshark_extras_found = xno
533               then
534                 AC_MSG_ERROR([Can't link with library libpcap.])
535               fi
536               LIBS=$ac_save_LIBS
537             ], $SOCKET_LIBS $NSL_LIBS)
538         fi
539         AC_SUBST(PCAP_LIBS)
540
541         #
542         # Check whether various variables and functions are defined by
543         # libpcap.
544         #
545         ac_save_LIBS="$LIBS"
546         LIBS="$PCAP_LIBS $SOCKET_LIBS $NSL_LIBS $LIBS"
547         AC_CHECK_FUNCS(pcap_open_dead pcap_freecode)
548         #
549         # pcap_breakloop may be present in the library but not declared
550         # in the pcap.h header file.  If it's not declared in the header
551         # file, attempts to use it will get warnings, and, if we're
552         # building with warnings treated as errors, that warning will
553         # cause compilation to fail.
554         #
555         # We are therefore first testing whether the function is present
556         # and then, if we're compiling with warnings as errors, testing
557         # whether it is usable.  It is usable if it compiles without
558         # a -Wimplicit warning (the "compile with warnings as errors"
559         # option requires GCC). If it is not usable, we fail and tell
560         # the user that the pcap.h header needs to be updated.
561         #
562         # Ceteris paribus, this should only happen with Mac OS X 10.3[.x] which
563         # can have an up-to-date pcap library without the corresponding pcap
564         # header.
565         #
566         # However, it might also happen on some others OSes with some erroneous
567         # system manipulations where multiple versions of libpcap might co-exist
568         # e.g. hand made symbolic link from libpcap.so -> libpcap.so.0.8 but
569         # having the pcap header version 0.7.
570         #
571         AC_MSG_CHECKING([whether pcap_breakloop is present])
572         ac_CFLAGS_saved="$CFLAGS"
573         AC_WIRESHARK_PCAP_BREAKLOOP_TRY_LINK
574         if test "x$ws_breakloop_compiled" = "xyes"; then
575           AC_MSG_RESULT(yes)
576           AC_DEFINE(HAVE_PCAP_BREAKLOOP, 1, [Define if pcap_breakloop is known])
577           if test "x$with_warnings_as_errors" = "xyes"; then
578             AC_MSG_CHECKING([whether pcap_breakloop is usable])
579             CFLAGS="$CFLAGS -Werror -Wimplicit"
580             AC_WIRESHARK_PCAP_BREAKLOOP_TRY_LINK
581             if test "x$ws_breakloop_compiled" = "xyes"; then
582               AC_MSG_RESULT(yes)
583             else
584               AC_MSG_RESULT(no)
585               AC_MSG_ERROR(
586 [Your pcap library is more recent than your pcap header.
587 As you are building with compiler warnings treated as errors, Wireshark
588 won't be able to use functions not declared in that header.
589 If you wish to build with compiler warnings treated as errors, You should
590 install a newer version of the header file.])
591             fi
592             CFLAGS="$ac_CFLAGS_saved"
593           fi
594         else
595           AC_MSG_RESULT(no)
596         fi
597
598         #
599         # Later versions of Mac OS X 10.3[.x] ship a pcap.h that
600         # doesn't define pcap_if_t but ship an 0.8[.x] libpcap,
601         # so the library has "pcap_findalldevs()", but pcap.h
602         # doesn't define "pcap_if_t" so you can't actually *use*
603         # "pcap_findalldevs()".
604         #
605         # That even appears to be true of systems shipped with
606         # 10.3.4, so it doesn't appear only to be a case of
607         # Software Update not updating header files.
608         #
609         # (You can work around this by installing the 0.8 header
610         # files.)
611         #
612         AC_CACHE_CHECK([whether pcap_findalldevs is present and usable],
613           [ac_cv_func_pcap_findalldevs],
614           [
615             AC_LINK_IFELSE(
616               [
617                 AC_LANG_SOURCE(
618                   [[
619                     #include <pcap.h>
620                     main()
621                     {
622                       pcap_if_t *devpointer;
623                       char errbuf[1];
624
625                       pcap_findalldevs(&devpointer, errbuf);
626                     }
627                   ]])
628               ],
629               [
630                 ac_cv_func_pcap_findalldevs=yes
631               ],
632               [
633                 ac_cv_func_pcap_findalldevs=no
634               ])
635           ])
636         #
637         # Don't check for other new routines that showed up after
638         # "pcap_findalldevs()" if we don't have a usable
639         # "pcap_findalldevs()", so we don't end up using them if the
640         # "pcap.h" is crufty and old and doesn't declare them.
641         #
642         if test $ac_cv_func_pcap_findalldevs = "yes" ; then
643           AC_DEFINE(HAVE_PCAP_FINDALLDEVS, 1,
644            [Define to 1 if you have the `pcap_findalldevs' function and a pcap.h that declares pcap_if_t.])
645           AC_CHECK_FUNCS(pcap_datalink_val_to_name pcap_datalink_name_to_val)
646           AC_CHECK_FUNCS(pcap_datalink_val_to_description)
647           AC_CHECK_FUNCS(pcap_list_datalinks pcap_set_datalink pcap_lib_version)
648           AC_CHECK_FUNCS(pcap_get_selectable_fd pcap_free_datalinks)
649           AC_CHECK_FUNC(pcap_create,
650           [
651             AC_DEFINE(HAVE_PCAP_CREATE, 1,
652              [Define to 1 if you have the `pcap_create' function.])
653             AC_DEFINE(CAN_SET_CAPTURE_BUFFER_SIZE, 1,
654              [Define to 1 if the capture buffer size can be set.])
655           ])
656           AC_CHECK_FUNCS(bpf_image pcap_set_tstamp_precision)
657         fi
658         LIBS="$ac_save_LIBS"
659 ])
660
661 AC_DEFUN([AC_WIRESHARK_PCAP_REMOTE_CHECK],
662 [
663     ac_save_LIBS="$LIBS"
664     LIBS="$PCAP_LIBS $SOCKET_LIBS $NSL_LIBS $LIBS"
665     AC_DEFINE(HAVE_REMOTE, 1, [Define to 1 to enable remote
666               capturing feature in WinPcap library])
667     AC_CHECK_FUNCS(pcap_open)
668     if test $ac_cv_func_pcap_open = "yes" ; then
669         AC_DEFINE(HAVE_PCAP_REMOTE, 1,
670             [Define to 1 if you have WinPcap remote capturing support and prefer to use these new API features.])
671     fi
672     AC_CHECK_FUNCS(pcap_setsampling)
673     LIBS="$ac_save_LIBS"
674 ])
675
676 #
677 # AC_WIRESHARK_ZLIB_CHECK
678 #
679 AC_DEFUN([AC_WIRESHARK_ZLIB_CHECK],
680 [
681         if test "x$zlib_dir" != "x"
682         then
683           #
684           # The user specified a directory in which zlib resides,
685           # so add the "include" subdirectory of that directory to
686           # the include file search path and the "lib" subdirectory
687           # of that directory to the library search path.
688           #
689           # XXX - if there's also a zlib in a directory that's
690           # already in CPPFLAGS or LDFLAGS, this won't make us find
691           # the version in the specified directory, as the compiler
692           # and/or linker will search that other directory before it
693           # searches the specified directory.
694           #
695           wireshark_save_CPPFLAGS="$CPPFLAGS"
696           CPPFLAGS="$CPPFLAGS -I$zlib_dir/include"
697           wireshark_save_LIBS="$LIBS"
698           AC_WIRESHARK_ADD_DASH_L(LIBS, $zlib_dir/lib)
699         fi
700
701         #
702         # Make sure we have "zlib.h".  If we don't, it means we probably
703         # don't have zlib, so don't use it.
704         #
705         AC_CHECK_HEADER(zlib.h,,
706           [
707             if test "x$zlib_dir" != "x"
708             then
709               #
710               # The user used "--with-zlib=" to specify a directory
711               # containing zlib, but we didn't find the header file
712               # there; that either means they didn't specify the
713               # right directory or are confused about whether zlib
714               # is, in fact, installed.  Report the error and give up.
715               #
716               AC_MSG_ERROR([zlib header not found in directory specified in --with-zlib])
717             else
718               if test "x$want_zlib" = "xyes"
719               then
720                 #
721                 # The user tried to force us to use the library, but we
722                 # couldn't find the header file; report an error.
723                 #
724                 AC_MSG_ERROR(Header file zlib.h not found.)
725               else
726                 #
727                 # We couldn't find the header file; don't use the
728                 # library, as it's probably not present.
729                 #
730                 want_zlib=no
731               fi
732             fi
733           ])
734
735         if test "x$want_zlib" != "xno"
736         then
737                 #
738                 # Well, we at least have the zlib header file.
739                 # We link with zlib to support uncompression of
740                 # gzipped network traffic, e.g. in an HTTP request
741                 # or response body.
742                 #
743                 if test "x$zlib_dir" != "x"
744                 then
745                         #
746                         # Put the "-L" flags for zlib at the beginning
747                         # of LIBS.
748                         #
749                         LIBS=""
750                         AC_WIRESHARK_ADD_DASH_L(LIBS, $zlib_dir/lib)
751                         LIBS="$LIBS -lz $wireshark_save_LIBS"
752                 else
753                         LIBS="-lz $LIBS"
754                 fi
755                 AC_DEFINE(HAVE_LIBZ, 1, [Define to use libz library])
756
757                 #
758                 # Check for "inflatePrime()" in zlib, which we need
759                 # in order to read compressed capture files.
760                 #
761                 AC_CHECK_FUNCS(inflatePrime)
762
763                 if test "x$ac_cv_func_inflatePrime" = "xyes" ; then
764                         #
765                         # Now check for "inflatePrime()" in zlib when
766                         # linking with the linker flags for GTK+
767                         # applications; people often grab XFree86 source
768                         # and build and install it on their systems,
769                         # and they appear sometimes to misconfigure
770                         # XFree86 so that, even on systems with zlib,
771                         # it assumes there is no zlib, so the XFree86
772                         # build process builds and installs its
773                         # own zlib in the X11 library directory.
774                         #
775                         # The zlib in at least some versions of XFree86
776                         # is an older version that may lack "inflatePrime()",
777                         # and that's the zlib with which Wireshark gets
778                         # linked, so the build of Wireshark fails.
779                         #
780                         AC_MSG_CHECKING([for inflatePrime missing when linking with X11])
781                         AC_TRY_LINK_FUNC(inflatePrime, AC_MSG_RESULT(no),
782                           [
783                             AC_MSG_RESULT(yes)
784                             AC_MSG_ERROR(old zlib found when linking with X11 - get rid of old zlib.)
785                           ])
786                 fi
787         else
788                 #
789                 # Restore the versions of CPPFLAGS and LIBS before
790                 # we added the "-with-zlib=" directory, as we didn't
791                 # actually find zlib there.
792                 #
793                 CPPFLAGS="$wireshark_save_CPPFLAGS"
794                 LIBS="$wireshark_save_LIBS"
795                 want_zlib=no
796         fi
797 ])
798
799 #
800 # AC_WIRESHARK_LIBLUA_CHECK
801 #
802 # Sets $have_lua to yes or no.
803 # If it's yes, it also sets $LUA_CFLAGS and $LUA_LIBS.
804 AC_DEFUN([AC_WIRESHARK_LIBLUA_CHECK],[
805
806         if test "x$want_lua_dir" = "x"
807         then
808                 # The user didn't tell us where to find Lua.  Let's go look for it.
809
810                 # First, try the standard (pkg-config) way.
811                 # Unfortunately Lua's pkg-config file isn't standardly named.
812                 # Some distributions allow installation of multiple versions of
813                 # Lua at the same time.  On such systems each version has its
814                 # own package name.
815                 #
816                 # We use a for loop instead of giving all the package names to
817                 # PKG_CHECK_MODULES because doing the latter doesn't appear to
818                 # work reliably (some package names are not searched for).
819                 for pkg in "lua < 5.3" lua5.2 lua-5.2 lua52 lua5.1 lua-5.1 lua51 lua5.0 lua-5.0 lua50
820                 do
821                         PKG_CHECK_MODULES(LUA, $pkg, [have_lua=yes], [true])
822
823                         if test "x$have_lua" = "xyes"
824                         then
825                                 break
826                         fi
827                 done
828         fi
829
830         if test "x$have_lua" != "xyes"
831         then
832                 # We don't have pkg-config or the user specified the path to
833                 # Lua (in $want_lua_dir).
834                 # Let's look for the header file.
835
836                 AC_MSG_CHECKING(for the location of lua.h)
837                 if test "x$want_lua_dir" = "x"
838                 then
839                         # The user didn't tell us where to look so we'll look in some
840                         # standard locations.
841                         want_lua_dir="/usr /usr/local $prefix"
842                 fi
843                 for dir in $want_lua_dir
844                 do
845                         if test -r "$dir/include/lua.h"
846                         then
847                                 header_dir="$dir/include"
848                                 lua_dir=$dir
849                                 break
850                         fi
851
852                         for ver in 5.2 52 5.1 51 5.0 50
853                         do
854                                 if test -r "$dir/include/lua$ver/lua.h"
855                                 then
856                                         header_dir="$dir/include/lua$ver"
857                                         lua_dir=$dir
858                                         break
859                                 fi
860                         done
861                 done
862
863                 if test "x$header_dir" = "x"
864                 then
865                         have_lua=no
866                         AC_MSG_RESULT(not found)
867                 else
868                         AC_MSG_RESULT($header_dir)
869
870                         AC_MSG_CHECKING(the Lua version)
871                         lua_ver=`$AWK AS_ESCAPE('/LUA_VERSION_NUM/ { print $NF; }' $header_dir/lua.h | sed 's/0/./')`
872
873                         if test "x$lua_ver" = "x5.3"
874                         then
875                                 # Wireshark doesn't compile with Lua 5.3 today
876                                 AC_MSG_RESULT($lua_ver - disabling Lua support)
877                                 have_lua=no
878                         else
879                                 AC_MSG_RESULT($lua_ver)
880
881                                 wireshark_save_CPPFLAGS="$CPPFLAGS"
882                                 CPPFLAGS="$CPPFLAGS -I$header_dir"
883                                 AC_CHECK_HEADERS(lua.h lualib.h lauxlib.h, ,
884                                 [
885                                         have_lua=no
886                                         # Restore our CPPFLAGS
887                                         CPPFLAGS="$wireshark_save_CPPFLAGS"
888                                 ])
889                         fi
890
891                         if test "x$have_lua" = "x"
892                         then
893                                 # Restore our CPPFLAGS and set LUA_CFLAGS
894                                 CPPFLAGS="$wireshark_save_CPPFLAGS"
895                                 LUA_CFLAGS="-I$header_dir"
896
897                                 # We have the header files and they work.  Now let's check if we
898                                 # have the library and it works.
899                                 #
900                                 # XXX - if there's also a liblua in a directory that's
901                                 # already in CPPFLAGS or LDFLAGS, this won't make us find
902                                 # the version in the specified directory, as the compiler
903                                 # and/or linker will search that other directory before it
904                                 # searches the specified directory.
905                                 #
906                                 # XXX - lib64?
907                                 wireshark_save_LIBS="$LIBS"
908                                 LIBS="$LIBS -L$lua_dir/lib"
909                                 AC_SEARCH_LIBS(luaL_openlibs, [lua-${lua_ver} lua${lua_ver} lua],
910                                 [
911                                         LUA_LIBS="-L$lua_dir/lib $ac_cv_search_luaL_openlibs -lm"
912                                         LIBS="$wireshark_save_LIBS"
913                                         have_lua=yes
914                                 ],[
915                                         LIBS="$wireshark_save_LIBS"
916                                         have_lua=no
917                                 ], -lm)
918                         fi
919                 fi
920         fi
921
922 ])
923
924 #
925 # AC_WIRESHARK_LIBPORTAUDIO_CHECK
926 #
927 AC_DEFUN([AC_WIRESHARK_LIBPORTAUDIO_CHECK],[
928
929         if test "x$portaudio_dir" != "x"
930         then
931                 #
932                 # The user specified a directory in which libportaudio
933                 # resides, so add the "include" subdirectory of that directory to
934                 # the include file search path and the "lib" subdirectory
935                 # of that directory to the library search path.
936                 #
937                 # XXX - if there's also a libportaudio in a directory that's
938                 # already in CPPFLAGS or LDFLAGS, this won't make us find
939                 # the version in the specified directory, as the compiler
940                 # and/or linker will search that other directory before it
941                 # searches the specified directory.
942                 #
943                 wireshark_save_CPPFLAGS="$CPPFLAGS"
944                 CPPFLAGS="$CPPFLAGS -I$portaudio_dir/include"
945                 wireshark_save_LIBS="$LIBS"
946                 LIBS="$LIBS -L$portaudio_dir/lib -lportaudio"
947                 wireshark_save_LDFLAGS="$LDFLAGS"
948                 LDFLAGS="$LDFLAGS -L$portaudio_dir/lib"
949         else
950                 #
951                 # The user specified no directory in which libportaudio resides,
952                 # so just add "-lportaudio" to the used libs.
953                 #
954                 wireshark_save_CPPFLAGS="$CPPFLAGS"
955                 wireshark_save_LDFLAGS="$LDFLAGS"
956                 wireshark_save_LIBS="$LIBS"
957                 LIBS="$LIBS -lportaudio"
958         fi
959
960         #
961         # Make sure we have "portaudio.h".  If we don't, it means we probably
962         # don't have libportaudio, so don't use it.
963         #
964         AC_CHECK_HEADERS(portaudio.h,,
965         [
966                 if test "x$portaudio_dir" != "x"
967                 then
968                         #
969                         # The user used "--with-portaudio=" to specify a directory
970                         # containing libportaudio, but we didn't find the header file
971                         # there; that either means they didn't specify the
972                         # right directory or are confused about whether libportaudio
973                         # is, in fact, installed.  Report the error and give up.
974                         #
975                         AC_MSG_ERROR([libportaudio header not found in directory specified in --with-portaudio])
976                 else
977                         CPPFLAGS="$wireshark_save_CPPFLAGS"
978                         LDFLAGS="$wireshark_save_LDFLAGS"
979                         LIBS="$wireshark_save_LIBS"
980                         PORTAUDIO_LIBS=""
981                         if test "x$want_portaudio" = "xyes"
982                         then
983                                 #
984                                 # The user tried to force us to use the library, but we
985                                 # couldn't find the header file; report an error.
986                                 #
987                                 AC_MSG_ERROR(Header file portaudio.h not found.)
988                         else
989                                 #
990                                 # We couldn't find the header file; don't use the
991                                 # library, as it's probably not present.
992                                 #
993                                 want_portaudio=no
994                         fi
995                 fi
996         ])
997
998         #
999         # Check whether we have the right version of portaudio
1000         #
1001         if test "x$want_portaudio" != "xno"
1002         then
1003                 AC_CHECK_TYPE(PortAudioStream,
1004                 AC_DEFINE(PORTAUDIO_API_1, 1, [Define if we are using version of of the Portaudio library API]),
1005                 ,
1006                 [#include <portaudio.h>])
1007         fi
1008
1009         if test "x$want_portaudio" != "xno"
1010         then
1011                 #
1012                 # Well, we at least have the portaudio header file.
1013                 #
1014                 # let's check if the libs are there
1015                 #
1016
1017                 AC_CHECK_LIB(portaudio, Pa_Initialize,
1018                 [
1019                         if test "x$portaudio_dir" != "x"
1020                         then
1021                                 #
1022                                 # Put the "-I" and "-L" flags for portaudio
1023                                 # into PORTAUDIO_INCLUDES and PORTAUDIO_LIBS,
1024                                 # respectively.
1025                                 #
1026                                 PORTAUDIO_LIBS="-L$portaudio_dir/lib -lportaudio"
1027                                 PORTAUDIO_INCLUDES="-I$portaudio_dir/include"
1028                         else
1029                                 PORTAUDIO_LIBS="-lportaudio"
1030                                 PORTAUDIO_INCLUDES=""
1031                         fi
1032                         AC_DEFINE(HAVE_LIBPORTAUDIO, 1, [Define to use libportaudio library])
1033                         want_portaudio=yes
1034                 ],[
1035                         #
1036                         # Restore the versions of CPPFLAGS, LDFLAGS, and
1037                         # LIBS before we added the "--with-portaudio="
1038                         # directory, as we didn't actually find portaudio
1039                         # there.
1040                         #
1041                         CPPFLAGS="$wireshark_save_CPPFLAGS"
1042                         LDFLAGS="$wireshark_save_LDFLAGS"
1043                         LIBS="$wireshark_save_LIBS"
1044                         PORTAUDIO_LIBS=""
1045                         # User requested --with-portaudio but it isn't available
1046                         if test "x$want_portaudio" = "xyes"
1047                         then
1048                                 AC_MSG_ERROR(Linking with libportaudio failed.)
1049                         fi
1050                         want_portaudio=no
1051                 ])
1052
1053         CPPFLAGS="$wireshark_save_CPPFLAGS"
1054         LDFLAGS="$wireshark_save_LDFLAGS"
1055         LIBS="$wireshark_save_LIBS"
1056         AC_SUBST(PORTAUDIO_LIBS)
1057         AC_SUBST(PORTAUDIO_INCLUDES)
1058
1059         fi
1060 ])
1061
1062 #
1063 # AC_WIRESHARK_RPM_CHECK
1064 # Looks for the rpm program, and checks to see if we can redefine "_topdir".
1065 #
1066 AC_DEFUN([AC_WIRESHARK_RPM_CHECK],
1067 [
1068         AC_CHECK_PROG(ac_cv_wireshark_have_rpm, rpm, "yes", "no")
1069         if test "x$ac_cv_wireshark_have_rpm" = "xyes"; then
1070                 rpm --define '_topdir /tmp' > /dev/null 2>&1
1071                 AC_MSG_CHECKING(to see if we can redefine _topdir)
1072                 if test $? -eq 0 ; then
1073                         AC_MSG_RESULT(yes)
1074                         HAVE_RPM=yes
1075                 else
1076                         AC_MSG_RESULT(no.  You'll have to build packages manually.)
1077                         HAVE_RPM=no
1078                 fi
1079         fi
1080 ])
1081
1082 #
1083 # AC_WIRESHARK_GNU_SED_CHECK
1084 # Checks if GNU sed is the first sed in PATH.
1085 #
1086 AC_DEFUN([AC_WIRESHARK_GNU_SED_CHECK],
1087 [
1088         AC_MSG_CHECKING(for GNU sed as first sed in PATH)
1089         if  ( sh -c "sed --version" </dev/null 2> /dev/null | grep "GNU sed" 2>&1 > /dev/null ) ;  then
1090                 AC_MSG_RESULT(yes)
1091                 HAVE_GNU_SED=yes
1092         else
1093                 AC_MSG_RESULT(no)
1094                 HAVE_GNU_SED=no
1095         fi
1096 ])
1097
1098 #
1099 # AC_WIRESHARK_C_ARES_CHECK
1100 #
1101 AC_DEFUN([AC_WIRESHARK_C_ARES_CHECK],
1102 [
1103         want_c_ares=defaultyes
1104
1105         if test "x$want_c_ares" = "xdefaultyes"; then
1106                 want_c_ares=yes
1107                 if test "x$ac_cv_enable_usr_local" = "xyes" ; then
1108                         withval=/usr/local
1109                         if test -d "$withval"; then
1110                                 AC_WIRESHARK_ADD_DASH_L(LDFLAGS, ${withval}/lib)
1111                         fi
1112                 fi
1113         fi
1114
1115         if test "x$want_c_ares" = "xyes"; then
1116                 AC_CHECK_LIB(cares, ares_init,
1117                   [
1118                     C_ARES_LIBS=-lcares
1119                 AC_DEFINE(HAVE_C_ARES, 1, [Define to use c-ares library])
1120                 have_good_c_ares=yes
1121                   ],, $SOCKET_LIBS $NSL_LIBS
1122                 )
1123         else
1124                 AC_MSG_RESULT(not required)
1125         fi
1126 ])
1127
1128
1129 #
1130 # AC_WIRESHARK_ADNS_CHECK
1131 #
1132 AC_DEFUN([AC_WIRESHARK_ADNS_CHECK],
1133 [
1134         want_adns=defaultyes
1135
1136         if test "x$want_adns" = "xdefaultyes"; then
1137                 want_adns=yes
1138                 if test "x$ac_cv_enable_usr_local" = "xyes" ; then
1139                         withval=/usr/local
1140                         if test -d "$withval"; then
1141                                 AC_WIRESHARK_ADD_DASH_L(LDFLAGS, ${withval}/lib)
1142                         fi
1143                 fi
1144         fi
1145
1146         if test "x$want_adns" = "xyes"; then
1147                 AC_CHECK_LIB(adns, adns_init,
1148                   [
1149                     ADNS_LIBS=-ladns
1150                     AC_DEFINE(HAVE_GNU_ADNS, 1, [Define to use GNU ADNS library])
1151                     have_good_adns=yes
1152                   ],, $SOCKET_LIBS $NSL_LIBS
1153                 )
1154         else
1155                 AC_MSG_RESULT(not required)
1156         fi
1157 ])
1158
1159
1160 #
1161 # AC_WIRESHARK_LIBCAP_CHECK
1162 #
1163 AC_DEFUN([AC_WIRESHARK_LIBCAP_CHECK],
1164 [
1165         want_libcap=defaultyes
1166
1167         if test "x$want_libcap" = "xdefaultyes"; then
1168                 want_libcap=yes
1169                 if test "x$ac_cv_enable_usr_local" = "xyes" ; then
1170                         withval=/usr/local
1171                         if test -d "$withval"; then
1172                                 AC_WIRESHARK_ADD_DASH_L(LDFLAGS, ${withval}/lib)
1173                         fi
1174                 fi
1175         fi
1176
1177         if test "x$want_libcap" = "xyes"; then
1178                 AC_CHECK_LIB(cap, cap_set_flag,
1179                   [
1180                     LIBCAP_LIBS=-lcap
1181                     AC_DEFINE(HAVE_LIBCAP, 1, [Define to use the libcap library])
1182                     have_good_libcap=yes
1183                   ],,
1184                 )
1185         else
1186                 AC_MSG_RESULT(not required)
1187         fi
1188 ])
1189
1190
1191 #
1192 # AC_WIRESHARK_KRB5_CHECK
1193 #
1194 AC_DEFUN([AC_WIRESHARK_KRB5_CHECK],
1195 [
1196         wireshark_save_CPPFLAGS="$CPPFLAGS"
1197         if test "x$krb5_dir" != "x"
1198         then
1199           #
1200           # The user specified a directory in which kerberos resides,
1201           # so add the "include" subdirectory of that directory to
1202           # the include file search path and the "lib" subdirectory
1203           # of that directory to the library search path.
1204           #
1205           # XXX - if there's also a kerberos in a directory that's
1206           # already in CPPFLAGS or LDFLAGS, this won't make us find
1207           # the version in the specified directory, as the compiler
1208           # and/or linker will search that other directory before it
1209           # searches the specified directory.
1210           #
1211           CPPFLAGS="$CPPFLAGS -I$krb5_dir/include"
1212           ac_heimdal_version=`grep heimdal $krb5_dir/include/krb5.h | head -n 1 | sed 's/^.*heimdal.*$/HEIMDAL/'`
1213           # MIT Kerberos moved krb5.h to krb5/krb5.h starting with release 1.5
1214           ac_mit_version_olddir=`grep 'Massachusetts' $krb5_dir/include/krb5.h | head -n 1 | sed 's/^.*Massachusetts.*$/MIT/'`
1215           ac_mit_version_newdir=`grep 'Massachusetts' $krb5_dir/include/krb5/krb5.h | head -n 1 | sed 's/^.*Massachusetts.*$/MIT/'`
1216           ac_krb5_version="$ac_heimdal_version$ac_mit_version_olddir$ac_mit_version_newdir"
1217           if test "x$ac_krb5_version" = "xHEIMDAL"
1218           then
1219               KRB5_LIBS="-L$krb5_dir/lib -lkrb5 -lasn1 $SSL_LIBS -lroken -lcrypt"
1220           else
1221               KRB5_LIBS="-L$krb5_dir/lib -lkrb5 -lk5crypto -lcom_err"
1222           fi
1223           if test "x$ac_krb5_version" = "xMIT"
1224           then
1225             AC_DEFINE(HAVE_MIT_KERBEROS, 1, [Define to use MIT kerberos])
1226           fi
1227         else
1228           AC_PATH_TOOL(KRB5_CONFIG, krb5-config)
1229           if test -x "$KRB5_CONFIG"
1230           then
1231             KRB5_FLAGS=`"$KRB5_CONFIG" --cflags`
1232             KRB5_LIBS=`"$KRB5_CONFIG" --libs`
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, so you must specify --with-ssl])
1255                 fi
1256                 ;;
1257             esac
1258             ac_krb5_version=`"$KRB5_CONFIG" --version | head -n 1 | sed -e 's/^.*heimdal.*$/HEIMDAL/' -e 's/^Kerberos .*$/MIT/' -e 's/^Solaris 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                 wireshark_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 CPPFLAGS from before we
1369                         # 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                         CPPFLAGS="$wireshark_save_CPPFLAGS"
1373                         KRB5_LIBS=""
1374                         want_krb5=no
1375                     fi
1376                 else
1377                     #
1378                     # We can link with Kerberos; see whether krb5.h
1379                     # defines KEYTYPE_ARCFOUR_56 (where "defines" means
1380                     # "as a #define or as an enum member).
1381                     #
1382                     AC_MSG_CHECKING([whether krb5.h defines KEYTYPE_ARCFOUR_56])
1383                     AC_COMPILE_IFELSE(
1384                       [
1385                         AC_LANG_SOURCE(
1386                           [[
1387                             #include <krb5.h>
1388                             #include <stdio.h>
1389
1390                             main()
1391                             {
1392                               printf("%u\n", KEYTYPE_ARCFOUR_56);
1393                             }
1394                           ]])
1395                       ],
1396                       [
1397                         AC_MSG_RESULT(yes)
1398                         AC_DEFINE(HAVE_KEYTYPE_ARCFOUR_56, 1, [Define if krb5.h defines KEYTYPE_ARCFOUR_56])
1399                       ],
1400                       [
1401                         AC_MSG_RESULT(no)
1402                       ])
1403                 fi
1404                 LIBS="$wireshark_save_LIBS"
1405             else
1406                 #
1407                 # It's not Heimdal or MIT.
1408                 #
1409                 AC_MSG_RESULT(no)
1410                 if test "x$want_krb5" = "xyes"
1411                 then
1412                     #
1413                     # The user tried to force us to use the library,
1414                     # but we can't do so; report an error.
1415                     #
1416                     AC_MSG_ERROR(Kerberos not found)
1417                 else
1418                     #
1419                     # Restore the versions of CPPFLAGS from before we
1420                     # added the flags for Kerberos.
1421                     #
1422                     AC_MSG_RESULT(Kerberos not found - disabling dissection for some kerberos data in packet decoding)
1423                     CPPFLAGS="$wireshark_save_CPPFLAGS"
1424                     KRB5_LIBS=""
1425                     want_krb5=no
1426                 fi
1427             fi
1428         else
1429             #
1430             # The user asked us not to use Kerberos, or they didn't
1431             # say whether they wanted us to use it but we found
1432             # that we couldn't.
1433             #
1434             # Restore the versions of CPPFLAGS from before we added
1435             # the flags for Kerberos.
1436             #
1437             CPPFLAGS="$wireshark_save_CPPFLAGS"
1438             KRB5_LIBS=""
1439             want_krb5=no
1440         fi
1441         AC_SUBST(KRB5_LIBS)
1442 ])
1443
1444 #
1445 # AC_WIRESHARK_GEOIP_CHECK
1446 #
1447 AC_DEFUN([AC_WIRESHARK_GEOIP_CHECK],
1448 [
1449         want_geoip=defaultyes
1450
1451         if test "x$want_geoip" = "xdefaultyes"; then
1452                 want_geoip=yes
1453                 if test "x$ac_cv_enable_usr_local" = "xyes" ; then
1454                         withval=/usr/local
1455                         if test -d "$withval"; then
1456                                 AC_WIRESHARK_ADD_DASH_L(LDFLAGS, ${withval}/lib)
1457                         fi
1458                 fi
1459         fi
1460
1461         if test "x$want_geoip" = "xyes"; then
1462                 AC_CHECK_LIB(GeoIP, GeoIP_new,
1463                   [
1464                     GEOIP_LIBS=-lGeoIP
1465                 AC_DEFINE(HAVE_GEOIP, 1, [Define to use GeoIP library])
1466                 have_good_geoip=yes
1467                   ],,
1468                 )
1469                 if test "x$have_good_geoip" = "xyes"; then
1470                         AC_CHECK_LIB(GeoIP, GeoIP_country_name_by_ipnum_v6,
1471                           [
1472                                 AC_DEFINE(HAVE_GEOIP_V6, 1, [Define if GeoIP supports IPv6 (GeoIP 1.4.5 and later)])
1473                           ],,
1474                         )
1475                 fi
1476         else
1477                 AC_MSG_RESULT(not required)
1478         fi
1479 ])
1480
1481 #AC_WIRESHARK_LDFLAGS_CHECK
1482 #
1483 # $1 : ldflag(s) to test
1484 #
1485 # We attempt to compile and link a test program with the specified linker
1486 # flag. The defined flag is added to LDFLAGS only if the link succeeds.
1487 #
1488 AC_DEFUN([AC_WIRESHARK_LDFLAGS_CHECK],
1489 [LD_OPTION="$1"
1490 AC_MSG_CHECKING(whether we can add $LD_OPTION to LDFLAGS)
1491 LDFLAGS_saved="$LDFLAGS"
1492 LDFLAGS="$LDFLAGS $LD_OPTION"
1493 AC_LINK_IFELSE(
1494   [
1495     AC_LANG_SOURCE([[main() { return; }]])
1496   ],
1497   [
1498     AC_MSG_RESULT(yes)
1499   ],
1500   [
1501     AC_MSG_RESULT(no)
1502     LDFLAGS="$LDFLAGS_saved"
1503   ])
1504 ])
1505
1506 dnl
1507 dnl Check whether, if you pass an unknown warning option to the
1508 dnl compiler, it fails or just prints a warning message and succeeds.
1509 dnl Set ac_wireshark_unknown_warning_option_error to the appropriate flag
1510 dnl to force an error if it would otherwise just print a warning message
1511 dnl and succeed.
1512 dnl
1513 AC_DEFUN([AC_WIRESHARK_CHECK_UNKNOWN_WARNING_OPTION_ERROR],
1514     [
1515         AC_MSG_CHECKING([whether the compiler fails when given an unknown warning option])
1516         save_CFLAGS="$CFLAGS"
1517         CFLAGS="$CFLAGS -Wxyzzy-this-will-never-succeed-xyzzy"
1518         AC_TRY_COMPILE(
1519             [],
1520             [return 0],
1521             [
1522                 AC_MSG_RESULT([no, adding -Werror=unknown-warning-option])
1523                 #
1524                 # We're assuming this is clang, where
1525                 # -Werror=unknown-warning-option is the appropriate
1526                 # option to force the compiler to fail.
1527                 #
1528                 ac_wireshark_unknown_warning_option_error="-Werror=unknown-warning-option"
1529             ],
1530             [
1531                 AC_MSG_RESULT([yes])
1532             ])
1533         CFLAGS="$save_CFLAGS"
1534     ])
1535
1536 dnl
1537 dnl Check whether, if you pass a valid-for-C-but-not-C++ option to the
1538 dnl compiler, it fails or just prints a warning message and succeeds.
1539 dnl Set ac_wireshark_non_cxx_warning_option_error to the appropriate flag
1540 dnl to force an error if it would otherwise just print a warning message
1541 dnl and succeed.
1542 dnl
1543 AC_DEFUN([AC_WIRESHARK_CHECK_NON_CXX_WARNING_OPTION_ERROR],
1544     [
1545         AC_MSG_CHECKING([whether the compiler fails when given an warning option not supported for C++])
1546         #
1547         # Some C+ compilers warn about -Wmissing-prototypes, and some warn
1548         # about -Wmissing-declarations.  Check both.
1549         #
1550         AC_LANG_PUSH(C++)
1551         save_CXXFLAGS="$CXXFLAGS"
1552         for flag in -Wmissing-prototypes -Wmissing-declarations; do
1553             CXXFLAGS="$save_CXXFLAGS $flag"
1554             AC_TRY_COMPILE(
1555                 [],
1556                 [return 0],
1557                 [
1558                     #
1559                     # We're assuming this is g++, where -Werror is the
1560                     # appropriate option to force the compiler to fail.
1561                     # Check whether it fails with -Werror.
1562                     #
1563                     # NOTE: it's important to put -Werror *before*
1564                     # the flag, otherwise, when it sees the flag,
1565                     # it doesn't yet know that warnings should be
1566                     # treated as errors, and doesn't treat the
1567                     # "that's C-only" warning as an error.
1568                     #
1569                     CXXFLAGS="$save_CXXFLAGS -Werror $flag"
1570                     AC_TRY_COMPILE(
1571                         [],
1572                         [return 0],
1573                         [
1574                             #
1575                             # No, so this option is actually OK
1576                             # with our C++ compiler.
1577                             #
1578                             # (We need an empty command here to
1579                             # prevent some versions of autoconf
1580                             # from generating a script with an
1581                             # empty "then" clause for an if statement.)
1582                             #
1583                             :
1584                         ],
1585                         [
1586                             #
1587                             # Yes, so we need -Werror for the tests.
1588                             #
1589                             ac_wireshark_non_cxx_warning_option_error="-Werror"
1590                             break
1591                         ])
1592                 ])
1593         done
1594         CXXFLAGS="$save_CXXFLAGS"
1595         AC_LANG_POP
1596         if test x$ac_wireshark_non_cxx_warning_option_error = x; then
1597             AC_MSG_RESULT([yes])
1598         else
1599             AC_MSG_RESULT([no, adding -Werror])
1600         fi
1601     ])
1602
1603 #
1604 # AC_WIRESHARK_COMPILER_FLAGS_CHECK
1605 #
1606 # $1 : flags to test
1607 # $2 : if supplied, C for C-only flags, CXX for C++-only flags
1608 # $3 : if supplied, a program to try to compile with the flag
1609 #      and, if the compile fails when -Werror is turned on,
1610 #      we don't add the flag - used for warning flags that
1611 #      issue incorrect or non-useful warnings with some
1612 #      compiler versions
1613 # $4 : must be supplied if $3 is supplied - a message describing
1614 #      for what the test program is testing
1615 #
1616 # The macro first determines if the compiler supports GCC-style flags.
1617 # Then it attempts to compile with the defined cflags.  The defined
1618 # flags are added to CFLAGS only if the compilation succeeds.
1619 #
1620 # We do this because not all such options are necessarily supported by
1621 # the version of the particular compiler we're using.
1622 #
1623 AC_DEFUN([AC_WIRESHARK_COMPILER_FLAGS_CHECK],
1624 [GCC_OPTION="$1"
1625 can_add_to_cflags=""
1626 can_add_to_cxxflags=""
1627 if test "x$ac_supports_gcc_flags" = "xyes" ; then
1628   if test "$2" != CXX ; then
1629     #
1630     # Not C++-only; if this can be added to the C compiler flags, add them.
1631     #
1632     # If the option begins with "-W", add
1633     # $ac_wireshark_unknown_warning_option_error to make sure that
1634     # we'll get an error if it's an unknown warning option; not all
1635     # compilers treat unknown warning options as errors (I'm looking at
1636     # you, clang).
1637     #
1638     # If the option begins with "-f" or "-m", add -Werror to make sure
1639     # that we'll get an error if we get "argument unused during compilation"
1640     # warnings, as those will either cause a failure for files compiled
1641     # with -Werror or annoying noise for files compiled without it.
1642     # (Yeah, you, clang.)
1643     #
1644     AC_MSG_CHECKING(whether we can add $GCC_OPTION to CFLAGS)
1645     CFLAGS_saved="$CFLAGS"
1646     if expr "x$GCC_OPTION" : "x-W.*" >/dev/null
1647     then
1648       CFLAGS="$CFLAGS $ac_wireshark_unknown_warning_option_error $GCC_OPTION"
1649     elif expr "x$GCC_OPTION" : "x-f.*" >/dev/null
1650     then
1651       CFLAGS="$CFLAGS -Werror $GCC_OPTION"
1652     elif expr "x$GCC_OPTION" : "x-m.*" >/dev/null
1653     then
1654       CFLAGS="$CFLAGS -Werror $GCC_OPTION"
1655     else
1656       CFLAGS="$CFLAGS $GCC_OPTION"
1657     fi
1658     AC_COMPILE_IFELSE(
1659       [
1660         AC_LANG_SOURCE([[int foo;]])
1661       ],
1662       [
1663         AC_MSG_RESULT(yes)
1664         can_add_to_cflags=yes
1665         #
1666         # OK, do we have a test program?  If so, check
1667         # whether it fails with this option and -Werror,
1668         # and, if so, don't include it.
1669         #
1670         # We test arg 4 here because arg 3 is a program which
1671         # could contain quotes (breaking the comparison).
1672         #
1673         if test "x$4" != "x" ; then
1674           CFLAGS="$CFLAGS -Werror"
1675           AC_MSG_CHECKING(whether $GCC_OPTION $4)
1676           AC_COMPILE_IFELSE(
1677             [AC_LANG_SOURCE($3)],
1678             [
1679               AC_MSG_RESULT(no)
1680               #
1681               # Remove "force an error for a warning" options, if we
1682               # added them, by setting CFLAGS to the saved value plus
1683               # just the new option.
1684               #
1685               CFLAGS="$CFLAGS_saved $GCC_OPTION"
1686               if test "$CC" = "$CC_FOR_BUILD"; then
1687                 #
1688                 # We're building the build tools with the same compiler
1689                 # with which we're building Wireshark, so add the flags
1690                 # to the flags for that compiler as well.
1691                 #
1692                 CFLAGS_FOR_BUILD="$CFLAGS_FOR_BUILD $GCC_OPTION"
1693               fi
1694             ],
1695             [
1696               AC_MSG_RESULT(yes)
1697               CFLAGS="$CFLAGS_saved"
1698             ])
1699         else
1700           #
1701           # Remove "force an error for a warning" options, if we
1702           # added them, by setting CFLAGS to the saved value plus
1703           # just the new option.
1704           #
1705           CFLAGS="$CFLAGS_saved $GCC_OPTION"
1706           if test "$CC" = "$CC_FOR_BUILD"; then
1707             #
1708             # We're building the build tools with the same compiler
1709             # with which we're building Wireshark, so add the flags
1710             # to the flags for that compiler as well.
1711             #
1712             CFLAGS_FOR_BUILD="$CFLAGS_FOR_BUILD $GCC_OPTION"
1713           fi
1714         fi
1715       ],
1716       [
1717         AC_MSG_RESULT(no)
1718         can_add_to_cflags=no
1719         CFLAGS="$CFLAGS_saved"
1720       ])
1721   fi
1722   if test "$2" != C ; then
1723     #
1724     # Not C-only; if this can be added to the C++ compiler flags, add them.
1725     #
1726     # If the option begins with "-W", add
1727     # $ac_wireshark_unknown_warning_option_error, as per the above, and
1728     # also add $ac_wireshark_non_cxx_warning_option_error, because at
1729     # lease some versions of g++ whine about -Wmissing-prototypes, the
1730     # fact that at least one of those versions refuses to warn about
1731     # function declarations without an earlier declaration nonwithstanding;
1732     # perhaps there's a reason not to warn about that with C++ even though
1733     # warning about it can be a Good Idea with C, but it's not obvious to
1734     # me).
1735     #
1736     # If the option begins with "-f" or "-m", add -Werror to make sure
1737     # that we'll get an error if we get "argument unused during compilation"
1738     # warnings, as those will either cause a failure for files compiled
1739     # with -Werror or annoying noise for files compiled without it.
1740     # (Yeah, you, clang++.)
1741     #
1742     AC_MSG_CHECKING(whether we can add $GCC_OPTION to CXXFLAGS)
1743     CXXFLAGS_saved="$CXXFLAGS"
1744     if expr "x$GCC_OPTION" : "x-W.*" >/dev/null
1745     then
1746       CXXFLAGS="$CXXFLAGS $ac_wireshark_unknown_warning_option_error $ac_wireshark_non_cxx_warning_option_error $GCC_OPTION"
1747     elif expr "x$GCC_OPTION" : "x-f.*" >/dev/null
1748     then
1749       CXXFLAGS="$CXXFLAGS -Werror $GCC_OPTION"
1750     elif expr "x$GCC_OPTION" : "x-m.*" >/dev/null
1751     then
1752       CXXFLAGS="$CXXFLAGS -Werror $GCC_OPTION"
1753     else
1754       CXXFLAGS="$CXXFLAGS $GCC_OPTION"
1755     fi
1756     AC_LANG_PUSH([C++])
1757     AC_COMPILE_IFELSE(
1758       [
1759         AC_LANG_SOURCE([[int foo;]])
1760       ],
1761       [
1762         AC_MSG_RESULT(yes)
1763         can_add_to_cxxflags=yes
1764         #
1765         # OK, do we have a test program?  If so, check
1766         # whether it fails with this option and -Werror,
1767         # and, if so, don't include it.
1768         #
1769         # We test arg 4 here because arg 3 is a program which
1770         # could contain quotes (breaking the comparison).
1771         #
1772         if test "x$4" != "x" ; then
1773           CXXFLAGS="$CXXFLAGS -Werror"
1774           AC_MSG_CHECKING(whether $GCC_OPTION $4)
1775           AC_COMPILE_IFELSE(
1776             [AC_LANG_SOURCE($3)],
1777             [
1778               AC_MSG_RESULT(no)
1779               #
1780               # Remove "force an error for a warning" options, if we
1781               # added them, by setting CXXFLAGS to the saved value plus
1782               # just the new option.
1783               #
1784               CXXFLAGS="$CXXFLAGS_saved $GCC_OPTION"
1785             ],
1786             [
1787               AC_MSG_RESULT(yes)
1788               CXXFLAGS="$CXXFLAGS_saved"
1789             ])
1790         else
1791           #
1792           # Remove "force an error for a warning" options, if we
1793           # added them, by setting CXXFLAGS to the saved value plus
1794           # just the new option.
1795           #
1796           CXXFLAGS="$CXXFLAGS_saved $GCC_OPTION"
1797         fi
1798       ],
1799       [
1800         AC_MSG_RESULT(no)
1801         can_add_to_cxxflags=no
1802         CXXFLAGS="$CXXFLAGS_saved"
1803       ])
1804     AC_LANG_POP([C++])
1805   fi
1806   if test "(" "$can_add_to_cflags" = "yes" -a "$can_add_to_cxxflags" = "no" ")" \
1807        -o "(" "$can_add_to_cflags" = "no" -a "$can_add_to_cxxflags" = "yes" ")"
1808   then
1809     #
1810     # Confusingly, some C++ compilers like -Wmissing-prototypes but
1811     # don't like -Wmissing-declarations and others like
1812     # -Wmissing-declarations but don't like -Wmissing-prototypes,
1813     # the fact that the corresponding C compiler likes both.  Don't
1814     # warn about them.
1815     #
1816     if test "(" x$GCC_OPTION != x-Wmissing-prototypes ")" \
1817          -a "(" x$GCC_OPTION != x-Wmissing-declarations ")"
1818     then
1819        AC_MSG_WARN([$CC and $CXX appear to be a mismatched pair])
1820     fi
1821   fi
1822 fi
1823 ])
1824
1825 # AC_WIRESHARK_GCC_FORTIFY_SOURCE_CHECK
1826 #
1827 # Checks if '-D_FORTIFY_SOURCE=...' is OK to use in CPPFLAGS.
1828 #  Use '-D_FORTIFY_SOURCE=...' in CPPFLAGS only if the GCC 'optimization level' is > 0.
1829 #  The use of '-D_FORTIFY_SOURCE=...' will cause a warning with at least some versions
1830 #    of glibc if the  GCC "optimization level" is 0 (default or -O or -O0)
1831 #    when using GCC to compile a source file which references the macro definition.
1832 #
1833 # See: http://gcc.gnu.org/ml/gcc-patches/2004-09/msg02055.html
1834 # See: http://sourceware.org/bugzilla/show_bug.cgi?id=13979
1835 #
1836 #   We'll use '-D_FORTIFY_SOURCE=2' only if there's no warning; Among other things this means
1837 #    that the  use of '-D_FORTIFY_SOURCE=2' with '-Werror' and '-O0' won't cause
1838 #    the compiler to stop on error.
1839 #   Assumption: CFLAGS already contains whatever optimization option including none) is
1840 #    to be used.
1841 #
1842
1843 AC_DEFUN([AC_WIRESHARK_GCC_FORTIFY_SOURCE_CHECK],
1844 [
1845 if test "x$GCC" = "xyes" -o "x$CC" = "xclang" ; then
1846   AC_MSG_CHECKING([whether -D_FORTIFY_SOURCE=... can be used (without generating a warning)])
1847   CFLAGS_saved="$CFLAGS"
1848   CPPFLAGS_saved="$CPPFLAGS"
1849   CFLAGS="$CFLAGS -Werror"
1850   CPPFLAGS="$CPPFLAGS -D_FORTIFY_SOURCE=2"
1851   AC_COMPILE_IFELSE([
1852     AC_LANG_SOURCE([[
1853                   #include <stdio.h>
1854                       int foo;
1855                   ]])],
1856                   [
1857                     AC_MSG_RESULT(yes)
1858                     #
1859                     # (CPPFLAGS contains _D_FORTIFY_SOURCE=2)
1860                     #
1861                   ],
1862                   [
1863                     AC_MSG_RESULT(no)
1864                     # Remove -D_FORTIFY_SOURCE=2
1865                     CPPFLAGS="$CPPFLAGS_saved"
1866                   ])
1867   CFLAGS="$CFLAGS_saved"
1868 fi
1869 ])
1870
1871 #
1872 # AC_WIRESHARK_OSX_INTEGRATION_CHECK
1873 #
1874 # Checks for the presence of OS X integration functions in the GTK+ framework
1875 # or as a separate library.
1876 #
1877 # GTK+ for MAC OS X now lives on www.gtk.org at:
1878 #
1879 #   http://www.gtk.org/download/macos.php
1880 #
1881 # Details on building with GTK-OSX are available at:
1882 #
1883 #   http://live.gnome.org/GTK%2B/OSX/Building
1884 #
1885 # The GTK-OSX library has been renamed to gtkmacintegration.
1886 # It was previously named igemacintegration.
1887 #
1888 # http://live.gnome.org/GTK%2B/OSX/Integration
1889 #    for the old Carbon-based integration functions
1890 #
1891 AC_DEFUN([AC_WIRESHARK_OSX_INTEGRATION_CHECK],
1892 [
1893         ac_save_CFLAGS="$CFLAGS"
1894         ac_save_LIBS="$LIBS"
1895         CFLAGS="$CFLAGS $GTK_CFLAGS"
1896         LIBS="$GTK_LIBS $LIBS"
1897
1898         #
1899         # Check for the new integration functions in a -lgtkmacintegration
1900         # library.
1901         #
1902         AC_CHECK_LIB(gtkmacintegration, gtkosx_application_set_menu_bar,
1903         [
1904                 AC_DEFINE(HAVE_GTKOSXAPPLICATION, 1,
1905                         [Define to 1 if -lgtkmacintegration includes the GtkOSXApplication Integration functions.])
1906                 have_ige_mac=yes
1907                 # We don't want gtk stuff in LIBS (which is reset below) so
1908                 # manually set GTK_LIBS (which is more appropriate)
1909                 GTK_LIBS="$GTK_LIBS -lgtkmacintegration"
1910         ])
1911
1912         if test x$have_ige_mac = x
1913         then
1914                 #
1915                 # Not found - check for the old integration functions in
1916                 # the Gtk framework.
1917                 #
1918                 AC_CHECK_LIB(Gtk, gtk_mac_menu_set_menu_bar,
1919                 [
1920                         AC_DEFINE(HAVE_IGE_MAC_INTEGRATION, 1,
1921                                 [Define to 1 if the the Gtk+ framework or a separate library includes the Imendio IGE Mac OS X Integration functions.])
1922                         have_ige_mac=yes
1923                         # We don't want gtk stuff in LIBS (which is reset below) so
1924                         # manually set GTK_LIBS (which is more appropriate)
1925                         GTK_LIBS="$GTK_LIBS -lGtk"
1926                 ])
1927         fi
1928
1929         if test x$have_ige_mac = x
1930         then
1931                 #
1932                 # Not found - check for the old integration functions in
1933                 # a -lgtkmacintegration library.
1934                 #
1935                 AC_CHECK_LIB(gtkmacintegration, gtk_mac_menu_set_menu_bar,
1936                 [
1937                         AC_DEFINE(HAVE_IGE_MAC_INTEGRATION, 1,
1938                                 [Define to 1 if the the Gtk+ framework or a separate library includes the Imendio IGE Mac OS X Integration functions.])
1939                         have_ige_mac=yes
1940                         # We don't want gtk stuff in LIBS (which is reset below) so
1941                         # manually set GTK_LIBS (which is more appropriate)
1942                         GTK_LIBS="$GTK_LIBS -lgtkmacintegration"
1943                 ])
1944         fi
1945         CFLAGS="$ac_save_CFLAGS"
1946         LIBS="$ac_save_LIBS"
1947 ])
1948
1949 # Based on AM_PATH_GTK in gtk-2.0.m4.
1950
1951 dnl AC_WIRESHARK_QT_MODULE_CHECK([MODULE, MINIMUM-VERSION,
1952 dnl     REQUESTED-MAJOR_VERSION, [ACTION-IF-FOUND, [ACTION-IF-NOT-FOUND]]])
1953 dnl Test for a particular Qt module and add the flags and libraries
1954 dnl for it to Qt_CFLAGS and Qt_LIBS.
1955 dnl
1956 AC_DEFUN([AC_WIRESHARK_QT_MODULE_CHECK],
1957 [
1958         #
1959         # Prior to Qt 5, modules were named QtXXX.
1960         # In Qt 5, they're named Qt5XXX.
1961         #
1962         # Try the Qt 5 version first.
1963         # (And be prepared to add Qt6 at some point....)
1964         #
1965         case "$3" in
1966
1967         yes|unspecified)
1968                 #
1969                 # Check for all versions of Qt we support.
1970                 #
1971                 modprefixes="Qt5 Qt"
1972                 major_version=""
1973                 #
1974                 # Version of the module we're checking for.
1975                 # Default to 4.0.0.
1976                 #
1977                 min_qt_version=ifelse([$2], ,4.0.0,$2)
1978                 ;;
1979
1980         4)
1981                 #
1982                 # Check for Qt 4.
1983                 #
1984                 modprefixes="Qt"
1985                 major_version=" version 4"
1986                 #
1987                 # Version of the module we're checking for.
1988                 # Default to 4.0.0.
1989                 #
1990                 min_qt_version=ifelse([$2], ,4.0.0,$2)
1991                 ;;
1992
1993         5)
1994                 #
1995                 # Check for Qt 5.
1996                 #
1997                 modprefixes="Qt5"
1998                 major_version=" version 5"
1999                 #
2000                 # Version of the module we're checking for.
2001                 # Default to 5.0.0.
2002                 #
2003                 min_qt_version=5.0.0
2004                 ;;
2005
2006         *)
2007                 AC_MSG_ERROR([Qt version $3 is not a known Qt version])
2008                 ;;
2009         esac
2010
2011         for modprefix in $modprefixes
2012         do
2013                 pkg_config_module="${modprefix}$1"
2014                 AC_MSG_CHECKING(for $pkg_config_module$major_version - version >= $min_qt_version)
2015                 if $PKG_CONFIG --atleast-version $min_qt_version $pkg_config_module; then
2016                         mod_version=`$PKG_CONFIG --modversion $pkg_config_module`
2017                         AC_MSG_RESULT(yes (version $mod_version))
2018                         Qt_CFLAGS="$Qt_CFLAGS `$PKG_CONFIG --cflags $pkg_config_module`"
2019                         Qt_LIBS="$Qt_LIBS `$PKG_CONFIG --libs $pkg_config_module`"
2020                         found_$1=yes
2021                         break
2022                 else
2023                         AC_MSG_RESULT(no)
2024                 fi
2025         done
2026
2027         if test "x$found_$1" = "xyes"; then
2028                 # Run Action-If-Found
2029                 ifelse([$4], , :, [$4])
2030         else
2031                 # Run Action-If-Not-Found
2032                 ifelse([$5], , :, [$5])
2033         fi
2034 ])
2035
2036 dnl AC_WIRESHARK_QT_CHECK([MINIMUM-VERSION, REQUESTED-MAJOR_VERSION,
2037 dnl     [ACTION-IF-FOUND, [ACTION-IF-NOT-FOUND]]])
2038 dnl Test for Qt and define Qt_CFLAGS and Qt_LIBS.
2039 dnl
2040 AC_DEFUN([AC_WIRESHARK_QT_CHECK],
2041 [
2042         no_qt=""
2043
2044         AC_PATH_TOOL(PKG_CONFIG, pkg-config, no)
2045
2046         if test x$PKG_CONFIG != xno ; then
2047                 if pkg-config --atleast-pkgconfig-version 0.7 ; then
2048                         :
2049                 else
2050                         echo *** pkg-config too old; version 0.7 or better required.
2051                         no_qt=yes
2052                         PKG_CONFIG=no
2053                 fi
2054         else
2055                 no_qt=yes
2056         fi
2057
2058         if test x"$no_qt" = x ; then
2059                 #
2060                 # OK, we have an adequate version of pkg-config.
2061                 #
2062                 # Check for the Core module; if we don't have that,
2063                 # we don't have Qt.
2064                 #
2065                 AC_WIRESHARK_QT_MODULE_CHECK(Core, $1, $2, , [no_qt=yes])
2066         fi
2067
2068         if test x"$no_qt" = x ; then
2069                 #
2070                 # We need the Gui module as well.
2071                 #
2072                 AC_WIRESHARK_QT_MODULE_CHECK(Gui, $1, $2, , [no_qt=yes])
2073         fi
2074
2075         if test x"$no_qt" = x ; then
2076                 #
2077                 # Qt 5.0 appears to move the widgets out of Qt GUI
2078                 # to Qt Widgets; look for the Widgets module, but
2079                 # don't fail if we don't have it.
2080                 #
2081                 AC_WIRESHARK_QT_MODULE_CHECK(Widgets, $1, $2)
2082
2083                 #
2084                 # Qt 5.0 also appears to move the printing support into
2085                 # the Qt PrintSupport module.
2086                 #
2087                 AC_WIRESHARK_QT_MODULE_CHECK(PrintSupport, $1, $2)
2088
2089                 #
2090                 # Qt 5.0 added multimedia widgets in the Qt
2091                 # MultimediaWidgets module.
2092                 #
2093                 AC_WIRESHARK_QT_MODULE_CHECK(MultimediaWidgets, $1, $2,
2094                         AC_DEFINE(QT_MULTIMEDIAWIDGETS_LIB, 1, [Define if we have QtMultimediaWidgets]))
2095
2096                 #
2097                 # While we're at it, look for QtMacExtras.  (Presumably
2098                 # if we're not building for OS X, it won't be present.)
2099                 #
2100                 # XXX - is there anything in QtX11Extras or QtWinExtras
2101                 # that we should be using?
2102                 #
2103                 AC_WIRESHARK_QT_MODULE_CHECK(MacExtras, $1, $2,
2104                         AC_DEFINE(QT_MACEXTRAS_LIB, 1, [Define if we have QtMacExtras]))
2105
2106                 AC_SUBST(Qt_LIBS)
2107
2108                 # Run Action-If-Found
2109                 ifelse([$3], , :, [$3])
2110         else
2111                 # Run Action-If-Not-Found
2112                 ifelse([$4], , :, [$4])
2113         fi
2114
2115 ])