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