69b2b8ce3f7afb017936e37e9e7e4194b90e5d77
[obnox/wireshark/wip.git] / acinclude.m4
1 dnl Macros that test for specific features.
2 dnl This file is part of the Autoconf packaging for Ethereal.
3 dnl Copyright (C) 1998-2000 by Gerald Combs.
4 dnl
5 dnl $Id: acinclude.m4,v 1.79 2004/06/29 07:59:12 guy Exp $
6 dnl
7 dnl This program is free software; you can redistribute it and/or modify
8 dnl it under the terms of the GNU General Public License as published by
9 dnl the Free Software Foundation; either version 2, or (at your option)
10 dnl any later version.
11 dnl
12 dnl This program is distributed in the hope that it will be useful,
13 dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
14 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 dnl GNU General Public License for more details.
16 dnl
17 dnl You should have received a copy of the GNU General Public License
18 dnl along with this program; if not, write to the Free Software
19 dnl Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
20 dnl 02111-1307, USA.
21 dnl
22 dnl As a special exception, the Free Software Foundation gives unlimited
23 dnl permission to copy, distribute and modify the configure scripts that
24 dnl are the output of Autoconf.  You need not follow the terms of the GNU
25 dnl General Public License when using or distributing such scripts, even
26 dnl though portions of the text of Autoconf appear in them.  The GNU
27 dnl General Public License (GPL) does govern all other use of the material
28 dnl that constitutes the Autoconf program.
29 dnl
30 dnl Certain portions of the Autoconf source text are designed to be copied
31 dnl (in certain cases, depending on the input) into the output of
32 dnl Autoconf.  We call these the "data" portions.  The rest of the Autoconf
33 dnl source text consists of comments plus executable code that decides which
34 dnl of the data portions to output in any given case.  We call these
35 dnl comments and executable code the "non-data" portions.  Autoconf never
36 dnl copies any of the non-data portions into its output.
37 dnl
38 dnl This special exception to the GPL applies to versions of Autoconf
39 dnl released by the Free Software Foundation.  When you make and
40 dnl distribute a modified version of Autoconf, you may extend this special
41 dnl exception to the GPL to apply to your modified version as well, *unless*
42 dnl your modified version has the potential to copy into its output some
43 dnl of the text that was the non-data portion of the version that you started
44 dnl with.  (In other words, unless your change moves or copies text from
45 dnl the non-data portions to the data portions.)  If your modification has
46 dnl such potential, you must delete any notice of this special exception
47 dnl to the GPL from your modified version.
48 dnl
49 dnl Written by David MacKenzie, with help from
50 dnl Franc,ois Pinard, Karl Berry, Richard Pixley, Ian Lance Taylor,
51 dnl Roland McGrath, Noah Friedman, david d zuhn, and many others.
52
53 #
54 # AC_ETHEREAL_ADD_DASH_L
55 #
56 # Add to the variable specified as the first argument a "-L" flag for the
57 # directory specified as the second argument, and, on Solaris, add a
58 # "-R" flag for it as well.
59 #
60 # XXX - IRIX, and other OSes, may require some flag equivalent to
61 # "-R" here.
62 #
63 AC_DEFUN([AC_ETHEREAL_ADD_DASH_L],
64 [$1="$$1 -L$2"
65 case "$host_os" in
66   solaris*)
67     $1="$$1 -R$2"
68   ;;
69 esac
70 ])
71
72
73 #
74 # AC_ETHEREAL_STRUCT_SA_LEN
75 #
76 dnl AC_STRUCT_ST_BLKSIZE extracted from the file in question,
77 dnl "acspecific.m4" in GNU Autoconf 2.12, and turned into
78 dnl AC_ETHEREAL_STRUCT_SA_LEN, which checks if "struct sockaddr"
79 dnl has the 4.4BSD "sa_len" member, and defines HAVE_SA_LEN; that's
80 dnl what's in this file.
81 dnl Done by Guy Harris <guy@alum.mit.edu> on 1998-11-14. 
82
83 dnl ### Checks for structure members
84
85 AC_DEFUN([AC_ETHEREAL_STRUCT_SA_LEN],
86 [AC_CACHE_CHECK([for sa_len in struct sockaddr], ac_cv_ethereal_struct_sa_len,
87 [AC_TRY_COMPILE([#include <sys/types.h>
88 #include <sys/socket.h>], [struct sockaddr s; s.sa_len;],
89 ac_cv_ethereal_struct_sa_len=yes, ac_cv_ethereal_struct_sa_len=no)])
90 if test $ac_cv_ethereal_struct_sa_len = yes; then
91   AC_DEFINE(HAVE_SA_LEN, 1, [Define if sa_len field exists in struct sockaddr])
92 fi
93 ])
94
95
96 dnl
97 dnl Check whether a given format can be used to print 64-bit integers
98 dnl
99 AC_DEFUN([AC_ETHEREAL_CHECK_64BIT_FORMAT],
100 [
101   AC_MSG_CHECKING([whether %$1x can be used to format 64-bit integers])
102   AC_RUN_IFELSE(
103     [
104       AC_LANG_SOURCE(
105         [[
106 #         ifdef HAVE_INTTYPES_H
107           #include <inttypes.h>
108 #         endif
109           #include <stdio.h>
110           #include <sys/types.h>
111
112           main()
113           {
114             u_int64_t t = 1;
115             char strbuf[16+1];
116             sprintf(strbuf, "%016$1x", t << 32);
117             if (strcmp(strbuf, "0000000100000000") == 0)
118               exit(0);
119             else
120               exit(1);
121           }
122         ]])
123     ],
124     [
125       AC_DEFINE(PRId64, "$1d", [Format for printing 64-bit signed decimal numbers])
126       AC_DEFINE(PRIo64, "$1o", [Format for printing 64-bit unsigned octal numbers])
127       AC_DEFINE(PRIx64, "$1x", [Format for printing 64-bit unsigned hexadecimal numbers])
128       AC_DEFINE(PRIu64, "$1u", [Format for printing 64-bit unsigned decimal numbers])
129       AC_MSG_RESULT(yes)
130     ],
131     [
132       AC_MSG_RESULT(no)
133       $2
134     ])
135 ])
136
137 #
138 # AC_ETHEREAL_IPV6_STACK
139 #
140 # By Jun-ichiro "itojun" Hagino, <itojun@iijlab.net>
141 #
142 AC_DEFUN([AC_ETHEREAL_IPV6_STACK],
143 [
144         v6type=unknown
145         v6lib=none
146
147         AC_MSG_CHECKING([ipv6 stack type])
148         for i in v6d toshiba kame inria zeta linux linux-glibc solaris8; do
149                 case $i in
150                 v6d)
151                         AC_EGREP_CPP(yes, [
152 #include </usr/local/v6/include/sys/types.h>
153 #ifdef __V6D__
154 yes
155 #endif],
156                                 [v6type=$i; v6lib=v6;
157                                 v6libdir=/usr/local/v6/lib;
158                                 CFLAGS="-I/usr/local/v6/include $CFLAGS"])
159                         ;;
160                 toshiba)
161                         AC_EGREP_CPP(yes, [
162 #include <sys/param.h>
163 #ifdef _TOSHIBA_INET6
164 yes
165 #endif],
166                                 [v6type=$i; v6lib=inet6;
167                                 v6libdir=/usr/local/v6/lib;
168                                 CFLAGS="-DINET6 $CFLAGS"])
169                         ;;
170                 kame)
171                         AC_EGREP_CPP(yes, [
172 #include <netinet/in.h>
173 #ifdef __KAME__
174 yes
175 #endif],
176                                 [v6type=$i; v6lib=inet6;
177                                 v6libdir=/usr/local/v6/lib;
178                                 CFLAGS="-DINET6 $CFLAGS"])
179                         ;;
180                 inria)
181                         AC_EGREP_CPP(yes, [
182 #include <netinet/in.h>
183 #ifdef IPV6_INRIA_VERSION
184 yes
185 #endif],
186                                 [v6type=$i; CFLAGS="-DINET6 $CFLAGS"])
187                         ;;
188                 zeta)
189                         AC_EGREP_CPP(yes, [
190 #include <sys/param.h>
191 #ifdef _ZETA_MINAMI_INET6
192 yes
193 #endif],
194                                 [v6type=$i; v6lib=inet6;
195                                 v6libdir=/usr/local/v6/lib;
196                                 CFLAGS="-DINET6 $CFLAGS"])
197                         ;;
198                 linux)
199                         if test -d /usr/inet6; then
200                                 v6type=$i
201                                 v6lib=inet6
202                                 v6libdir=/usr/inet6
203                                 CFLAGS="-DINET6 $CFLAGS"
204                         fi
205                         ;;
206                 linux-glibc)
207                         AC_EGREP_CPP(yes, [
208 #include <features.h>
209 #if defined(__GLIBC__) && defined(__GLIBC_MINOR__)
210 #if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 1) || __GLIBC__ > 2
211 yes
212 #endif
213 #endif],
214                         [v6type=$i; v6lib=inet6; CFLAGS="-DINET6 $CFLAGS"])
215                         ;;
216                 solaris8)
217                         if test "`uname -s`" = "SunOS" && test "`uname -r`" = "5.8"; then
218                                 v6type=$i
219                                 v6lib=inet6
220                                 [CFLAGS="-DINET6 -DSOLARIS8_INET6 $CFLAGS"]
221                         fi
222                         ;; 
223                 esac
224                 if test "$v6type" != "unknown"; then
225                         break
226                 fi
227         done
228
229         if test "$v6lib" != "none"; then
230                 for dir in $v6libdir /usr/local/v6/lib /usr/local/lib; do
231                         if test -d $dir -a -f $dir/lib$v6lib.a; then
232                                 LIBS="-L$dir $LIBS -l$v6lib"
233                                 break
234                         fi
235                 done
236                 enable_ipv6="yes"
237         else
238                 enable_ipv6="no"
239         fi
240         AC_MSG_RESULT(["$v6type, $v6lib"])
241 ])
242
243 #
244 # AC_ETHEREAL_GETHOSTBY_LIB_CHECK
245 #
246 # Checks whether we need "-lnsl" to get "gethostby*()", which we use
247 # in "resolv.c".
248 #
249 # Adapted from stuff in the AC_PATH_XTRA macro in "acspecific.m4" in
250 # GNU Autoconf 2.13; the comment came from there.
251 # Done by Guy Harris <guy@alum.mit.edu> on 2000-01-14. 
252 #
253 AC_DEFUN([AC_ETHEREAL_GETHOSTBY_LIB_CHECK],
254 [
255     # msh@cis.ufl.edu says -lnsl (and -lsocket) are needed for his 386/AT,
256     # to get the SysV transport functions.
257     # chad@anasazi.com says the Pyramid MIS-ES running DC/OSx (SVR4)
258     # needs -lnsl.
259     # The nsl library prevents programs from opening the X display
260     # on Irix 5.2, according to dickey@clark.net.
261     AC_CHECK_FUNC(gethostbyname, ,
262         AC_CHECK_LIB(nsl, gethostbyname, NSL_LIBS="-lnsl"))
263     AC_SUBST(NSL_LIBS)
264 ])
265
266 #
267 # AC_ETHEREAL_SOCKET_LIB_CHECK
268 #
269 # Checks whether we need "-lsocket" to get "socket()", which is used
270 # by libpcap on some platforms - and, in effect, "gethostby*()" on
271 # most if not all platforms (so that it can use NIS or DNS or...
272 # to look up host names).
273 #
274 # Adapted from stuff in the AC_PATH_XTRA macro in "acspecific.m4" in
275 # GNU Autoconf 2.13; the comment came from there.
276 # Done by Guy Harris <guy@alum.mit.edu> on 2000-01-14. 
277 #
278 # We use "connect" because that's what AC_PATH_XTRA did.
279 #
280 AC_DEFUN([AC_ETHEREAL_SOCKET_LIB_CHECK],
281 [
282     # lieder@skyler.mavd.honeywell.com says without -lsocket,
283     # socket/setsockopt and other routines are undefined under SCO ODT
284     # 2.0.  But -lsocket is broken on IRIX 5.2 (and is not necessary
285     # on later versions), says simon@lia.di.epfl.ch: it contains
286     # gethostby* variants that don't use the nameserver (or something).
287     # -lsocket must be given before -lnsl if both are needed.
288     # We assume that if connect needs -lnsl, so does gethostbyname.
289     AC_CHECK_FUNC(connect, ,
290       AC_CHECK_LIB(socket, connect, SOCKET_LIBS="-lsocket",
291                 AC_MSG_ERROR(Function 'socket' not found.), $NSL_LIBS))
292     AC_SUBST(SOCKET_LIBS)
293 ])
294
295 #
296 # AC_ETHEREAL_PCAP_CHECK
297 #
298 AC_DEFUN([AC_ETHEREAL_PCAP_CHECK],
299 [
300         if test -z "$pcap_dir"
301         then
302           # Pcap header checks
303           # XXX need to set a var AC_CHECK_HEADER(pcap.h,,)
304
305           #
306           # The user didn't specify a directory in which libpcap resides;
307           # we assume that the current library search path will work,
308           # but we may have to look for the header in a "pcap"
309           # subdirectory of "/usr/include" or "/usr/local/include",
310           # as some systems apparently put "pcap.h" in a "pcap"
311           # subdirectory, and we also check "$prefix/include" - and
312           # "$prefix/include/pcap", in case $prefix is set to
313           # "/usr/include" or "/usr/local/include".
314           #
315           # XXX - should we just add "$prefix/include" to the include
316           # search path and "$prefix/lib" to the library search path?
317           #
318           AC_MSG_CHECKING(for extraneous pcap header directories)
319           found_pcap_dir=""
320           pcap_dir_list="/usr/include/pcap $prefix/include/pcap $prefix/include"
321           if test "x$ac_cv_enable_usr_local" = "xyes" ; then
322             pcap_dir_list="$pcap_dir_list /usr/local/include/pcap"
323           fi
324           for pcap_dir in $pcap_dir_list
325           do
326             if test -d $pcap_dir ; then
327                 if test x$pcap_dir != x/usr/include -a x$pcap_dir != x/usr/local/include ; then
328                     CFLAGS="$CFLAGS -I$pcap_dir"
329                     CPPFLAGS="$CPPFLAGS -I$pcap_dir"
330                 fi
331                 found_pcap_dir=" $found_pcap_dir -I$pcap_dir"
332                 break
333             fi
334           done
335
336           if test "$found_pcap_dir" != "" ; then
337             AC_MSG_RESULT(found --$found_pcap_dir added to CFLAGS)
338           else
339             AC_MSG_RESULT(not found)
340           fi
341         else
342           #
343           # The user specified a directory in which libpcap resides,
344           # so add the "include" subdirectory of that directory to
345           # the include file search path and the "lib" subdirectory
346           # of that directory to the library search path.
347           #
348           # XXX - if there's also a libpcap in a directory that's
349           # already in CFLAGS, CPPFLAGS, or LDFLAGS, this won't
350           # make us find the version in the specified directory,
351           # as the compiler and/or linker will search that other
352           # directory before it searches the specified directory.
353           #
354           CFLAGS="$CFLAGS -I$pcap_dir/include"
355           CPPFLAGS="$CPPFLAGS -I$pcap_dir/include"
356           AC_ETHEREAL_ADD_DASH_L(LDFLAGS, $pcap_dir/lib)
357         fi
358
359         # Pcap header check
360         AC_CHECK_HEADER(pcap.h,, 
361             AC_MSG_ERROR([[Header file pcap.h not found; if you installed libpcap
362 from source, did you also do \"make install-incl\", and if you installed a
363 binary package of libpcap, is there also a developer's package of libpcap,
364 and did you also install that package?]]))
365
366         #
367         # Check to see if we find "pcap_open_live" in "-lpcap".
368         #
369         AC_CHECK_LIB(pcap, pcap_open_live,
370           [
371             PCAP_LIBS=-lpcap
372             AC_DEFINE(HAVE_LIBPCAP, 1, [Define to use libpcap library])
373           ], [
374             AC_MSG_CHECKING([for pcap_open_live in -lpcap -lcfg -lodm])
375             ac_save_LIBS="$LIBS"
376             LIBS="-lpcap -lcfg -lodm"
377             AC_TRY_LINK(
378                 [
379 #       include <pcap.h>
380                 ],
381                 [
382         pcap_open_live(NULL, 0, 0, 0, NULL);
383                 ],
384                 [
385                 AC_MSG_RESULT([yes])
386                 PCAP_LIBS="-lpcap -lcfg -lodm"
387                 AC_DEFINE(HAVE_LIBPCAP, 1, [Define to use libpcap library])
388                 ],
389                 [
390                 AC_MSG_RESULT([no])
391                 AC_MSG_ERROR([Library libpcap not found.])
392                 ])
393             LIBS=$ac_save_LIBS
394           ], $SOCKET_LIBS $NSL_LIBS)
395         AC_SUBST(PCAP_LIBS)
396
397         #
398         # Check whether various variables and functions are defined by
399         # libpcap.
400         #
401         ac_save_LIBS="$LIBS"
402         AC_MSG_CHECKING(whether pcap_version is defined by libpcap)
403         LIBS="$PCAP_LIBS $SOCKET_LIBS $NSL_LIBS $LIBS"
404         AC_TRY_LINK(
405            [
406 #       include <stdio.h>
407         extern char *pcap_version;
408            ],
409            [
410         printf ("%s\n", pcap_version);
411            ],
412            ac_cv_pcap_version_defined=yes,
413            ac_cv_pcap_version_defined=no,
414            [echo $ac_n "cross compiling; assumed OK... $ac_c"])
415         if test "$ac_cv_pcap_version_defined" = yes ; then
416                 AC_MSG_RESULT(yes)
417                 AC_DEFINE(HAVE_PCAP_VERSION, 1, [Define if libpcap version is known])
418         else
419                 AC_MSG_RESULT(no)
420         fi
421         AC_CHECK_FUNCS(pcap_findalldevs pcap_lib_version pcap_open_dead)
422         AC_CHECK_FUNCS(pcap_datalink_val_to_name pcap_datalink_name_to_val)
423         AC_CHECK_FUNCS(pcap_list_datalinks pcap_set_datalink)
424         LIBS="$ac_save_LIBS"
425 ])
426
427 #
428 # AC_ETHEREAL_ZLIB_CHECK
429 #
430 AC_DEFUN([AC_ETHEREAL_ZLIB_CHECK],
431 [
432         if test "x$zlib_dir" != "x"
433         then
434           #
435           # The user specified a directory in which zlib resides,
436           # so add the "include" subdirectory of that directory to
437           # the include file search path and the "lib" subdirectory
438           # of that directory to the library search path.
439           #
440           # XXX - if there's also a zlib in a directory that's
441           # already in CFLAGS, CPPFLAGS, or LDFLAGS, this won't
442           # make us find the version in the specified directory,
443           # as the compiler and/or linker will search that other
444           # directory before it searches the specified directory.
445           #
446           ethereal_save_CFLAGS="$CFLAGS"
447           CFLAGS="$CFLAGS -I$zlib_dir/include"
448           ethereal_save_CPPFLAGS="$CPPFLAGS"
449           CPPFLAGS="$CPPFLAGS -I$zlib_dir/include"
450           ethereal_save_LIBS="$LIBS"
451           AC_ETHEREAL_ADD_DASH_L(LIBS, $zlib_dir/lib)
452         fi
453
454         #
455         # Make sure we have "zlib.h".  If we don't, it means we probably
456         # don't have zlib, so don't use it.
457         #
458         AC_CHECK_HEADER(zlib.h,,
459           [
460             if test "x$zlib_dir" != "x"
461             then
462               #
463               # The user used "--with-zlib=" to specify a directory
464               # containing zlib, but we didn't find the header file
465               # there; that either means they didn't specify the
466               # right directory or are confused about whether zlib
467               # is, in fact, installed.  Report the error and give up.
468               #
469               AC_MSG_ERROR([zlib header not found in directory specified in --with-zlib])
470             else
471               if test "x$want_zlib" = "xyes"
472               then
473                 #
474                 # The user tried to force us to use the library, but we
475                 # couldn't find the header file; report an error.
476                 #
477                 AC_MSG_ERROR(Header file zlib.h not found.)
478               else
479                 #
480                 # We couldn't find the header file; don't use the
481                 # library, as it's probably not present.
482                 #
483                 want_zlib=no
484               fi
485             fi
486           ])
487
488         if test "x$want_zlib" != "xno"
489         then
490                 #
491                 # Well, we at least have the zlib header file.
492                 #
493                 # Check for "gzgets()" in zlib, because we need it, but
494                 # some older versions of zlib don't have it.  It appears
495                 # from the zlib ChangeLog that any released version of zlib
496                 # with "gzgets()" should have the other routines we
497                 # depend on, such as "gzseek()", "gztell()", and "zError()".
498                 #
499                 # Another reason why we require "gzgets()" is that
500                 # some versions of zlib that didn't have it, such
501                 # as 1.0.8, had a bug in "gzseek()" that meant that it
502                 # doesn't work correctly on uncompressed files; this
503                 # means we cannot use version 1.0.8.  (Unfortunately,
504                 # that's the version that comes with recent X11 source,
505                 # and many people who install XFree86 on their Slackware
506                 # boxes don't realize that they should configure it to
507                 # use the native zlib rather than building and installing
508                 # the crappy old version that comes with XFree86.)
509                 #
510                 # I.e., we can't just avoid using "gzgets()", as
511                 # versions of zlib without "gzgets()" are likely to have
512                 # a broken "gzseek()".
513                 #
514                 AC_CHECK_LIB(z, gzgets,
515                 [
516                         if test "x$zlib_dir" != "x"
517                         then
518                                 #
519                                 # Put the "-I" and "-L" flags for zlib at
520                                 # the beginning of CFLAGS, CPPFLAGS, and
521                                 # LIBS.
522                                 #
523                                 LIBS=""
524                                 AC_ETHEREAL_ADD_DASH_L(LIBS, $zlib_dir/lib)
525                                 LIBS="$LIBS -lz $ethereal_save_LIBS"
526                         else
527                                 LIBS="-lz $LIBS"
528                         fi
529                         AC_DEFINE(HAVE_LIBZ, 1, [Define to use libz library])
530                 ],[
531                         if test "x$zlib_dir" != "x"
532                         then
533                                 #
534                                 # Restore the versions of CFLAGS, CPPFLAGS,
535                                 # and LIBS before we added the "-with-zlib="
536                                 # directory, as we didn't actually find
537                                 # zlib there, or didn't find a zlib that
538                                 # contains gzgets there.
539                                 #
540                                 CFLAGS="$ethereal_save_CFLAGS"
541                                 CPPFLAGS="$ethereal_save_CPPFLAGS"
542                                 LIBS="$ethereal_save_LIBS"
543                         fi
544                         want_zlib=no
545                 ])
546         fi
547
548         if test "x$want_zlib" != "xno"
549         then
550                 #
551                 # Well, we at least have the zlib header file and a zlib
552                 # with "gzgets()".
553                 #
554                 # Now check for "gzgets()" in zlib when linking with the
555                 # linker flags for GTK+ applications; people often grab
556                 # XFree86 source and build and install it on their systems,
557                 # and they appear sometimes to misconfigure XFree86 so that,
558                 # even on systems with zlib, it assumes there is no zlib,
559                 # so the XFree86 build process builds and installs its
560                 # own zlib in the X11 library directory.
561                 #
562                 # The XFree86 zlib is an older version that lacks
563                 # "gzgets()", and that's the zlib with which Ethereal
564                 # gets linked, so the build of Ethereal fails.
565                 #
566                 ac_save_CFLAGS="$CFLAGS"
567                 ac_save_LIBS="$LIBS"
568                 CFLAGS="$CFLAGS $GTK_CFLAGS"
569                 LIBS="$GTK_LIBS -lz $LIBS"
570                 AC_MSG_CHECKING([for gzgets missing when linking with X11])
571                 AC_TRY_LINK_FUNC(gzgets, AC_MSG_RESULT(no),
572                   [
573                     AC_MSG_RESULT(yes)
574                     AC_MSG_ERROR(old zlib found when linking with X11 - get rid of old zlib.)
575                   ])
576                 CFLAGS="$ac_save_CFLAGS"
577                 LIBS="$ac_save_LIBS"
578         fi
579 ])
580
581 #
582 # AC_ETHEREAL_LIBPCRE_CHECK
583 #
584 AC_DEFUN([AC_ETHEREAL_LIBPCRE_CHECK],
585 [
586         if test "x$pcre_dir" != "x"
587         then
588           #
589           # The user specified a directory in which libpcre resides,
590           # so add the "include" subdirectory of that directory to
591           # the include file search path and the "lib" subdirectory
592           # of that directory to the library search path.
593           #
594           # XXX - if there's also a libpcre in a directory that's
595           # already in CFLAGS, CPPFLAGS, or LDFLAGS, this won't
596           # make us find the version in the specified directory,
597           # as the compiler and/or linker will search that other
598           # directory before it searches the specified directory.
599           #
600           ethereal_save_CFLAGS="$CFLAGS"
601           CFLAGS="$CFLAGS -I$pcre_dir/include"
602           ethereal_save_CPPFLAGS="$CPPFLAGS"
603           CPPFLAGS="$CPPFLAGS -I$pcre_dir/include"
604           ethereal_save_LIBS="$LIBS"
605           LIBS="$LIBS -lpcre"
606           ethereal_save_LDFLAGS="$LDFLAGS"
607           LDFLAGS="$LDFLAGS -L$pcre_dir/lib"
608         fi
609
610         #
611         # Make sure we have "pcre.h".  If we don't, it means we probably
612         # don't have libpcre, so don't use it.
613         #
614         AC_CHECK_HEADER(pcre.h,,
615           [
616             if test "x$pcre_dir" != "x"
617             then
618               #
619               # The user used "--with-pcre=" to specify a directory
620               # containing libpcre, but we didn't find the header file
621               # there; that either means they didn't specify the
622               # right directory or are confused about whether libpcre
623               # is, in fact, installed.  Report the error and give up.
624               #
625               AC_MSG_ERROR([libpcre header not found in directory specified in --with-pcre])
626             else
627               if test "x$want_pcre" = "xyes"
628               then
629                 #
630                 # The user tried to force us to use the library, but we
631                 # couldn't find the header file; report an error.
632                 #
633                 AC_MSG_ERROR(Header file pcre.h not found.)
634               else
635                 #
636                 # We couldn't find the header file; don't use the
637                 # library, as it's probably not present.
638                 #
639                 want_pcre=no
640               fi
641             fi
642           ])
643
644         if test "x$want_pcre" != "xno"
645         then
646                 #
647                 # Well, we at least have the pcre header file.
648                 #
649                 # We're only using standard functions from libpcre,
650                 # so we don't need to perform extra checks.
651                 #
652                 AC_CHECK_LIB(pcre, pcre_compile,
653                 [
654                         if test "x$pcre_dir" != "x"
655                         then
656                                 #
657                                 # Put the "-I" and "-L" flags for pcre at
658                                 # the beginning of CFLAGS, CPPFLAGS,
659                                 # LDFLAGS, and LIBS.
660                                 #
661                                 PCRE_LIBS="-L$pcre_dir/lib -lpcre $ethereal_save_LIBS"
662                         else
663                                 PCRE_LIBS="-lpcre"
664                         fi
665                         AC_DEFINE(HAVE_LIBPCRE, 1, [Define to use libpcre library])
666                 ],[
667                         if test "x$pcre_dir" != "x"
668                         then
669                                 #
670                                 # Restore the versions of CFLAGS, CPPFLAGS,
671                                 # LDFLAGS, and LIBS before we added the
672                                 # "--with-pcre=" directory, as we didn't
673                                 # actually find pcre there.
674                                 #
675                                 CFLAGS="$ethereal_save_CFLAGS"
676                                 CPPFLAGS="$ethereal_save_CPPFLAGS"
677                                 LDFLAGS="$ethereal_save_LDFLAGS"
678                                 LIBS="$ethereal_save_LIBS"
679                                 PCRE_LIBS=""
680                         fi
681                         want_pcre=no
682                 ])
683                 AC_SUBST(PCRE_LIBS)
684         fi
685 ])
686
687 #
688 # AC_ETHEREAL_UCDSNMP_CHECK
689 #
690 AC_DEFUN([AC_ETHEREAL_UCDSNMP_CHECK],
691 [
692         if test "x$ucdsnmp_dir" != "x"
693         then
694                 #
695                 # The user specified a directory in which UCD SNMP resides,
696                 # so add the "include" subdirectory of that directory to
697                 # the include file search path and the "lib" subdirectory
698                 # of that directory to the library search path.
699                 #
700                 # XXX - if there's also a libpcap in a directory that's
701                 # already in CFLAGS, CPPFLAGS, or LDFLAGS, this won't
702                 # make us find the version in the specified directory,
703                 # as the compiler and/or linker will search that other
704                 # directory before it searches the specified directory.
705                 #
706                 CFLAGS="$CFLAGS -I$ucdsnmp_dir/include"
707                 CPPFLAGS="$CPPFLAGS -I$ucdsnmp_dir/include"
708                 AC_ETHEREAL_ADD_DASH_L(LDFLAGS, $ucdsnmp_dir/lib)
709         fi
710
711         #
712         # Check for one of the UCD SNMP header files we include,
713         # to see whether we have UCD SNMP installed.
714         #
715         AC_CHECK_HEADER(ucd-snmp/ucd-snmp-config.h,
716         [
717                 #
718                 # UCD SNMP or Net-SNMP might require various helper
719                 # libraries on various platforms, such as "-ldes425"
720                 # in "/usr/kerberos/lib" on some versions of Red
721                 # Hat Linux, or "-lkstat" on Solaris.
722                 # XXX - it may also require "-lcrypto" on some platforms;
723                 # we should check for that as well, rather than requiring
724                 # users to explicitly indicate whether it's required.
725                 #
726                 # XXX - autoconf really needs a way to test for
727                 # a given routine in a given library *and* to test
728                 # whether additional "-L"/"-R"/whatever flags are
729                 # needed *before* the "-l" flag for the library
730                 # and to test whether additional libraries are
731                 # needed after the library *and* to cache all that
732                 # information.
733                 #
734                 for extras in "" "-L/usr/kerberos/lib -ldes425" "-lkstat"
735                 do
736                         AC_CHECK_LIB(snmp, sprint_realloc_objid,
737                           [
738                                 SNMP_LIBS="-lsnmp $extras"; break
739                           ],
740                           [
741                                 #
742                                 # Throw away the cached "we didn't find it"
743                                 # answer, so that if we rerun "configure",
744                                 # we still do all these checks and don't
745                                 # just blithely assume we don't need
746                                 # the extra libraries.
747                                 #
748                                 unset ac_cv_lib_snmp_sprint_realloc_objid
749                           ], $SOCKET_LIBS $NSL_LIBS $SSL_LIBS $extras)
750                 done
751
752                 #
753                 # If we didn't find "sprint_realloc_objid()", fail.
754                 # Either the user needs a newer version of UCD SNMP
755                 # with "sprint_realloc_objid()", or they may need to
756                 # specify "--with-ssl".
757                 #
758                 if test "$ac_cv_lib_snmp_sprint_realloc_objid" = no; then
759                     AC_MSG_ERROR([UCD SNMP header files found, but sprint_realloc_objid not found in SNMP library.])
760                 fi
761
762                 #
763                 # We found it, so we have UCD SNMP.
764                 #
765                 AC_DEFINE(HAVE_UCD_SNMP, 1, [Define to enable support for UCD-SNMP])
766                 have_ucd_snmp="yes"
767         ],[
768                 #
769                 # No, we don't have it.
770                 # If the user explicitly asked for UCD SNMP, fail,
771                 # otherwise just don't use the UCD SNMP library.
772                 #
773                 if test "x$want_ucdsnmp" = "xyes" ; then
774                         AC_MSG_ERROR(Header file ucd-snmp/snmp.h not found.)
775                 fi
776         ])
777 ])
778
779 #
780 # AC_ETHEREAL_SSL_CHECK
781 #
782 AC_DEFUN([AC_ETHEREAL_SSL_CHECK],
783 [
784         want_ssl=defaultyes
785
786         AC_ARG_WITH(ssl,
787 changequote(<<, >>)dnl
788 <<  --with-ssl[=DIR]        use SSL crypto library (located in directory DIR, if supplied).   [default=yes, if present]>>,
789 changequote([, ])dnl
790         [
791         if   test "x$withval" = "xno";  then
792                 want_ssl=no
793         elif test "x$withval" = "xyes"; then
794                 want_ssl=yes
795         elif test -d "$withval"; then
796                 want_ssl=yes
797                 AC_ETHEREAL_ADD_DASH_L(LDFLAGS, ${withval}/lib)
798         fi
799         ])
800
801         if test "x$want_ssl" = "xdefaultyes"; then
802                 want_ssl=yes
803                 withval=/usr/local/ssl
804                 if test -d "$withval"; then
805                         AC_ETHEREAL_ADD_DASH_L(LDFLAGS, ${withval}/lib)
806                 fi
807         fi
808
809         if test "x$want_ssl" = "xyes"; then
810                 AC_CHECK_LIB(crypto, EVP_md5,
811                   [
812                     SSL_LIBS=-lcrypto
813                   ],,
814                 )
815         else
816                 AC_MSG_RESULT(not required)
817         fi
818 ])
819
820 #
821 # AC_ETHEREAL_RPM_CHECK
822 # Looks for the rpm program, and checks to see if we can redefine "_topdir".
823 #
824 AC_DEFUN([AC_ETHEREAL_RPM_CHECK],
825 [
826         AC_CHECK_PROG(ac_cv_ethereal_have_rpm, rpm, "yes", "no")
827         if test "x$ac_cv_ethereal_have_rpm" = "xyes"; then
828                 rpm --define '_topdir /tmp' > /dev/null 2>&1
829                 AC_MSG_CHECKING(to see if we can redefine _topdir)
830                 if test $? -eq 0 ; then
831                         AC_MSG_RESULT(yes)
832                         HAVE_RPM=yes
833                 else
834                         AC_MSG_RESULT(no.  You'll have to build packages manually.)
835                         HAVE_RPM=no
836                 fi
837         fi
838 ])
839
840 #
841 # AC_ETHEREAL_GNU_SED_CHECK
842 # Checks if GNU sed is the first sed in PATH.
843 #
844 AC_DEFUN([AC_ETHEREAL_GNU_SED_CHECK],
845 [
846         AC_MSG_CHECKING(for GNU sed as first sed in PATH)
847         if  ( sh -c "sed --version" </dev/null 2> /dev/null | grep "GNU sed" 2>&1 > /dev/null ) ;  then
848                 AC_MSG_RESULT(yes)
849                 HAVE_GNU_SED=yes
850         else
851                 AC_MSG_RESULT(no)
852                 HAVE_GNU_SED=no
853         fi
854 ])
855
856 #
857 # AC_ETHEREAL_ADNS_CHECK
858 #
859 AC_DEFUN([AC_ETHEREAL_ADNS_CHECK],
860 [
861         want_adns=defaultyes
862
863         AC_ARG_WITH(adns,
864 changequote(<<, >>)dnl
865 <<  --with-adns[=DIR]       use GNU ADNS (located in directory DIR, if supplied).   [default=yes, if present]>>,
866 changequote([, ])dnl
867         [
868         if   test "x$withval" = "xno";  then
869                 want_adns=no
870         elif test "x$withval" = "xyes"; then
871                 want_adns=yes
872         elif test -d "$withval"; then
873                 want_adns=yes
874                 AC_ETHEREAL_ADD_DASH_L(LDFLAGS, ${withval}/lib)
875         fi
876         ])
877
878         if test "x$want_adns" = "xdefaultyes"; then
879                 want_adns=yes
880                 withval=/usr/local
881                 if test -d "$withval"; then
882                         AC_ETHEREAL_ADD_DASH_L(LDFLAGS, ${withval}/lib)
883                 fi
884         fi
885
886         if test "x$want_adns" = "xyes"; then
887                 AC_CHECK_LIB(adns, adns_init,
888                   [
889                     ADNS_LIBS=-ladns
890                 AC_DEFINE(HAVE_GNU_ADNS, 1, [Define to use GNU ADNS library])
891                 have_good_adns=yes
892                   ],, $SOCKET_LIBS $NSL_LIBS
893                 )
894         else
895                 AC_MSG_RESULT(not required)
896         fi
897 ])
898
899
900 #
901 # AC_ETHEREAL_KRB5_CHECK
902 #
903 AC_DEFUN([AC_ETHEREAL_KRB5_CHECK],
904 [
905         if test "x$krb5_dir" != "x"
906         then
907           #
908           # The user specified a directory in which kerberos resides,
909           # so add the "include" subdirectory of that directory to
910           # the include file search path and the "lib" subdirectory
911           # of that directory to the library search path.
912           #
913           # XXX - if there's also a kerberos in a directory that's
914           # already in CFLAGS, CPPFLAGS, or LDFLAGS, this won't
915           # make us find the version in the specified directory,
916           # as the compiler and/or linker will search that other
917           # directory before it searches the specified directory.
918           #
919           ethereal_save_CFLAGS="$CFLAGS"
920           CFLAGS="$CFLAGS -I$krb5_dir/include"
921           ethereal_save_CPPFLAGS="$CPPFLAGS"
922           CPPFLAGS="$CPPFLAGS -I$krb5_dir/include"
923           #ethereal_save_LIBS="$LIBS"
924           #LIBS="$LIBS -lkrb5 -lasn1 -lcrypto -lroken -lcrypt -lresolv"
925           KRB5_LIBS="-lkrb5 -lasn1 -lcrypto -lroken -lcrypt -lresolv"
926           ethereal_save_LDFLAGS="$LDFLAGS"
927           LDFLAGS="$LDFLAGS -L$krb5_dir/lib"
928           ac_krb5_version=`grep -i heimdal $krb5_dir/include/krb5.h | head -n 1 | sed 's/^.*heimdal.*$/HEIMDAL/i'` 
929         else
930           AC_PATH_PROG(KRB5_CONFIG, krb5-config) 
931           if test -x "$KRB5_CONFIG"
932           then
933             KRB5_FLAGS=`"$KRB5_CONFIG" --cflags`
934             CFLAGS="$CFLAGS $KRB5_FLAGS"
935             CPPFLAGS="$CPPFLAGS $KRB5_FLAGS"
936             KRB5_LIBS=`"$KRB5_CONFIG" --libs`
937             # Looks like krb5-config is lacking -lresolv on some systems
938             AC_MSG_CHECKING(whether library list looks OK)
939             if echo "$KRB5_LIBS" | grep resolv >/dev/null
940             then
941                 AC_MSG_RESULT(yes)
942             else
943                 KRB5_LIBS="$KRB5_LIBS -lresolv"
944                 AC_MSG_RESULT(Adding -lresolv to libs)
945             fi
946
947             #LIBS="$LIBS $KRB5_LIBS"
948             ac_krb5_version=`"$KRB5_CONFIG" --version | head -n 1 | sed 's/^.*heimdal.*$/HEIMDAL/i'`
949           fi
950         fi
951
952         #
953         # Make sure we have "krb5.h".  If we don't, it means we probably
954         # don't have kerberos, so don't use it.
955         #
956         AC_CHECK_HEADER(krb5.h,,
957           [
958             if test "x$krb5_dir" != "x"
959             then
960               #
961               # The user used "--with-krb5=" to specify a directory
962               # containing kerberos, but we didn't find the header file
963               # there; that either means they didn't specify the
964               # right directory or are confused about whether kerberos
965               # is, in fact, installed.  Report the error and give up.
966               #
967               AC_MSG_ERROR([kerberos header not found in directory specified in --with-krb5])
968             else
969               if test "x$want_krb5" = "xyes"
970               then
971                 #
972                 # The user tried to force us to use the library, but we
973                 # couldn't find the header file; report an error.
974                 #
975                 AC_MSG_ERROR(Header file krb5.h not found.)
976               else
977                 #
978                 # We couldn't find the header file; don't use the
979                 # library, as it's probably not present.
980                 #
981                 want_krb5=no
982               fi
983             fi
984           ])
985
986         if test "x$want_krb5" != "xno" -a "x$ac_krb5_version" = "xHEIMDAL"
987         then
988                 #
989                 # Well, we at least have the krb5 header file.
990                 #
991                 AC_CHECK_LIB(krb5, krb5_kt_resolve,
992                 [
993                         if test "x$krb5_dir" != "x"
994                         then
995                                 #
996                                 # Put the "-I" and "-L" flags for krb5 at
997                                 # the beginning of CFLAGS, CPPFLAGS,
998                                 # LDFLAGS, and LIBS.
999                                 #
1000                                 KRB5_LIBS="-L$krb5_dir/lib $KRB5_LIBS"
1001                         fi
1002                         AC_DEFINE(HAVE_KERBEROS, 1, [Define to use kerberos])
1003                         AC_DEFINE(HAVE_HEIMDAL_KERBEROS, 1, [Define to use heimdal kerberos])
1004                 ],[
1005                         if test "x$krb5_dir" != "x"
1006                         then
1007                                 #
1008                                 # Restore the versions of CFLAGS, CPPFLAGS,
1009                                 # LDFLAGS, and LIBS before we added the
1010                                 # "--with-krb5=" directory, as we didn't
1011                                 # actually find kerberos there.
1012                                 #
1013                                 CFLAGS="$ethereal_save_CFLAGS"
1014                                 CPPFLAGS="$ethereal_save_CPPFLAGS"
1015                                 LDFLAGS="$ethereal_save_LDFLAGS"
1016                                 #LIBS="$ethereal_save_LIBS"
1017                                 KRB5_LIBS=""
1018                         fi
1019                         want_krb5=no
1020                 ], $KRB5_LIBS)
1021         else
1022                 KRB5_LIBS=""
1023                 want_krb5=no
1024         fi
1025         AC_SUBST(KRB5_LIBS)
1026 ])
1027