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