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