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