Replace "--enable-zlib" with "--with-zlib", and have it take an optional
[obnox/wireshark/wip.git] / wiretap / 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.14 2002/04/08 01:34:39 guy Exp $
6 dnl
7
8 #
9 # AC_WIRETAP_ADD_DASH_L
10 #
11 # Add to the variable specified as the first argument a "-L" flag for the
12 # directory specified as the second argument, and, on Solaris, add a
13 # "-R" flag for it as well.
14 #
15 # XXX - IRIX, and other OSes, may require some flag equivalent to
16 # "-R" here.
17 #
18 AC_DEFUN(AC_WIRETAP_ADD_DASH_L,
19 [$1="$$1 -L$2"
20 case "$host_os" in
21   solaris*)
22     $1="$$1 -R$2"
23   ;;
24 esac
25 ])
26
27 #
28 # AC_WIRETAP_PCAP_CHECK
29 #
30 AC_DEFUN(AC_WIRETAP_PCAP_CHECK,
31 [
32         if test -z "$pcap_dir"
33         then
34           #
35           # The user didn't specify a directory in which libpcap resides;
36           # we assume that the current library search path will work,
37           # but we may have to look for the header in a "pcap"
38           # subdirectory of "/usr/include" or "/usr/local/include",
39           # as some systems apparently put "pcap.h" in a "pcap"
40           # subdirectory, and we also check "$prefix/include".
41           #
42           # XXX - should we just add "$prefix/include" to the include
43           # search path?
44           #
45           AC_MSG_CHECKING(for extraneous pcap header directories)
46           found_pcap_dir=""
47           for pcap_dir in /usr/include/pcap /usr/local/include/pcap $prefix/include
48           do
49             if test -d $pcap_dir ; then
50               CFLAGS="$CFLAGS -I$pcap_dir"
51               CPPFLAGS="$CPPFLAGS -I$pcap_dir"
52               found_pcap_dir=" $found_pcap_dir -I$pcap_dir"
53             fi
54           done
55
56           if test "$found_pcap_dir" != "" ; then
57             AC_MSG_RESULT(found --$found_pcap_dir added to CFLAGS)
58           else
59             AC_MSG_RESULT(not found)
60           fi
61         else
62           #
63           # The user specified a directory in which libpcap resides,
64           # so add the "include" subdirectory of that directory to
65           # the include file search path.
66           #
67           # XXX - if there's also a libpcap in a directory that's
68           # already in CFLAGS or CPPFLAGS, this won't make us find
69           # the version in the specified directory, as the compiler
70           # will search that other directory before it searches the
71           # specified directory.
72           #
73           CFLAGS="$CFLAGS -I$pcap_dir/include"
74           CPPFLAGS="$CPPFLAGS -I$pcap_dir/include"
75         fi
76
77         # Pcap header check
78         AC_CHECK_HEADERS(pcap.h)
79 ])
80
81 #
82 # AC_WIRETAP_ZLIB_CHECK
83 #
84 AC_DEFUN(AC_WIRETAP_ZLIB_CHECK,
85 [
86         if test "x$zlib_dir" != "x"
87         then
88           #
89           # The user specified a directory in which zlib resides,
90           # so add the "include" subdirectory of that directory to
91           # the include file search path and the "lib" subdirectory
92           # of that directory to the library search path.
93           #
94           # XXX - if there's also a zlib in a directory that's
95           # already in CFLAGS, CPPFLAGS, or LDFLAGS, this won't
96           # make us find the version in the specified directory,
97           # as the compiler and/or linker will search that other
98           # directory before it searches the specified directory.
99           #
100           wiretap_save_CFLAGS="$CFLAGS"
101           CFLAGS="$CFLAGS -I$zlib_dir/include"
102           wiretap_save_CPPLAGS="$CPPLAGS"
103           CPPFLAGS="$CPPFLAGS -I$zlib_dir/include"
104           wiretap_save_LIBS="$LIBS"
105           AC_WIRETAP_ADD_DASH_L(LIBS, $zlib_dir/lib)
106         fi
107
108         #
109         # Make sure we have "zlib.h".  If we don't, it means we probably
110         # don't have zlib, so don't use it.
111         #
112         AC_CHECK_HEADER(zlib.h,,
113           [
114             if test "x$zlib_dir" != "x"
115             then
116               #
117               # The user used "--with-zlib=" to specify a directory
118               # containing zlib, but we didn't find the header file
119               # there; that either means they didn't specify the
120               # right directory or are confused about whether zlib
121               # is, in fact, installed.  Report the error and give up.
122               #
123               AC_MSG_ERROR([zlib header not found in directory specified in --with-zlib])
124             else
125               if test "x$want_zlib" = "xyes"
126               then
127                 #
128                 # The user tried to force us to use the library, but we
129                 # couldn't find the header file; report an error.
130                 #
131                 AC_MSG_ERROR(Header file zlib.h not found.)
132               else
133                 #
134                 # We couldn't find the header file; don't use the
135                 # library, as it's probably not present.
136                 #
137                 want_zlib=no
138               fi
139             fi
140           ])
141
142         if test "x$want_zlib" != "xno"
143         then
144                 #
145                 # Well, we at least have the zlib header file.
146                 #
147                 # Check for "gzgets()" in zlib, because we need it, but
148                 # some older versions of zlib don't have it.  It appears
149                 # from the zlib ChangeLog that any released version of zlib
150                 # with "gzgets()" should have the other routines we
151                 # depend on, such as "gzseek()", "gztell()", and "zError()".
152                 #
153                 # Another reason why we require "gzgets()" is that
154                 # some versions of zlib that didn't have it, such
155                 # as 1.0.8, had a bug in "gzseek()" that meant that it
156                 # doesn't work correctly on uncompressed files; this
157                 # means we cannot use version 1.0.8.  (Unfortunately,
158                 # that's the version that comes with recent X11 source,
159                 # and many people who install XFree86 on their Slackware
160                 # boxes don't realize that they should configure it to
161                 # use the native zlib rather than building and installing
162                 # the crappy old version that comes with XFree86.)
163                 #
164                 # I.e., we can't just avoid using "gzgets()", as
165                 # versions of zlib without "gzgets()" are likely to have
166                 # a broken "gzseek()".
167                 #
168                 AC_CHECK_LIB(z, gzgets,
169                 [
170                         if test "x$zlib_dir" != "x"
171                         then
172                                 #
173                                 # Put the "-I" and "-L" flags for zlib at
174                                 # the beginning of CFLAGS, CPPFLAGS, and
175                                 # LIBS.
176                                 #
177                                 LIBS=""
178                                 AC_WIRETAP_ADD_DASH_L(LIBS, $zlib_dir/lib)
179                                 LIBS="$LIBS -lz $wiretap_save_LIBS"
180                         else
181                                 LIBS="-lz $LIBS"
182                         fi
183                         AC_DEFINE(HAVE_LIBZ)
184                 ],[
185                         if test "x$zlib_dir" != "x"
186                         then
187                                 #
188                                 # Restore the versions of CFLAGS, CPPFLAGS,
189                                 # and LIBS before we added the "-with-zlib="
190                                 # directory, as we didn't actually find
191                                 # zlib there, or didn't find a zlib that
192                                 # contains gzgets there.
193                                 #
194                                 CFLAGS="$wiretap_save_CFLAGS"
195                                 CPPFLAGS="$wiretap_save_CPPLAGS"
196                                 LIBS="$wiretap_save_LIBS"
197                         fi
198                         want_zlib=no
199                 ])
200         fi
201
202         if test "x$want_zlib" != "xno"
203         then
204                 #
205                 # Well, we at least have the zlib header file and a zlib
206                 # with "gzgets()".
207                 #
208                 # Now check for "gzgets()" in zlib when linking with the
209                 # linker flags for GTK+ applications; people often grab
210                 # XFree86 source and build and install it on their systems,
211                 # and they appear sometimes to misconfigure XFree86 so that,
212                 # even on systems with zlib, it assumes there is no zlib,
213                 # so the XFree86 build process builds and installs its
214                 # own zlib in the X11 library directory.
215                 #
216                 # The XFree86 zlib is an older version that lacks
217                 # "gzgets()", and that's the zlib with which Ethereal
218                 # gets linked, so the build of Ethereal fails.
219                 #
220                 ac_save_CFLAGS="$CFLAGS"
221                 ac_save_LIBS="$LIBS"
222                 CFLAGS="$CFLAGS $GTK_CFLAGS"
223                 LIBS="$GTK_LIBS -lz $LIBS"
224                 AC_MSG_CHECKING([for gzgets missing when linking with X11])
225                 AC_TRY_LINK_FUNC(gzgets, AC_MSG_RESULT(no),
226                   [
227                     AC_MSG_RESULT(yes)
228                     AC_MSG_ERROR(old zlib found when linking with X11 - get rid of old zlib.)
229                   ])
230                 CFLAGS="$ac_save_CFLAGS"
231                 LIBS="$ac_save_LIBS"
232         fi
233 ])