Add CMake version.h dependency
[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                     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_DEFINE(HAVE_REMOTE, 1, [Define to 1 to enable remote
427               capturing feature in WinPcap library])
428     AC_CHECK_FUNCS(pcap_open)
429     if test $ac_cv_func_pcap_open = "yes" ; then
430         AC_DEFINE(HAVE_PCAP_REMOTE, 1,
431             [Define to 1 if you have WinPcap remote capturing support and prefer to use these new API features.])
432     fi
433     AC_CHECK_FUNCS(pcap_setsampling)
434     LIBS="$ac_save_LIBS"
435 ])
436
437 #
438 # AC_WIRESHARK_ZLIB_CHECK
439 #
440 AC_DEFUN([AC_WIRESHARK_ZLIB_CHECK],
441 [
442         AC_WIRESHARK_PUSH_FLAGS
443
444         if test "x$zlib_dir" != "x"
445         then
446           #
447           # The user specified a directory in which zlib resides,
448           # so add the "include" subdirectory of that directory to
449           # the include file search path and the "lib" subdirectory
450           # of that directory to the library search path.
451           #
452           # XXX - if there's also a zlib in a directory that's
453           # already in CPPFLAGS or LDFLAGS, this won't make us find
454           # the version in the specified directory, as the compiler
455           # and/or linker will search that other directory before it
456           # searches the specified directory.
457           #
458           CPPFLAGS="$CPPFLAGS -I$zlib_dir/include"
459           AC_WIRESHARK_ADD_DASH_L(LDFLAGS, $zlib_dir/lib)
460         fi
461
462         #
463         # Make sure we have "zlib.h".  If we don't, it means we probably
464         # don't have zlib, so don't use it.
465         #
466         AC_CHECK_HEADER(zlib.h,,
467           [
468             if test "x$zlib_dir" != "x"
469             then
470               #
471               # The user used "--with-zlib=" to specify a directory
472               # containing zlib, but we didn't find the header file
473               # there; that either means they didn't specify the
474               # right directory or are confused about whether zlib
475               # is, in fact, installed.  Report the error and give up.
476               #
477               AC_MSG_ERROR([zlib header not found in directory specified in --with-zlib])
478             else
479               if test "x$want_zlib" = "xyes"
480               then
481                 #
482                 # The user tried to force us to use the library, but we
483                 # couldn't find the header file; report an error.
484                 #
485                 AC_MSG_ERROR(Header file zlib.h not found.)
486               else
487                 #
488                 # We couldn't find the header file; don't use the
489                 # library, as it's probably not present.
490                 #
491                 want_zlib=no
492               fi
493             fi
494           ])
495
496         if test "x$want_zlib" != "xno"
497         then
498                 #
499                 # Well, we at least have the zlib header file.
500                 # We link with zlib to support uncompression of
501                 # gzipped network traffic, e.g. in an HTTP request
502                 # or response body.
503                 #
504                 if test "x$zlib_dir" != "x"
505                 then
506                   WS_CPPFLAGS="$WS_CPPFLAGS -I$zlib_dir/include"
507                   AC_WIRESHARK_ADD_DASH_L(WS_LDFLAGS, $zlib_dir/lib)
508                 fi
509                 LIBS="-lz $LIBS"
510                 AC_DEFINE(HAVE_ZLIB, 1, [Define to use zlib library])
511                 #
512                 # Check for "inflatePrime()" in zlib, which we need
513                 # in order to read compressed capture files.
514                 #
515                 AC_CHECK_FUNCS(inflatePrime)
516
517                 if test "x$ac_cv_func_inflatePrime" = "xyes" ; then
518                         #
519                         # Now check for "inflatePrime()" in zlib when
520                         # linking with the linker flags for GTK+
521                         # applications; people often grab XFree86 source
522                         # and build and install it on their systems,
523                         # and they appear sometimes to misconfigure
524                         # XFree86 so that, even on systems with zlib,
525                         # it assumes there is no zlib, so the XFree86
526                         # build process builds and installs its
527                         # own zlib in the X11 library directory.
528                         #
529                         # The zlib in at least some versions of XFree86
530                         # is an older version that may lack "inflatePrime()",
531                         # and that's the zlib with which Wireshark gets
532                         # linked, so the build of Wireshark fails.
533                         #
534                         AC_MSG_CHECKING([for inflatePrime missing when linking with X11])
535                         AC_TRY_LINK_FUNC(inflatePrime, AC_MSG_RESULT(no),
536                           [
537                             AC_MSG_RESULT(yes)
538                             AC_MSG_ERROR(old zlib found when linking with X11 - get rid of old zlib.)
539                           ])
540                 fi
541         fi
542
543         AC_WIRESHARK_POP_FLAGS
544 ])
545
546 #
547 # AC_WIRESHARK_LIBLUA_CHECK
548 #
549 # Sets $have_lua to yes or no.
550 # If it's yes, it also sets $LUA_CFLAGS and $LUA_LIBS.
551 AC_DEFUN([AC_WIRESHARK_LIBLUA_CHECK],[
552
553         AC_WIRESHARK_PUSH_FLAGS
554
555         if test "x$want_lua_dir" = "x"
556         then
557                 # The user didn't tell us where to find Lua.  Let's go look for it.
558
559                 # First, try the standard (pkg-config) way.
560                 # Unfortunately Lua's pkg-config file isn't standardly named.
561                 # Some distributions allow installation of multiple versions of
562                 # Lua at the same time.  On such systems each version has its
563                 # own package name.
564                 #
565                 # We use a for loop instead of giving all the package names to
566                 # PKG_CHECK_MODULES because doing the latter doesn't appear to
567                 # work reliably (some package names are not searched for).
568                 for pkg in "lua < 5.3" lua5.2 lua-5.2 lua52 lua5.1 lua-5.1 lua51 lua5.0 lua-5.0 lua50
569                 do
570                         AC_MSG_CHECKING(if you have $pkg)
571                         PKG_CHECK_EXISTS($pkg,
572                         [
573                          AC_MSG_RESULT(yes)
574                          have_lua=yes
575                         ],
576                         [
577                          AC_MSG_RESULT(no)
578                         ])
579
580                         if test "x$have_lua" = "xyes"
581                         then
582                                 PKG_WIRESHARK_CHECK_SYSTEM_MODULES(LUA, $pkg)
583                                 CPPFLAGS="$LUA_CFLAGS $CPPFLAGS"
584                                 AC_CHECK_HEADERS(lua.h lualib.h lauxlib.h)
585                                 break
586                         fi
587                 done
588         fi
589
590         if test "x$have_lua" != "xyes"
591         then
592                 # We don't have pkg-config or the user specified the path to
593                 # Lua (in $want_lua_dir).
594                 # Let's look for the header file.
595
596                 AC_MSG_CHECKING(for the location of lua.h)
597                 if test "x$want_lua_dir" = "x"
598                 then
599                         # The user didn't tell us where to look so we'll look in some
600                         # standard locations.
601                         want_lua_dir="/usr/local /usr $prefix"
602                 fi
603                 for dir in $want_lua_dir
604                 do
605                         if test -r "$dir/include/lua.h"
606                         then
607                                 header_dir="$dir/include"
608                                 lua_dir=$dir
609                                 break
610                         fi
611
612                         for ver in 5.2 52 5.1 51 5.0 50
613                         do
614                                 if test -r "$dir/include/lua$ver/lua.h"
615                                 then
616                                         header_dir="$dir/include/lua$ver"
617                                         lua_dir=$dir
618                                         break
619                                 fi
620                         done
621                 done
622
623                 if test "x$header_dir" = "x"
624                 then
625                         have_lua=no
626                         AC_MSG_RESULT(not found)
627                 else
628                         AC_MSG_RESULT($header_dir)
629
630                         AC_MSG_CHECKING(the Lua version)
631                         lua_ver=`$AWK AS_ESCAPE('/LUA_VERSION_NUM/ { print $NF; }' $header_dir/lua.h | sed 's/0/./')`
632
633                         if test "x$lua_ver" = "x5.3"
634                         then
635                                 # Wireshark doesn't compile with Lua 5.3 today
636                                 AC_MSG_RESULT($lua_ver - disabling Lua support)
637                                 have_lua=no
638                         else
639                                 AC_MSG_RESULT($lua_ver)
640
641                                 CPPFLAGS="$CPPFLAGS -I$header_dir"
642                                 AC_CHECK_HEADERS(lua.h lualib.h lauxlib.h, ,
643                                 [
644                                         have_lua=no
645                                 ])
646                         fi
647
648                         if test "x$have_lua" = "x"
649                         then
650                                 # Set LUA_CFLAGS
651                                 LUA_CFLAGS="-I$header_dir"
652
653                                 # We have the header files and they work.  Now let's check if we
654                                 # have the library and it works.
655                                 #
656                                 # XXX - if there's also a liblua in a directory that's
657                                 # already in CPPFLAGS or LDFLAGS, this won't make us find
658                                 # the version in the specified directory, as the compiler
659                                 # and/or linker will search that other directory before it
660                                 # searches the specified directory.
661                                 #
662                                 # XXX - lib64?
663                                 LDFLAGS="-L$lua_dir/lib $LDFLAGS"
664                                 AC_SEARCH_LIBS(luaL_openlibs, [lua-${lua_ver} lua${lua_ver} lua],
665                                 [
666                                         LUA_LIBS="-L$lua_dir/lib $ac_cv_search_luaL_openlibs -lm"
667                                         have_lua=yes
668                                 ],[
669                                         have_lua=no
670                                 ], -lm)
671                         fi
672                 fi
673         fi
674
675         AC_WIRESHARK_POP_FLAGS
676 ])
677
678 #
679 # AC_WIRESHARK_LIBPORTAUDIO_CHECK
680 #
681 AC_DEFUN([AC_WIRESHARK_LIBPORTAUDIO_CHECK],[
682
683         AC_WIRESHARK_PUSH_FLAGS
684         wireshark_save_LIBS="$LIBS"
685
686         if test "x$portaudio_dir" != "x"
687         then
688                 #
689                 # The user specified a directory in which libportaudio
690                 # resides, so add the "include" subdirectory of that directory to
691                 # the include file search path and the "lib" subdirectory
692                 # of that directory to the library search path.
693                 #
694                 # XXX - if there's also a libportaudio in a directory that's
695                 # already in CPPFLAGS or LDFLAGS, this won't make us find
696                 # the version in the specified directory, as the compiler
697                 # and/or linker will search that other directory before it
698                 # searches the specified directory.
699                 #
700                 CPPFLAGS="$CPPFLAGS -I$portaudio_dir/include"
701                 LDFLAGS="$LDFLAGS -L$portaudio_dir/lib"
702         fi
703         LIBS="-lportaudio $LIBS"
704
705         #
706         # Make sure we have "portaudio.h".  If we don't, it means we probably
707         # don't have libportaudio, so don't use it.
708         #
709         AC_CHECK_HEADERS(portaudio.h,,
710         [
711                 if test "x$portaudio_dir" != "x"
712                 then
713                         #
714                         # The user used "--with-portaudio=" to specify a directory
715                         # containing libportaudio, but we didn't find the header file
716                         # there; that either means they didn't specify the
717                         # right directory or are confused about whether libportaudio
718                         # is, in fact, installed.  Report the error and give up.
719                         #
720                         AC_MSG_ERROR([libportaudio header not found in directory specified in --with-portaudio])
721                 else
722                         if test "x$want_portaudio" = "xyes"
723                         then
724                                 #
725                                 # The user tried to force us to use the library, but we
726                                 # couldn't find the header file; report an error.
727                                 #
728                                 AC_MSG_ERROR(Header file portaudio.h not found.)
729                         else
730                                 #
731                                 # We couldn't find the header file; don't use the
732                                 # library, as it's probably not present.
733                                 #
734                                 want_portaudio=no
735                         fi
736                 fi
737         ])
738
739         #
740         # Check whether we have the right version of portaudio
741         #
742         if test "x$want_portaudio" != "xno"
743         then
744                 AC_CHECK_TYPE(PortAudioStream,
745                 AC_DEFINE(PORTAUDIO_API_1, 1, [Define if we are using version of of the Portaudio library API]),
746                 ,
747                 [#include <portaudio.h>])
748         fi
749
750         if test "x$want_portaudio" != "xno"
751         then
752                 #
753                 # Well, we at least have the portaudio header file.
754                 #
755                 # let's check if the libs are there
756                 #
757                 PORTAUDIO_LIBS=""
758                 PORTAUDIO_INCLUDES=""
759
760                 AC_CHECK_LIB(portaudio, Pa_Initialize,
761                 [
762                         if test "x$portaudio_dir" != "x"
763                         then
764                                 #
765                                 # Put the "-I" and "-L" flags for portaudio
766                                 # into PORTAUDIO_INCLUDES and PORTAUDIO_LIBS,
767                                 # respectively.
768                                 #
769                                 PORTAUDIO_LIBS="-L$portaudio_dir/lib -lportaudio"
770                                 PORTAUDIO_INCLUDES="-I$portaudio_dir/include"
771                         else
772                                 PORTAUDIO_LIBS="-lportaudio"
773                         fi
774                         AC_DEFINE(HAVE_LIBPORTAUDIO, 1, [Define to use libportaudio library])
775                         want_portaudio=yes
776                 ],[
777                         # User requested --with-portaudio but it isn't available
778                         if test "x$want_portaudio" = "xyes"
779                         then
780                                 AC_MSG_ERROR(Linking with libportaudio failed.)
781                         fi
782                         want_portaudio=no
783                 ])
784                 AC_SUBST(PORTAUDIO_LIBS)
785                 AC_SUBST(PORTAUDIO_INCLUDES)
786
787         fi
788
789         LIBS="$wireshark_save_LIBS"
790         AC_WIRESHARK_POP_FLAGS
791 ])
792
793 #
794 # AC_WIRESHARK_RPM_CHECK
795 # Looks for the rpm program, and checks to see if we can redefine "_topdir".
796 #
797 AC_DEFUN([AC_WIRESHARK_RPM_CHECK],
798 [
799         AC_CHECK_PROG(ac_cv_wireshark_have_rpm, rpm, "yes", "no")
800         if test "x$ac_cv_wireshark_have_rpm" = "xyes"; then
801                 rpm --define '_topdir /tmp' > /dev/null 2>&1
802                 AC_MSG_CHECKING(to see if we can redefine _topdir)
803                 if test $? -eq 0 ; then
804                         AC_MSG_RESULT(yes)
805                         HAVE_RPM=yes
806                 else
807                         AC_MSG_RESULT(no.  You'll have to build packages manually.)
808                         HAVE_RPM=no
809                 fi
810         fi
811 ])
812
813
814 #
815 # AC_WIRESHARK_C_ARES_CHECK
816 #
817 AC_DEFUN([AC_WIRESHARK_C_ARES_CHECK],
818 [
819         want_c_ares=defaultyes
820
821         if test "x$want_c_ares" = "xdefaultyes"; then
822                 want_c_ares=yes
823         fi
824
825         if test "x$want_c_ares" = "xyes"; then
826                 AC_CHECK_LIB(cares, ares_init,
827                   [
828                     C_ARES_LIBS=-lcares
829                     AC_DEFINE(HAVE_C_ARES, 1, [Define to use c-ares library])
830                     have_good_c_ares=yes
831                   ])
832         else
833                 AC_MSG_RESULT(not required)
834         fi
835 ])
836
837
838 #
839 # AC_WIRESHARK_LIBCAP_CHECK
840 #
841 AC_DEFUN([AC_WIRESHARK_LIBCAP_CHECK],
842 [
843         want_libcap=defaultyes
844
845         if test "x$want_libcap" = "xdefaultyes"; then
846                 want_libcap=yes
847         fi
848
849         if test "x$want_libcap" = "xyes"; then
850                 AC_CHECK_LIB(cap, cap_set_flag,
851                   [
852                     LIBCAP_LIBS=-lcap
853                     AC_DEFINE(HAVE_LIBCAP, 1, [Define to use the libcap library])
854                     have_good_libcap=yes
855                   ],,
856                 )
857         else
858                 AC_MSG_RESULT(not required)
859         fi
860 ])
861
862
863 #
864 # AC_WIRESHARK_KRB5_CHECK
865 #
866 AC_DEFUN([AC_WIRESHARK_KRB5_CHECK],
867 [
868         AC_WIRESHARK_PUSH_FLAGS
869         wireshark_save_LIBS="$LIBS"
870
871         if test "x$krb5_dir" != "x"
872         then
873           #
874           # The user specified a directory in which kerberos resides,
875           # so add the "include" subdirectory of that directory to
876           # the include file search path and the "lib" subdirectory
877           # of that directory to the library search path.
878           #
879           # XXX - if there's also a kerberos in a directory that's
880           # already in CPPFLAGS or LDFLAGS, this won't make us find
881           # the version in the specified directory, as the compiler
882           # and/or linker will search that other directory before it
883           # searches the specified directory.
884           #
885           KRB5_CFLAGS="-I$krb5_dir/include"
886           ac_heimdal_version=`grep heimdal $krb5_dir/include/krb5.h | head -n 1 | sed 's/^.*heimdal.*$/HEIMDAL/'`
887           # MIT Kerberos moved krb5.h to krb5/krb5.h starting with release 1.5
888           ac_mit_version_olddir=`grep 'Massachusetts' $krb5_dir/include/krb5.h | head -n 1 | sed 's/^.*Massachusetts.*$/MIT/'`
889           ac_mit_version_newdir=`grep 'Massachusetts' $krb5_dir/include/krb5/krb5.h | head -n 1 | sed 's/^.*Massachusetts.*$/MIT/'`
890           ac_krb5_version="$ac_heimdal_version$ac_mit_version_olddir$ac_mit_version_newdir"
891           if test "x$ac_krb5_version" = "xHEIMDAL"
892           then
893               KRB5_LIBS="-L$krb5_dir/lib -lkrb5 -lasn1 $SSL_LIBS -lroken -lcrypt"
894           else
895               KRB5_LIBS="-L$krb5_dir/lib -lkrb5 -lk5crypto -lcom_err"
896           fi
897           if test "x$ac_krb5_version" = "xMIT"
898           then
899             AC_DEFINE(HAVE_MIT_KERBEROS, 1, [Define to use MIT kerberos])
900           fi
901         else
902           AC_PATH_TOOL(KRB5_CONFIG, krb5-config)
903           if test -x "$KRB5_CONFIG"
904           then
905             KRB5_CFLAGS=`"$KRB5_CONFIG" --cflags`
906             KRB5_LIBS=`"$KRB5_CONFIG" --libs`
907             #
908             # If -lcrypto is in KRB5_FLAGS, we require it to build
909             # with Heimdal/MIT.  We don't want to built with it by
910             # default, due to annoying license incompatibilities
911             # between the OpenSSL license and the GPL, so:
912             #
913             #   if SSL_LIBS is set to a non-empty string, we
914             #   remove -lcrypto from KRB5_LIBS and replace
915             #   it with SSL_LIBS;
916             #
917             #   if SSL_LIBS is not set to a non-empty string
918             #   we fail with an appropriate error message.
919             #
920             case "$KRB5_LIBS" in
921             *-lcrypto*)
922                 if test ! -z "$SSL_LIBS"
923                 then
924                     KRB5_LIBS=`echo $KRB5_LIBS | sed 's/-lcrypto//'`
925                     KRB5_LIBS="$KRB5_LIBS $SSL_LIBS"
926                 else
927                     AC_MSG_ERROR([Kerberos library requires -lcrypto, so you must specify --with-ssl])
928                 fi
929                 ;;
930             esac
931             ac_krb5_version=`"$KRB5_CONFIG" --version | head -n 1 | sed -e 's/^.*heimdal.*$/HEIMDAL/' -e 's/^Kerberos .*$/MIT/' -e 's/^Solaris Kerberos .*$/MIT/'`
932           fi
933         fi
934
935         CPPFLAGS="$CPPFLAGS $KRB5_CFLAGS"
936
937         #
938         # Make sure we have "krb5.h".  If we don't, it means we probably
939         # don't have kerberos, so don't use it.
940         #
941         AC_CHECK_HEADER(krb5.h,,
942           [
943             if test "x$krb5_dir" != "x"
944             then
945               #
946               # The user used "--with-krb5=" to specify a directory
947               # containing kerberos, but we didn't find the header file
948               # there; that either means they didn't specify the
949               # right directory or are confused about whether kerberos
950               # is, in fact, installed.  Report the error and give up.
951               #
952               AC_MSG_ERROR([kerberos header not found in directory specified in --with-krb5])
953             else
954               if test "x$want_krb5" = "xyes"
955               then
956                 #
957                 # The user tried to force us to use the library, but we
958                 # couldn't find the header file; report an error.
959                 #
960                 AC_MSG_ERROR(Header file krb5.h not found.)
961               else
962                 #
963                 # We couldn't find the header file; don't use the
964                 # library, as it's probably not present.
965                 #
966                 KRB5_CFLAGS=""
967                 KRB5_LIBS=""
968                 want_krb5=no
969                 AC_MSG_RESULT(No Heimdal or MIT header found - disabling dissection for some kerberos data in packet decoding)
970               fi
971             fi
972           ])
973
974         if test "x$want_krb5" != "xno"
975         then
976             #
977             # Well, we at least have the krb5 header file.
978             # Check whether this is Heimdal or MIT.
979             #
980             AC_MSG_CHECKING(whether the Kerberos library is Heimdal or MIT)
981             if test "x$ac_krb5_version" = "xHEIMDAL" -o "x$ac_krb5_version" = "xMIT"
982             then
983                 #
984                 # Yes.
985                 # Check whether we have krb5_kt_resolve - and whether
986                 # we need to link with -lresolv when linking with
987                 # the Kerberos library.
988                 #
989                 AC_MSG_RESULT($ac_krb5_version)
990                 found_krb5_kt_resolve=no
991                 for extras in "" "-lresolv"
992                 do
993                     LIBS="$KRB5_LIBS $extras $wireshark_save_LIBS"
994                     if test -z "$extras"
995                     then
996                         AC_MSG_CHECKING([whether $ac_krb5_version includes krb5_kt_resolve])
997                     else
998                         AC_MSG_CHECKING([whether $ac_krb5_version includes krb5_kt_resolve (linking with $extras)])
999                     fi
1000                     AC_TRY_LINK(
1001                         [
1002                         ],
1003                         [
1004                             krb5_kt_resolve();
1005                         ],
1006                         [
1007                             #
1008                             # We found "krb5_kt_resolve()".
1009                             #
1010                             AC_MSG_RESULT(yes)
1011                             if test -n "$extras"; then
1012                               KRB5_LIBS="$KRB5_LIBS $extras"
1013                             fi
1014                             AC_DEFINE(HAVE_KERBEROS, 1, [Define to use kerberos])
1015                             if test "x$ac_krb5_version" = "xHEIMDAL"
1016                             then
1017                                 AC_DEFINE(HAVE_HEIMDAL_KERBEROS, 1, [Define to use heimdal kerberos])
1018                             elif test "x$ac_krb5_version" = "xMIT"
1019                             then
1020                                 AC_DEFINE(HAVE_MIT_KERBEROS, 1, [Define to use MIT kerberos])
1021                             fi
1022                             found_krb5_kt_resolve=yes
1023                             break
1024                         ],
1025                         [
1026                             AC_MSG_RESULT(no)
1027                         ])
1028                 done
1029                 if test "$found_krb5_kt_resolve" = no
1030                 then
1031                     #
1032                     # We didn't find "krb5_kt_resolve()" in the
1033                     # Kerberos library, even when we tried linking
1034                     # with -lresolv; we can't link with kerberos.
1035                     #
1036                     if test "x$want_krb5" = "xyes"
1037                     then
1038                         #
1039                         # The user tried to force us to use the library,
1040                         # but we can't do so; report an error.
1041                         #
1042                         AC_MSG_ERROR(Usable $ac_krb5_version not found)
1043                     else
1044                         #
1045                         # Don't use
1046                         #
1047                         AC_MSG_RESULT(Usable $ac_krb5_version not found - disabling dissection for some kerberos data in packet decoding)
1048                         KRB5_CFLAGS=""
1049                         KRB5_LIBS=""
1050                         want_krb5=no
1051                     fi
1052                 else
1053                     #
1054                     # We can link with Kerberos; see whether krb5.h
1055                     # defines KEYTYPE_ARCFOUR_56 (where "defines" means
1056                     # "as a #define or as an enum member).
1057                     #
1058                     AC_MSG_CHECKING([whether krb5.h defines KEYTYPE_ARCFOUR_56])
1059                     AC_COMPILE_IFELSE(
1060                       [
1061                         AC_LANG_SOURCE(
1062                           [[
1063                             #include <krb5.h>
1064                             #include <stdio.h>
1065
1066                             main()
1067                             {
1068                               printf("%u\n", KEYTYPE_ARCFOUR_56);
1069                             }
1070                           ]])
1071                       ],
1072                       [
1073                         AC_MSG_RESULT(yes)
1074                         AC_DEFINE(HAVE_KEYTYPE_ARCFOUR_56, 1, [Define if krb5.h defines KEYTYPE_ARCFOUR_56])
1075                       ],
1076                       [
1077                         AC_MSG_RESULT(no)
1078                       ])
1079                 fi
1080             else
1081                 #
1082                 # It's not Heimdal or MIT.
1083                 #
1084                 AC_MSG_RESULT(no)
1085                 if test "x$want_krb5" = "xyes"
1086                 then
1087                     #
1088                     # The user tried to force us to use the library,
1089                     # but we can't do so; report an error.
1090                     #
1091                     AC_MSG_ERROR(Kerberos not found)
1092                 else
1093                     #
1094                     # Don't use.
1095                     #
1096                     AC_MSG_RESULT(Kerberos not found - disabling dissection for some kerberos data in packet decoding)
1097                     KRB5_CFLAGS=""
1098                     KRB5_LIBS=""
1099                     want_krb5=no
1100                 fi
1101             fi
1102         else
1103             #
1104             # The user asked us not to use Kerberos, or they didn't
1105             # say whether they wanted us to use it but we found
1106             # that we couldn't.
1107             #
1108             KRB5_CFLAGS=""
1109             KRB5_LIBS=""
1110             want_krb5=no
1111         fi
1112         AC_SUBST(KRB5_CFLAGS)
1113         AC_SUBST(KRB5_LIBS)
1114
1115         LIBS="$wireshark_save_LIBS"
1116         AC_WIRESHARK_POP_FLAGS
1117 ])
1118
1119 #
1120 # AC_WIRESHARK_GEOIP_CHECK
1121 #
1122 AC_DEFUN([AC_WIRESHARK_GEOIP_CHECK],
1123 [
1124         want_geoip=defaultyes
1125
1126         if test "x$want_geoip" = "xdefaultyes"; then
1127                 want_geoip=yes
1128         fi
1129
1130         if test "x$want_geoip" = "xyes"; then
1131                 AC_CHECK_LIB(GeoIP, GeoIP_new,
1132                   [
1133                     GEOIP_LIBS=-lGeoIP
1134                 AC_DEFINE(HAVE_GEOIP, 1, [Define to use GeoIP library])
1135                 have_good_geoip=yes
1136                   ],,
1137                 )
1138                 if test "x$have_good_geoip" = "xyes"; then
1139                         AC_CHECK_LIB(GeoIP, GeoIP_country_name_by_ipnum_v6,
1140                           [
1141                                 AC_DEFINE(HAVE_GEOIP_V6, 1, [Define if GeoIP supports IPv6 (GeoIP 1.4.5 and later)])
1142                           ],,
1143                         )
1144                 fi
1145         else
1146                 AC_MSG_RESULT(not required)
1147         fi
1148 ])
1149
1150 #
1151 # AC_WIRESHARK_LIBSSH_CHECK
1152 #
1153 AC_DEFUN([AC_WIRESHARK_LIBSSH_CHECK],
1154 [
1155         want_libssh=defaultyes
1156
1157         if test "x$want_libssh" = "xdefaultyes"; then
1158                 want_libssh=yes
1159         fi
1160
1161         if test "x$want_libssh" = "xyes"; then
1162                 AC_CHECK_LIB(ssh, ssh_new,
1163                   [
1164                     LIBSSH_LIBS=-lssh
1165                         AC_DEFINE(HAVE_LIBSSH, 1, [Define to use libssh library])
1166                         have_good_libssh=yes
1167                   ],,
1168                 )
1169                 AC_CHECK_LIB(ssh, ssh_userauth_agent,
1170                   [
1171                     LIBSSH_LIBS=-lssh
1172                         AC_DEFINE(HAVE_SSH_USERAUTH_AGENT, 1, [Libssh library has ssh_userauth_agent])
1173                         have_ssh_userauth_agent=yes
1174                   ],,
1175                 )
1176         else
1177                 AC_MSG_RESULT(not required)
1178         fi
1179 ])
1180
1181 #AC_WIRESHARK_LDFLAGS_CHECK
1182 #
1183 # $1 : ldflag(s) to test
1184 #
1185 # We attempt to compile and link a test program with the specified linker
1186 # flag. The defined flag is added to LDFLAGS only if the link succeeds.
1187 #
1188 AC_DEFUN([AC_WIRESHARK_LDFLAGS_CHECK],
1189 [LD_OPTION="$1"
1190 AC_MSG_CHECKING(whether we can add $LD_OPTION to LDFLAGS)
1191 AC_WIRESHARK_PUSH_FLAGS
1192 LDFLAGS="$LDFLAGS $LD_OPTION"
1193 can_add_to_ldflags=""
1194 AC_LINK_IFELSE(
1195   [
1196     AC_LANG_SOURCE([[main() { return; }]])
1197   ],
1198   [
1199     AC_MSG_RESULT(yes)
1200     AX_APPEND_FLAG([$LD_OPTION], [WS_LDFLAGS])
1201     can_add_to_ldflags=yes
1202   ],
1203   [
1204     AC_MSG_RESULT(no)
1205     can_add_to_ldflags=no
1206   ])
1207   AC_WIRESHARK_POP_FLAGS
1208 ])
1209
1210 dnl
1211 dnl Check whether, if you pass an unknown warning option to the
1212 dnl compiler, it fails or just prints a warning message and succeeds.
1213 dnl Set ac_wireshark_unknown_warning_option_error to the appropriate flag
1214 dnl to force an error if it would otherwise just print a warning message
1215 dnl and succeed.
1216 dnl
1217 AC_DEFUN([AC_WIRESHARK_CHECK_UNKNOWN_WARNING_OPTION_ERROR],
1218     [
1219         AC_MSG_CHECKING([whether the compiler fails when given an unknown warning option])
1220         AC_WIRESHARK_PUSH_FLAGS
1221         CFLAGS="$CFLAGS -Wxyzzy-this-will-never-succeed-xyzzy"
1222         AC_TRY_COMPILE(
1223             [],
1224             [return 0],
1225             [
1226                 AC_MSG_RESULT([no, adding -Werror=unknown-warning-option])
1227                 #
1228                 # We're assuming this is clang, where
1229                 # -Werror=unknown-warning-option is the appropriate
1230                 # option to force the compiler to fail.
1231                 #
1232                 ac_wireshark_unknown_warning_option_error="-Werror=unknown-warning-option"
1233             ],
1234             [
1235                 AC_MSG_RESULT([yes])
1236             ])
1237         AC_WIRESHARK_POP_FLAGS
1238     ])
1239
1240 dnl
1241 dnl Check whether, if you pass a valid-for-C-but-not-C++ option to the
1242 dnl compiler, it fails or just prints a warning message and succeeds.
1243 dnl Set ac_wireshark_non_cxx_warning_option_error to the appropriate flag
1244 dnl to force an error if it would otherwise just print a warning message
1245 dnl and succeed.
1246 dnl
1247 AC_DEFUN([AC_WIRESHARK_CHECK_NON_CXX_WARNING_OPTION_ERROR],
1248     [
1249         AC_MSG_CHECKING([whether the compiler fails when given an warning option not supported for C++])
1250         #
1251         # Some C+ compilers warn about -Wmissing-prototypes, and some warn
1252         # about -Wmissing-declarations.  Check both.
1253         #
1254         AC_LANG_PUSH(C++)
1255         AC_WIRESHARK_PUSH_FLAGS
1256         save_CXXFLAGS="$CXXFLAGS"
1257         for flag in -Wmissing-prototypes -Wmissing-declarations; do
1258             CXXFLAGS="$save_CXXFLAGS $flag"
1259             AC_TRY_COMPILE(
1260                 [],
1261                 [return 0],
1262                 [
1263                     #
1264                     # We're assuming this is g++, where -Werror is the
1265                     # appropriate option to force the compiler to fail.
1266                     # Check whether it fails with -Werror.
1267                     #
1268                     # NOTE: it's important to put -Werror *before*
1269                     # the flag, otherwise, when it sees the flag,
1270                     # it doesn't yet know that warnings should be
1271                     # treated as errors, and doesn't treat the
1272                     # "that's C-only" warning as an error.
1273                     #
1274                     CXXFLAGS="$save_CXXFLAGS -Werror $flag"
1275                     AC_TRY_COMPILE(
1276                         [],
1277                         [return 0],
1278                         [
1279                             #
1280                             # No, so this option is actually OK
1281                             # with our C++ compiler.
1282                             #
1283                             # (We need an empty command here to
1284                             # prevent some versions of autoconf
1285                             # from generating a script with an
1286                             # empty "then" clause for an if statement.)
1287                             #
1288                             :
1289                         ],
1290                         [
1291                             #
1292                             # Yes, so we need -Werror for the tests.
1293                             #
1294                             ac_wireshark_non_cxx_warning_option_error="-Werror"
1295                             break
1296                         ])
1297                 ])
1298         done
1299         AC_WIRESHARK_POP_FLAGS
1300         AC_LANG_POP
1301         if test x$ac_wireshark_non_cxx_warning_option_error = x; then
1302             AC_MSG_RESULT([yes])
1303         else
1304             AC_MSG_RESULT([no, adding -Werror])
1305         fi
1306     ])
1307
1308 #
1309 # AC_WIRESHARK_COMPILER_FLAGS_CHECK
1310 #
1311 # $1 : flags to test
1312 # $2 : if supplied, C for C-only flags, CXX for C++-only flags
1313 # $3 : if supplied, a program to try to compile with the flag
1314 #      and, if the compile fails when -Werror is turned on,
1315 #      we don't add the flag - used for warning flags that
1316 #      issue incorrect or non-useful warnings with some
1317 #      compiler versions
1318 # $4 : must be supplied if $3 is supplied - a message describing
1319 #      for what the test program is testing
1320 #
1321 # The macro first determines if the compiler supports GCC-style flags.
1322 # Then it attempts to compile with the defined cflags.  The defined
1323 # flags are added to WS_CHECKED_CFLAGS only if the compilation succeeds.
1324 # CFLAGS remains unchanged. can_add_to_cflags is set to "no" when the
1325 # flag is checked but unavailable. (Like-wise for CXXFLAGS.)
1326 #
1327 # We do this because not all such options are necessarily supported by
1328 # the version of the particular compiler we're using.
1329 #
1330 AC_DEFUN([AC_WIRESHARK_COMPILER_FLAGS_CHECK],
1331 [GCC_OPTION="$1"
1332 can_add_to_cflags=""
1333 can_add_to_cxxflags=""
1334 if test "x$ac_supports_gcc_flags" = "xyes" ; then
1335   if test "$2" != CXX ; then
1336     #
1337     # Not C++-only; if this can be added to the C compiler flags, add them.
1338     #
1339     # If the option begins with "-W", add
1340     # $ac_wireshark_unknown_warning_option_error to make sure that
1341     # we'll get an error if it's an unknown warning option; not all
1342     # compilers treat unknown warning options as errors (I'm looking at
1343     # you, clang).
1344     #
1345     # If the option begins with "-f" or "-m", add -Werror to make sure
1346     # that we'll get an error if we get "argument unused during compilation"
1347     # warnings, as those will either cause a failure for files compiled
1348     # with -Werror or annoying noise for files compiled without it.
1349     # (Yeah, you, clang.)
1350     #
1351     AC_MSG_CHECKING(whether we can add $GCC_OPTION to CFLAGS)
1352     AC_WIRESHARK_PUSH_FLAGS
1353     if expr "x$GCC_OPTION" : "x-W.*" >/dev/null
1354     then
1355       CFLAGS="$CFLAGS $ac_wireshark_unknown_warning_option_error $GCC_OPTION"
1356     elif expr "x$GCC_OPTION" : "x-f.*" >/dev/null
1357     then
1358       CFLAGS="$CFLAGS -Werror $GCC_OPTION"
1359     elif expr "x$GCC_OPTION" : "x-m.*" >/dev/null
1360     then
1361       CFLAGS="$CFLAGS -Werror $GCC_OPTION"
1362     else
1363       CFLAGS="$CFLAGS $GCC_OPTION"
1364     fi
1365     AC_COMPILE_IFELSE(
1366       [
1367         AC_LANG_SOURCE([[int foo;]])
1368       ],
1369       [
1370         AC_MSG_RESULT(yes)
1371         can_add_to_cflags=yes
1372         #
1373         # OK, do we have a test program?  If so, check
1374         # whether it fails with this option and -Werror,
1375         # and, if so, don't include it.
1376         #
1377         # We test arg 4 here because arg 3 is a program which
1378         # could contain quotes (breaking the comparison).
1379         #
1380         if test "x$4" != "x" ; then
1381           CFLAGS="$CFLAGS -Werror"
1382           AC_MSG_CHECKING(whether $GCC_OPTION $4)
1383           AC_COMPILE_IFELSE(
1384             [AC_LANG_SOURCE($3)],
1385             [
1386               AC_MSG_RESULT(no)
1387               #
1388               # Remove "force an error for a warning" options, if we
1389               # added them, by setting CFLAGS to the saved value plus
1390               # just the new option.
1391               #
1392               AX_APPEND_FLAG([$GCC_OPTION], [WS_CFLAGS])
1393               if test "$CC" = "$CC_FOR_BUILD"; then
1394                 #
1395                 # We're building the build tools with the same compiler
1396                 # with which we're building Wireshark, so add the flags
1397                 # to the flags for that compiler as well.
1398                 #
1399                 AX_APPEND_FLAG([$GCC_OPTION], [WS_CFLAGS_FOR_BUILD])
1400               fi
1401             ],
1402             [
1403               AC_MSG_RESULT(yes)
1404             ])
1405         else
1406           #
1407           # Remove "force an error for a warning" options, if we
1408           # added them, by setting CFLAGS to the saved value plus
1409           # just the new option.
1410           #
1411           AX_APPEND_FLAG([$GCC_OPTION], [WS_CFLAGS])
1412           if test "$CC" = "$CC_FOR_BUILD"; then
1413             #
1414             # We're building the build tools with the same compiler
1415             # with which we're building Wireshark, so add the flags
1416             # to the flags for that compiler as well.
1417             #
1418             AX_APPEND_FLAG([$GCC_OPTION], [WS_CFLAGS_FOR_BUILD])
1419           fi
1420         fi
1421       ],
1422       [
1423         AC_MSG_RESULT(no)
1424         can_add_to_cflags=no
1425       ])
1426       AC_WIRESHARK_POP_FLAGS
1427   fi
1428   #
1429   # Did we find a C++ compiler?
1430   #
1431   if test "x$CXX" != "x" ; then
1432     #
1433     # Yes.  Is this option only for the C compiler?
1434     #
1435     if test "$2" != C ; then
1436       #
1437       # Not C-only; if this option can be added to the C++ compiler
1438       # options, add it.
1439       #
1440       # If the option begins with "-W", add
1441       # $ac_wireshark_unknown_warning_option_error, as per the above, and
1442       # also add $ac_wireshark_non_cxx_warning_option_error, because at
1443       # lease some versions of g++ whine about -Wmissing-prototypes, the
1444       # fact that at least one of those versions refuses to warn about
1445       # function declarations without an earlier declaration nonwithstanding;
1446       # perhaps there's a reason not to warn about that with C++ even though
1447       # warning about it can be a Good Idea with C, but it's not obvious to
1448       # me).
1449       #
1450       # If the option begins with "-f" or "-m", add -Werror to make sure
1451       # that we'll get an error if we get "argument unused during compilation"
1452       # warnings, as those will either cause a failure for files compiled
1453       # with -Werror or annoying noise for files compiled without it.
1454       # (Yeah, you, clang++.)
1455       #
1456       AC_MSG_CHECKING(whether we can add $GCC_OPTION to CXXFLAGS)
1457       AC_WIRESHARK_PUSH_FLAGS
1458       if expr "x$GCC_OPTION" : "x-W.*" >/dev/null
1459       then
1460         CXXFLAGS="$CXXFLAGS $ac_wireshark_unknown_warning_option_error $ac_wireshark_non_cxx_warning_option_error $GCC_OPTION"
1461       elif expr "x$GCC_OPTION" : "x-f.*" >/dev/null
1462       then
1463         CXXFLAGS="$CXXFLAGS -Werror $GCC_OPTION"
1464       elif expr "x$GCC_OPTION" : "x-m.*" >/dev/null
1465       then
1466         CXXFLAGS="$CXXFLAGS -Werror $GCC_OPTION"
1467       else
1468         CXXFLAGS="$CXXFLAGS $GCC_OPTION"
1469       fi
1470       AC_LANG_PUSH([C++])
1471       AC_COMPILE_IFELSE(
1472         [
1473           AC_LANG_SOURCE([[int foo;]])
1474         ],
1475         [
1476           AC_MSG_RESULT(yes)
1477           can_add_to_cxxflags=yes
1478           #
1479           # OK, do we have a test program?  If so, check
1480           # whether it fails with this option and -Werror,
1481           # and, if so, don't include it.
1482           #
1483           # We test arg 4 here because arg 3 is a program which
1484           # could contain quotes (breaking the comparison).
1485           #
1486           if test "x$4" != "x" ; then
1487             CXXFLAGS="$CXXFLAGS -Werror"
1488             AC_MSG_CHECKING(whether $GCC_OPTION $4)
1489             AC_COMPILE_IFELSE(
1490               [AC_LANG_SOURCE($3)],
1491               [
1492                 AC_MSG_RESULT(no)
1493                 #
1494                 # Remove "force an error for a warning" options, if we
1495                 # added them, by setting CXXFLAGS to the saved value plus
1496                 # just the new option.
1497                 #
1498                 AX_APPEND_FLAG([$GCC_OPTION], [WS_CXXFLAGS])
1499               ],
1500               [
1501                 AC_MSG_RESULT(yes)
1502               ])
1503           else
1504             #
1505             # Remove "force an error for a warning" options, if we
1506             # added them, by setting CXXFLAGS to the saved value plus
1507             # just the new option.
1508             #
1509             AX_APPEND_FLAG([$GCC_OPTION], [WS_CXXFLAGS])
1510           fi
1511         ],
1512         [
1513           AC_MSG_RESULT(no)
1514           can_add_to_cxxflags=no
1515         ])
1516       AC_WIRESHARK_POP_FLAGS
1517       AC_LANG_POP([C++])
1518     fi
1519     if test "(" "$can_add_to_cflags" = "yes" -a "$can_add_to_cxxflags" = "no" ")" \
1520          -o "(" "$can_add_to_cflags" = "no" -a "$can_add_to_cxxflags" = "yes" ")"
1521     then
1522       #
1523       # Confusingly, some C++ compilers like -Wmissing-prototypes but
1524       # don't like -Wmissing-declarations and others like
1525       # -Wmissing-declarations but don't like -Wmissing-prototypes,
1526       # the fact that the corresponding C compiler likes both.  Don't
1527       # warn about them.
1528       #
1529       if test "(" x$GCC_OPTION != x-Wmissing-prototypes ")" \
1530            -a "(" x$GCC_OPTION != x-Wmissing-declarations ")"
1531       then
1532          AC_MSG_WARN([$CC and $CXX appear to be a mismatched pair])
1533       fi
1534     fi
1535   fi
1536 fi
1537 ])
1538
1539 # AC_WIRESHARK_GCC_FORTIFY_SOURCE_CHECK
1540 #
1541 # Checks if '-D_FORTIFY_SOURCE=...' is OK to use in CPPFLAGS.
1542 #  Use '-D_FORTIFY_SOURCE=...' in CPPFLAGS only if the GCC 'optimization level' is > 0.
1543 #  The use of '-D_FORTIFY_SOURCE=...' will cause a warning with at least some versions
1544 #    of glibc if the  GCC "optimization level" is 0 (default or -O or -O0)
1545 #    when using GCC to compile a source file which references the macro definition.
1546 #
1547 # See: http://gcc.gnu.org/ml/gcc-patches/2004-09/msg02055.html
1548 # See: http://sourceware.org/bugzilla/show_bug.cgi?id=13979
1549 #
1550 #   We'll use '-D_FORTIFY_SOURCE=2' only if there's no warning; Among other things this means
1551 #    that the  use of '-D_FORTIFY_SOURCE=2' with '-Werror' and '-O0' won't cause
1552 #    the compiler to stop on error.
1553 #   Assumption: CFLAGS already contains whatever optimization option including none) is
1554 #    to be used.
1555 #
1556
1557 AC_DEFUN([AC_WIRESHARK_GCC_FORTIFY_SOURCE_CHECK],
1558 [
1559 if test "x$GCC" = "xyes" -o "x$CC" = "xclang" ; then
1560   AC_MSG_CHECKING([whether -D_FORTIFY_SOURCE=2 can be used (without generating a warning)])
1561   AC_WIRESHARK_PUSH_FLAGS
1562   CFLAGS="$CFLAGS -Werror"
1563   CPPFLAGS="$CPPFLAGS -D_FORTIFY_SOURCE=2"
1564   AC_COMPILE_IFELSE([
1565     AC_LANG_SOURCE([[
1566                   #include <stdio.h>
1567                       int foo;
1568                   ]])],
1569                   [
1570                     AC_MSG_RESULT(yes)
1571                     AX_APPEND_FLAG([-D_FORTIFY_SOURCE=2], [WS_CPPFLAGS])
1572                   ],
1573                   [
1574                     AC_MSG_RESULT(no)
1575                   ])
1576   AC_WIRESHARK_POP_FLAGS
1577 fi
1578 ])
1579
1580 #
1581 # AC_WIRESHARK_GCC_SYSTEM_INCLUDE
1582 #
1583 # Replace -I include flag for -isystem in FLAGS argument
1584 #
1585 AC_DEFUN([AC_WIRESHARK_GCC_SYSTEM_INCLUDE],
1586 [
1587         if test "x$GCC" = "xyes" -o "x$CC" = "xclang" ; then
1588                 $1=`printf %s " $$1" \
1589                         | sed -e 's/  *-I *\// -isystem\//g' -e 's/^ *//'`
1590         fi
1591 ])
1592
1593 #
1594 # PKG_WIRESHARK_CHECK_SYSTEM_MODULES
1595 #
1596 AC_DEFUN([PKG_WIRESHARK_CHECK_SYSTEM_MODULES],
1597 [
1598         PKG_CHECK_MODULES($@)
1599         AC_WIRESHARK_GCC_SYSTEM_INCLUDE($1_CFLAGS)
1600 ])
1601
1602 #
1603 # AC_WIRESHARK_OSX_INTEGRATION_CHECK
1604 #
1605 # Checks for the presence of OS X integration functions in the GTK+ framework
1606 # or as a separate library.
1607 #
1608 # GTK+ for MAC OS X now lives on www.gtk.org at:
1609 #
1610 #   http://www.gtk.org/download/macos.php
1611 #
1612 # Details on building with GTK-OSX are available at:
1613 #
1614 #   http://live.gnome.org/GTK%2B/OSX/Building
1615 #
1616 # The GTK-OSX library has been renamed to gtkmacintegration.
1617 # It was previously named igemacintegration.
1618 #
1619 # http://live.gnome.org/GTK%2B/OSX/Integration
1620 #    for the old Carbon-based integration functions
1621 #
1622 AC_DEFUN([AC_WIRESHARK_OSX_INTEGRATION_CHECK],
1623 [
1624         AC_WIRESHARK_PUSH_FLAGS
1625         ac_save_LIBS="$LIBS"
1626         CFLAGS="$CFLAGS $GTK_CFLAGS"
1627         LIBS="$GTK_LIBS $LIBS"
1628
1629         #
1630         # Check for the new integration functions in a -lgtkmacintegration
1631         # library.
1632         #
1633         AC_CHECK_LIB(gtkmacintegration, gtkosx_application_set_menu_bar,
1634         [
1635                 AC_DEFINE(HAVE_GTKOSXAPPLICATION, 1,
1636                         [Define to 1 if -lgtkmacintegration includes the GtkOSXApplication Integration functions.])
1637                 have_ige_mac=yes
1638                 # We don't want gtk stuff in LIBS (which is reset below) so
1639                 # manually set GTK_LIBS (which is more appropriate)
1640                 GTK_LIBS="$GTK_LIBS -lgtkmacintegration"
1641         ])
1642
1643         if test x$have_ige_mac = x
1644         then
1645                 #
1646                 # Not found - check for the old integration functions in
1647                 # the Gtk framework.
1648                 #
1649                 AC_CHECK_LIB(Gtk, gtk_mac_menu_set_menu_bar,
1650                 [
1651                         AC_DEFINE(HAVE_IGE_MAC_INTEGRATION, 1,
1652                                 [Define to 1 if the the Gtk+ framework or a separate library includes the Imendio IGE Mac OS X Integration functions.])
1653                         have_ige_mac=yes
1654                         # We don't want gtk stuff in LIBS (which is reset below) so
1655                         # manually set GTK_LIBS (which is more appropriate)
1656                         GTK_LIBS="$GTK_LIBS -lGtk"
1657                 ])
1658         fi
1659
1660         if test x$have_ige_mac = x
1661         then
1662                 #
1663                 # Not found - check for the old integration functions in
1664                 # a -lgtkmacintegration library.
1665                 #
1666                 AC_CHECK_LIB(gtkmacintegration, gtk_mac_menu_set_menu_bar,
1667                 [
1668                         AC_DEFINE(HAVE_IGE_MAC_INTEGRATION, 1,
1669                                 [Define to 1 if the the Gtk+ framework or a separate library includes the Imendio IGE Mac OS X Integration functions.])
1670                         have_ige_mac=yes
1671                         # We don't want gtk stuff in LIBS (which is reset below) so
1672                         # manually set GTK_LIBS (which is more appropriate)
1673                         GTK_LIBS="$GTK_LIBS -lgtkmacintegration"
1674                 ])
1675         fi
1676         LIBS="$ac_save_LIBS"
1677         AC_WIRESHARK_POP_FLAGS
1678 ])
1679
1680 # Based on AM_PATH_GTK in gtk-2.0.m4.
1681
1682 dnl AC_WIRESHARK_QT_MODULE_CHECK_WITH_QT_VERSION([MODULE, MINIMUM-VERSION,
1683 dnl     REQUESTED-MAJOR_VERSION, [ACTION-IF-FOUND, [ACTION-IF-NOT-FOUND]]])
1684 dnl Test for a particular Qt module, for a particular Qt major version,
1685 dnl and, if we find it add the flags and libraries for it to Qt_CFLAGS
1686 dnl and Qt_LIBS.
1687 dnl
1688 AC_DEFUN([AC_WIRESHARK_QT_MODULE_CHECK_WITH_QT_VERSION],
1689 [
1690         case "$3" in
1691
1692         4)
1693                 #
1694                 # Check for Qt 4.
1695                 #
1696                 modprefix="Qt"
1697                 #
1698                 # Version of the module we're checking for.
1699                 # Default to 4.0.0.
1700                 #
1701                 min_qt_version=ifelse([$2], ,4.0.0,$2)
1702                 ;;
1703
1704         5)
1705                 #
1706                 # Check for Qt 5.
1707                 #
1708                 modprefix="Qt5"
1709                 #
1710                 # Version of the module we're checking for.
1711                 # Default to 5.0.0.
1712                 #
1713                 min_qt_version=5.0.0
1714                 ;;
1715
1716         *)
1717                 AC_MSG_ERROR([Qt version $3 is not a known Qt version])
1718                 ;;
1719         esac
1720
1721         pkg_config_module="${modprefix}$1"
1722         AC_MSG_CHECKING(for $pkg_config_module - version >= $min_qt_version)
1723         if $PKG_CONFIG --atleast-version $min_qt_version $pkg_config_module; then
1724                 mod_version=`$PKG_CONFIG --modversion $pkg_config_module`
1725                 AC_MSG_RESULT(yes (version $mod_version))
1726                 mod_cflags=`$PKG_CONFIG --cflags $pkg_config_module`
1727                 AC_WIRESHARK_GCC_SYSTEM_INCLUDE(mod_cflags)
1728                 Qt_CFLAGS="$Qt_CFLAGS $mod_cflags"
1729                 Qt_LIBS="$Qt_LIBS `$PKG_CONFIG --libs $pkg_config_module`"
1730                 # Run Action-If-Found
1731                 ifelse([$4], , :, [$4])
1732         else
1733                 AC_MSG_RESULT(no)
1734                 # Run Action-If-Not-Found
1735                 ifelse([$5], , :, [$5])
1736         fi
1737 ])
1738
1739 dnl AC_WIRESHARK_QT_MODULE_CHECK([MODULE, MINIMUM-VERSION,
1740 dnl     REQUESTED-MAJOR_VERSION, [ACTION-IF-FOUND, [ACTION-IF-NOT-FOUND]]])
1741 dnl Test for a particular Qt module and add the flags and libraries
1742 dnl for it to Qt_CFLAGS and Qt_LIBS.
1743 dnl
1744 AC_DEFUN([AC_WIRESHARK_QT_MODULE_CHECK],
1745 [
1746         #
1747         # Prior to Qt 5, modules were named QtXXX.
1748         # In Qt 5, they're named Qt5XXX.
1749         # This will need to change to handle future major Qt releases.
1750         #
1751         case "$3" in
1752
1753         yes|unspecified)
1754                 #
1755                 # Check for all versions of Qt we support.
1756                 # Try the Qt 5 version first.
1757                 #
1758                 versions="5 4"
1759                 ;;
1760
1761         4)
1762                 #
1763                 # Check for Qt 4.
1764                 #
1765                 versions="4"
1766                 ;;
1767
1768         5)
1769                 #
1770                 # Check for Qt 5.
1771                 #
1772                 versions="5"
1773                 ;;
1774
1775         *)
1776                 AC_MSG_ERROR([Qt version $3 is not a known Qt version])
1777                 ;;
1778         esac
1779
1780         for version in $versions
1781         do
1782                 AC_WIRESHARK_QT_MODULE_CHECK_WITH_QT_VERSION($1, $2,
1783                     $version, [foundit=yes], [foundit=no])
1784                 if test "x$foundit" = "xyes"; then
1785                         break
1786                 fi
1787         done
1788
1789         if test "x$foundit" = "xyes"; then
1790                 # Remember which version of Qt we found
1791                 qt_version=$version
1792                 # Run Action-If-Found
1793                 ifelse([$4], , :, [$4])
1794         else
1795                 # Run Action-If-Not-Found
1796                 ifelse([$5], , :, [$5])
1797         fi
1798 ])
1799
1800 AC_DEFUN([AC_WIRESHARK_QT_ADD_PIC_IF_NEEDED],
1801 [
1802     AC_LANG_PUSH([C++])
1803         AC_WIRESHARK_PUSH_FLAGS
1804         CPPFLAGS="$CPPFLAGS $Qt_CFLAGS"
1805         AC_MSG_CHECKING([whether Qt works without -fPIC])
1806         AC_PREPROC_IFELSE(
1807                 [AC_LANG_SOURCE([[#include <QtCore>]])],
1808                 [AC_MSG_RESULT(yes)],
1809                 [
1810                         AC_MSG_RESULT(no)
1811                         AC_MSG_CHECKING([whether Qt works with -fPIC])
1812                         CPPFLAGS="$CPPFLAGS -fPIC"
1813                         AC_PREPROC_IFELSE(
1814                                 [AC_LANG_SOURCE([[#include <QtCore>]])],
1815                                 [
1816                                         AC_MSG_RESULT(yes)
1817                                         Qt_CFLAGS="$Qt_CFLAGS -fPIC"
1818                                 ],
1819                                 [
1820                                         AC_MSG_RESULT(no)
1821                                         AC_MSG_ERROR(Couldn't compile Qt without -fPIC nor with -fPIC)
1822                                 ])
1823                 ])
1824         AC_WIRESHARK_POP_FLAGS
1825     AC_LANG_POP([C++])
1826 ])
1827
1828 dnl AC_WIRESHARK_QT_CHECK([MINIMUM-VERSION, REQUESTED-MAJOR_VERSION,
1829 dnl     [ACTION-IF-FOUND, [ACTION-IF-NOT-FOUND]]])
1830 dnl Test for Qt and define Qt_CFLAGS and Qt_LIBS.
1831 dnl
1832 AC_DEFUN([AC_WIRESHARK_QT_CHECK],
1833 [
1834         qt_version_to_check="$2"
1835
1836         #
1837         # Check for the Core module; if we don't have that,
1838         # we don't have Qt.  If we *do* have it, we know what
1839         # version it is, so only check for that version of
1840         # other modules.
1841         #
1842         AC_WIRESHARK_QT_MODULE_CHECK(Core, $1, $qt_version_to_check,
1843             [
1844               qt_version_to_check=$qt_version
1845               QT_VERSION=$mod_version
1846             ],
1847             [no_qt=yes])
1848
1849         if test x"$no_qt" = x ; then
1850                 #
1851                 # We need the Gui module as well.
1852                 #
1853                 AC_WIRESHARK_QT_MODULE_CHECK(Gui, $1, $qt_version_to_check, ,
1854                     [no_qt=yes])
1855         fi
1856
1857         if test x"$no_qt" = x ; then
1858                 #
1859                 # Qt 5.0 appears to move the widgets out of Qt GUI
1860                 # to Qt Widgets; look for the Widgets module, but
1861                 # don't fail if we don't have it.
1862                 #
1863                 AC_WIRESHARK_QT_MODULE_CHECK(Widgets, $1, $qt_version_to_check)
1864
1865                 #
1866                 # Qt 5.0 also appears to move the printing support into
1867                 # the Qt PrintSupport module.
1868                 #
1869                 AC_WIRESHARK_QT_MODULE_CHECK(PrintSupport, $1, $qt_version_to_check)
1870
1871                 #
1872                 # Qt 5.0 added multimedia in the Qt
1873                 # Multimedia module.
1874                 #
1875                 have_qt_multimedia_lib=no
1876                 AC_WIRESHARK_QT_MODULE_CHECK(Multimedia, $1, $qt_version_to_check,
1877                         have_qt_multimedia_lib=yes
1878                         AC_DEFINE(QT_MULTIMEDIA_LIB, 1, [Define if we have QtMultimedia]))
1879
1880                 #
1881                 # While we're at it, look for QtMacExtras.  (Presumably
1882                 # if we're not building for OS X, it won't be present.)
1883                 #
1884                 # XXX - is there anything in QtX11Extras or QtWinExtras
1885                 # that we should be using?
1886                 #
1887                 AC_WIRESHARK_QT_MODULE_CHECK(MacExtras, $1, $qt_version_to_check,
1888                         AC_DEFINE(QT_MACEXTRAS_LIB, 1, [Define if we have QtMacExtras]))
1889
1890                 AC_WIRESHARK_QT_ADD_PIC_IF_NEEDED
1891
1892                 # Run Action-If-Found
1893                 ifelse([$3], , :, [$3])
1894         else
1895                 # Run Action-If-Not-Found
1896                 ifelse([$4], , :, [$4])
1897         fi
1898
1899 ])
1900
1901 dnl AC_WIRESHARK_QT_TOOL_CHECK([TOOLPATHVAR, TOOL, REQUESTED-MAJOR_VERSION])
1902 dnl Test for a particular Qt tool for some specific version of Qt
1903 dnl
1904 AC_DEFUN([AC_WIRESHARK_QT_TOOL_CHECK],
1905 [
1906         #
1907         # At least in some versions of Debian/Ubuntu, and perhaps
1908         # other OSes, the Qt build tools are just links to a
1909         # program called "qtchooser", and even if you want to
1910         # build with Qt 5, running the tool might give you the
1911         # Qt 4 version of the tool unless you run the tool with
1912         # a -qt=5 argument.
1913         #
1914         # So we look for qtchooser and, if we find it, use the
1915         # -qt={version} argument, otherwise we look for particular
1916         # tool versions using tool name suffixes.
1917         #
1918         AC_PATH_PROG(QTCHOOSER, qtchooser)
1919         if test ! -z "$QTCHOOSER"; then
1920                 #
1921                 # We found qtchooser; we assume that means that
1922                 # the tool is linked to qtchooser, so that we
1923                 # can run it with the -qt={version} flag to get
1924                 # the appropriate version of the tool.
1925                 #
1926                 AC_PATH_PROG($1, $2)
1927                 if test "x$$1" = x; then
1928                         #
1929                         # We can't build Qt Wireshark without that
1930                         # tool..
1931                         #
1932                         AC_MSG_ERROR(I couldn't find $2; make sure it's installed and in your path)
1933                 fi
1934
1935                 #
1936                 # Add the -qt={version} argument to it.
1937                 #
1938                 $1="$$1 -qt=$qt_version"
1939         else
1940                 #
1941                 # Annoyingly, on some Linux distros (e.g. Debian)
1942                 # the Qt 5 tools have no suffix and the Qt 4 tools
1943                 # have suffix -qt4. On other distros (e.g. openSUSE)
1944                 # the Qt 5 tools have suffix -qt5 and the Qt 4 tools
1945                 # have no suffix.
1946                 #
1947                 # So we check for the tool first with the -qtN suffix
1948                 # and then with no suffix.
1949                 #
1950                 AC_PATH_PROGS($1, [$2-qt$qt_version $2])
1951                 if test "x$$1" = x; then
1952                         #
1953                         # We can't build Qt Wireshark without that
1954                         # tool..
1955                         #
1956                         AC_MSG_ERROR(I couldn't find $2-qt$qt_version or $2; make sure it's installed and in your path)
1957                 fi
1958         fi
1959 ])