change the script to automatically stop on warning if compiling with gcc.
[obnox/wireshark/wip.git] / wiretap / configure.in
1 # $Id$
2 #
3 AC_INIT(wtap.c)
4
5 AC_PREREQ(2.52)
6
7 AC_CANONICAL_HOST
8 AC_CANONICAL_TARGET
9
10 AM_INIT_AUTOMAKE(libwtap.a, 0.0.0)
11 AM_CONFIG_HEADER(config.h)
12
13 AM_DISABLE_STATIC
14
15 dnl Checks for programs.
16 AC_PROG_CC
17 AC_PROG_CPP
18 AC_PROG_YACC
19 AM_PROG_LEX
20 AC_PROG_LIBTOOL
21 AC_PATH_PROG(LEX, flex)
22
23 AC_SUBST(FLEX_PATH)
24
25 #
26 # If we're running gcc, add '-Wall -W -Wcast-qual' to CFLAGS, and add
27 # '-D_U_="__attribute__((unused))"' as well, so we can use _U_ to
28 # flag unused function arguments and not get warnings about them.
29 # If "--with-extra-gcc-checks" was specified, add some additional
30 # warning checks.
31 #
32 # Otherwise, add '-D_U_=""', so that _U_ used to flag an unused function
33 # argument will compile with non-GCC compilers.
34 #
35 AC_ARG_WITH(extra-gcc-checks,
36 [  --with-extra-gcc-checks Do additional -W checks in GCC.  [default=no]],
37 [
38         if test $withval != no
39         then
40                 wireshark_extra_gcc_flags=" -Wcast-qual -Wcast-align -Wbad-function-cast -pedantic -Wmissing-declarations -Wwrite-strings"
41         fi
42 ],)
43 AC_MSG_CHECKING(to see if we can add '-Wall -W$wireshark_extra_gcc_flags' to CFLAGS)
44 if test x$GCC != x ; then
45   CFLAGS="-D_U_=\"__attribute__((unused))\" -Wall -W $wireshark_extra_gcc_flags $CFLAGS"
46   AC_MSG_RESULT(yes)
47 else
48   CFLAGS="-D_U_=\"\" $CFLAGS"
49   AC_MSG_RESULT(no)
50 fi
51
52 AC_MSG_CHECKING(to see if we can add '-Wdeclaration-after-statement' to CFLAGS)
53 if test x$GCC == xyes ; then
54   # some versions of GCC support this directive
55   rm -rf conftest*
56   echo "int foo;" >>conftest.c
57   if $CC -c -o conftest.o conftest.c -Wdeclaration-after-statement > /dev/null 2>&1 ; then
58     CFLAGS="$CFLAGS -Wdeclaration-after-statement"
59     AC_MSG_RESULT(yes)
60   else
61     AC_MSG_RESULT(no)
62   fi
63 else
64   # non-gcc compilers do not support this directive
65   AC_MSG_RESULT(no)
66 fi
67 rm -rf conftest*
68
69 AC_MSG_CHECKING(to see if we can add '-Wno-pointer-sign' to CFLAGS)
70 if test x$GCC == xyes ; then
71   # some versions of GCC support this directive
72   rm -rf conftest*
73   echo "int foo;" >>conftest.c
74   if $CC -c -o conftest.o conftest.c -Wno-pointer-sign > /dev/null 2>&1 ; then
75     CFLAGS="$CFLAGS -Wno-pointer-sign"
76     AC_MSG_RESULT(yes)
77   else
78     AC_MSG_RESULT(no)
79   fi
80 else
81   # non-gcc compilers do not support this directive
82   AC_MSG_RESULT(no)
83 fi
84 rm -rf conftest*
85
86 AC_ARG_WITH(warnings-as-errors,
87   AC_HELP_STRING( [--without-warnings-as-errors], 
88                   [Don't treat warnings as errors (only for gcc). [default=yes]]),
89 [
90   without_warnings_as_errors="no"
91   if test "x$GCC" != "x" && test "x$withval" = "xno"; then
92       without_warnings_as_errors="yes"
93   fi
94 ],
95   if test "x$GCC" != "x"; then
96     without_warnings_as_errors="no"
97   fi
98 )
99 AM_CONDITIONAL(HAVE_WARNINGS_AS_ERRORS, test "x$without_warnings_as_errors" = "xno")
100
101 #
102 # Add any platform-specific compiler flags needed.
103 #
104 AC_MSG_CHECKING(for platform-specific compiler flags)
105 if test "x$GCC" = x
106 then
107         #
108         # Not GCC - assume it's the vendor's compiler.
109         #
110         case "$host_os" in
111         hpux*)
112                 #
113                 # HP's ANSI C compiler; flags suggested by Jost Martin.
114                 # "-Ae" for ANSI C plus extensions such as "long long".
115                 # "+O2", for optimization.  XXX - works with "-g"?
116                 #
117                 CFLAGS="-Ae +O2 $CFLAGS"
118                 AC_MSG_RESULT(HP ANSI C compiler - added -Ae +O2)
119                 ;;
120         darwin*)
121                 #
122                 # It may be called "cc", but it's really a GCC derivative
123                 # with a problematic special precompiler and precompiled
124                 # headers; turn off the special precompiler, as some
125                 # apparently-legal code won't compile with its precompiled
126                 # headers.
127                 #
128                 CFLAGS="-no-cpp-precomp $CFLAGS"
129                 AC_MSG_RESULT(Apple GCC - added -no-cpp-precomp)
130                 ;;
131         *)
132                 AC_MSG_RESULT(none needed)
133                 ;;
134         esac
135 else
136         case "$host_os" in
137         darwin*)
138                 #
139                 # See comments above about Apple's lovely C compiler.
140                 #
141                 CFLAGS="-no-cpp-precomp $CFLAGS"
142                 AC_MSG_RESULT(Apple GCC - added -no-cpp-precomp)
143                 ;;
144         *)
145         AC_MSG_RESULT(none needed)
146         ;;
147         esac
148 fi
149
150
151 #
152 # Add any platform-specific linker flags needed.
153 #
154 AC_MSG_CHECKING(for platform-specific linker flags)
155 case "$host_os" in
156 darwin*)
157         #
158         # Add -Wl,-single_module to the LDFLAGS used with shared
159         # libraries, to fix some error that show up in some cases;
160         # some Apple documentation recommends it for most shared
161         # libraries.
162         #
163         LDFLAGS_SHAREDLIB="-Wl,-single_module"
164         #
165         # Add -Wl,-search_paths_first to make sure that if we search
166         # directories A and B, in that order, for a given library, a
167         # non-shared version in directory A, rather than a shared
168         # version in directory B, is chosen (so we can use
169         # --with-pcap=/usr/local to force all programs to be linked
170         # with a static version installed in /usr/local/lib rather than
171         # the system version in /usr/lib).
172         #
173         LDFLAGS="-Wl,-search_paths_first $LDFLAGS"
174         AC_MSG_RESULT([Apple linker - added -Wl,-single_module and -Wl,-search_paths_first])
175         ;;
176 cygwin*)
177         #
178         # Shared libraries in cygwin/Win32 must never contain
179         # undefined symbols.
180         #
181         LDFLAGS="$LDFLAGS -no-undefined"
182         AC_MSG_RESULT(CygWin GNU ld - added -no-undefined)
183         ;;
184 *)
185         AC_MSG_RESULT(none needed)
186         ;;
187 esac
188 AC_SUBST(LDFLAGS_SHAREDLIB)
189
190 AC_ARG_ENABLE(profile-build,
191 [  --enable-profile-build  build profile-ready binaries.  [default=no]],enable_profile_build=$enableval,enable_profile_build=no)
192 AM_CONDITIONAL(USE_PROFILE_BUILD, test x$enable_profile_build = xyes)
193 AC_MSG_CHECKING(if profile builds must be generated)
194 if test "x$enable_profile_build" = "xyes" ; then
195         if test -n "$GCC" ; then
196                 AC_MSG_RESULT(yes)
197                 CFLAGS=" -pg $CFLAGS"
198         else
199                 AC_MSG_RESULT(no)
200                 echo "Building profile binaries currently only supported for GCC."
201         fi
202 else
203         AC_MSG_RESULT(no)
204 fi
205         
206 AC_ARG_ENABLE(gtk2,
207 [  --disable-gtk2           build Glib1/Gtk1+-based wireshark/tshark.  [default=no]],enable_gtk2=$enableval,enable_gtk2=yes)
208
209 if test "x$enable_gtk2" = "xyes" ; then
210         AM_PATH_GLIB_2_0(2.0.0, CFLAGS="$CFLAGS $GLIB_CFLAGS" LIBS="$LIBS $GLIB_LIBS", , gmodule)
211 else
212         AM_PATH_GLIB(1.2.0, CFLAGS="$CFLAGS $GLIB_CFLAGS" LIBS="$LIBS $GLIB_LIBS", , gmodule)
213 fi
214
215 dnl Look in /usr/local for header files and libraries ?
216 AC_ARG_ENABLE(usr-local,
217 [  --enable-usr-local      look for headers and libs in /usr/local tree.  [default=yes]],enable_usr_local=$enableval,enable_usr_local=yes)
218
219 AC_MSG_CHECKING(whether to use /usr/local for headers and libraries)
220 if test "x$enable_usr_local" = "xyes" ; then
221         AC_MSG_RESULT(yes)
222         #
223         # Arrange that we search for header files in "/usr/local/include",
224         # as various packages we use ("libpcap", "zlib") may have been installed
225         # under "/usr/local/include".
226         #
227         # We do this after checking for GLib, so that "-I/usr/local/include"
228         # comes after any "-I" flags added by "AM_PATH_GLIB"; if the user has
229         # installed a pre-1.2.9 version of GLib, it'd probably go under
230         # "/usr/local", and if they then install 1.2.9 or later without
231         # uninstalling the pre-1.2.9 version, 1.2.9's header files won't be
232         # in "/usr/local/include" (they're put in a separate directory so that
233         # GLib 1.2[.x] and 1.3[.x]/2.x can coexist), and if we search
234         # "/usr/local/include" before searching the directory "AM_PATH_GLIB"
235         # specifies, we may pick up headers from the older version.
236         #
237         CFLAGS="$CFLAGS -I/usr/local/include"
238         CPPFLAGS="$CPPFLAGS -I/usr/local/include"
239
240         #
241         # Arrange that we search for libraries in "/usr/local/lib", as we'll
242         # be testing whether zlib has gzgets, and we need to be able to find
243         # zlib even if it's in "/usr/local/lib".
244         #
245         # We do this after checking for GLib; see above.
246         #
247         LDFLAGS="$LDFLAGS -L/usr/local/lib"
248 else
249         AC_MSG_RESULT(no)
250 fi
251
252 dnl Checks for header files
253 AC_HEADER_STDC
254 AC_CHECK_HEADERS(sys/time.h netinet/in.h unistd.h fcntl.h sys/stat.h sys/types.h)
255
256 #
257 # Define WS_VAR_IMPORT appropriately for declarations of external
258 # variables exported from dynamically-linked libraries.
259 #
260 AC_DEFINE(WS_VAR_IMPORT, extern, [Define as the string to precede external variable declarations in dynamically-linked libraries])
261
262 # We must know our byte order
263 AC_C_BIGENDIAN
264
265 #
266 # Does GLib define G_GINT64_MODIFIER?
267 #
268 AC_MSG_CHECKING([[whether glib.h defines the G_GINT64_MODIFIER macro]])
269 AC_COMPILE_IFELSE(
270   [
271     AC_LANG_SOURCE(
272       [[
273         #include <glib.h>
274         #if GTK_MAJOR_VERSION >= 2
275         #include <glib/gprintf.h>
276         #endif
277         #include <stdio.h>
278
279         main()
280         {
281           char strbuf[16+1];
282           g_snprintf(strbuf, sizeof strbuf, "%" G_GINT64_MODIFIER "x\n", (gint64)1);
283         }
284       ]])
285   ],
286   [
287     AC_MSG_RESULT(yes)
288   ],
289   [
290     AC_MSG_RESULT(no)
291     AC_WIRETAP_CHECK_64BIT_FORMAT(ll,
292       [
293         AC_WIRETAP_CHECK_64BIT_FORMAT(L,
294           [
295             AC_WIRETAP_CHECK_64BIT_FORMAT(q,
296               [
297                 AC_MSG_ERROR([neither %llx nor %Lx nor %qx worked on a 64-bit integer])
298               ])
299           ])
300       ])
301   ])
302
303 #
304 # Look for libpcap, so we can include <pcap.h> in libpcap.c if it's
305 # found.
306 #
307 # "--with-pcap" is merely done to allow the user to specify a directory
308 # in which to look for <pcap.h> (and so that specifying it to the
309 # top-level Wireshark configure script specifies it to the Wiretap
310 # configure script as well); we search for it regardless of whether
311 # "--without-pcap" was specified, as Wiretap isn't linked with it and
312 # there's no benefit to not looking for the header.
313 #
314 AC_ARG_WITH(pcap,
315 [  --with-pcap=DIR         libpcap is located in directory DIR.],
316 [
317         if test $withval != yes -a $withval != no
318         then
319                 pcap_dir=$withval
320         fi
321 ],[
322         pcap_dir=
323 ])
324 AC_WIRETAP_PCAP_CHECK
325
326 dnl zlib check
327 AC_MSG_CHECKING(whether to use zlib for reading compressed capture files)
328
329 AC_ARG_WITH(zlib,
330 [  --with-zlib[=DIR]       use zlib (located in directory DIR, if supplied) to read compressed data.  [default=yes, if present]],
331 [
332         if test $withval = no
333         then
334                 want_zlib=no
335         elif test $withval = yes
336         then
337                 want_zlib=yes
338         else
339                 want_zlib=yes
340                 zlib_dir=$withval
341         fi
342 ],[
343         #
344         # Use zlib if it's present, otherwise don't.
345         #
346         want_zlib=ifpresent
347         zlib_dir=
348 ])
349 if test "x$want_zlib" = "xno" ; then
350         AC_MSG_RESULT(no)
351 else
352         AC_MSG_RESULT(yes)
353         AC_WIRETAP_ZLIB_CHECK
354         if test "x$want_zlib" = "xno" ; then
355                 AC_MSG_RESULT(zlib not found - disabling compressed capture file support)
356         fi
357 fi
358
359 AC_OUTPUT(Makefile)