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