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