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