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