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