Add -Werror when using GCC only to the Makefile.am of the base
[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 "-Wcast-align"
30 # as well.  (Add more checks here in the future?)
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 -Wcast-qual -Werror $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 # Create the USING_GCC variable for use in Makefile.am files
53 AM_CONDITIONAL(USING_GCC, test "x$GCC" != "x")
54
55 #
56 # Add any platform-specific compiler flags needed.
57 #
58 AC_MSG_CHECKING(for platform-specific compiler flags)
59 if test "x$GCC" = x
60 then
61         #
62         # Not GCC - assume it's the vendor's compiler.
63         #
64         case "$host_os" in
65         hpux*)
66                 #
67                 # HP's ANSI C compiler; flags suggested by Jost Martin.
68                 # "-Ae" for ANSI C plus extensions such as "long long".
69                 # "+O2", for optimization.  XXX - works with "-g"?
70                 #
71                 CFLAGS="-Ae +O2 $CFLAGS"
72                 AC_MSG_RESULT(HP ANSI C compiler - added -Ae +O2)
73                 ;;
74         darwin*)
75                 #
76                 # It may be called "cc", but it's really a GCC derivative
77                 # with a problematic special precompiler and precompiled
78                 # headers; turn off the special precompiler, as some
79                 # apparently-legal code won't compile with its precompiled
80                 # headers.
81                 #
82                 CFLAGS="-no-cpp-precomp $CFLAGS"
83                 AC_MSG_RESULT(Apple GCC - added -no-cpp-precomp)
84                 ;;
85         *)
86                 AC_MSG_RESULT(none needed)
87                 ;;
88         esac
89 else
90         case "$host_os" in
91         darwin*)
92                 #
93                 # See comments above about Apple's lovely C compiler.
94                 #
95                 CFLAGS="-no-cpp-precomp $CFLAGS"
96                 AC_MSG_RESULT(Apple GCC - added -no-cpp-precomp)
97                 ;;
98         *)
99         AC_MSG_RESULT(none needed)
100         ;;
101         esac
102 fi
103
104
105 #
106 # Add any platform-specific linker flags needed.
107 #
108 AC_MSG_CHECKING(for platform-specific linker flags)
109 case "$host_os" in
110 darwin*)
111         #
112         # Add -Wl,-single_module to the LDFLAGS used with shared
113         # libraries, to fix some error that show up in some cases;
114         # some Apple documentation recommends it for most shared
115         # libraries.
116         #
117         LDFLAGS_SHAREDLIB="-Wl,-single_module"
118         #
119         # Add -Wl,-search_paths_first to make sure that if we search
120         # directories A and B, in that order, for a given library, a
121         # non-shared version in directory A, rather than a shared
122         # version in directory B, is chosen (so we can use
123         # --with-pcap=/usr/local to force all programs to be linked
124         # with a static version installed in /usr/local/lib rather than
125         # the system version in /usr/lib).
126         #
127         LDFLAGS="-Wl,-search_paths_first $LDFLAGS"
128         AC_MSG_RESULT(Apple linker - added -Wl,-single_module and -Wl,-search_paths_first)
129         ;;
130 cygwin*)
131         #
132         # Shared libraries in cygwin/Win32 must never contain
133         # undefined symbols.
134         #
135         LDFLAGS="$LDFLAGS -no-undefined"
136         AC_MSG_RESULT(CygWin GNU ld - added -no-undefined)
137         ;;
138 *)
139         AC_MSG_RESULT(none needed)
140         ;;
141 esac
142 AC_SUBST(LDFLAGS_SHAREDLIB)
143
144 AC_ARG_ENABLE(profile-build,
145 [  --enable-profile-build  build profile-ready binaries.  [default=no]],enable_profile_build=$enableval,enable_profile_build=no)
146 AM_CONDITIONAL(USE_PROFILE_BUILD, test x$enable_profile_build = xyes)
147 AC_MSG_CHECKING(if profile builds must be generated)
148 if test "x$enable_profile_build" = "xyes" ; then
149         if test -n "$GCC" ; then
150                 AC_MSG_RESULT(yes)
151                 CFLAGS=" -pg $CFLAGS"
152         else
153                 AC_MSG_RESULT(no)
154                 echo "Building profile binaries currently only supported for GCC."
155         fi
156 else
157         AC_MSG_RESULT(no)
158 fi
159         
160 AC_ARG_ENABLE(gtk2,
161 [  --disable-gtk2           build Glib1/Gtk1+-based wireshark/tshark.  [default=no]],enable_gtk2=$enableval,enable_gtk2=yes)
162
163 if test "x$enable_gtk2" = "xyes" ; then
164         AM_PATH_GLIB_2_0(2.0.0, CFLAGS="$CFLAGS $GLIB_CFLAGS" LIBS="$LIBS $GLIB_LIBS", , gmodule)
165 else
166         AM_PATH_GLIB(1.2.0, CFLAGS="$CFLAGS $GLIB_CFLAGS" LIBS="$LIBS $GLIB_LIBS", , gmodule)
167 fi
168
169 dnl Look in /usr/local for header files and libraries ?
170 AC_ARG_ENABLE(usr-local,
171 [  --enable-usr-local      look for headers and libs in /usr/local tree.  [default=yes]],enable_usr_local=$enableval,enable_usr_local=yes)
172
173 AC_MSG_CHECKING(whether to use /usr/local for headers and libraries)
174 if test "x$enable_usr_local" = "xyes" ; then
175         AC_MSG_RESULT(yes)
176         #
177         # Arrange that we search for header files in "/usr/local/include",
178         # as various packages we use ("libpcap", "zlib") may have been installed
179         # under "/usr/local/include".
180         #
181         # We do this after checking for GLib, so that "-I/usr/local/include"
182         # comes after any "-I" flags added by "AM_PATH_GLIB"; if the user has
183         # installed a pre-1.2.9 version of GLib, it'd probably go under
184         # "/usr/local", and if they then install 1.2.9 or later without
185         # uninstalling the pre-1.2.9 version, 1.2.9's header files won't be
186         # in "/usr/local/include" (they're put in a separate directory so that
187         # GLib 1.2[.x] and 1.3[.x]/2.x can coexist), and if we search
188         # "/usr/local/include" before searching the directory "AM_PATH_GLIB"
189         # specifies, we may pick up headers from the older version.
190         #
191         CFLAGS="$CFLAGS -I/usr/local/include"
192         CPPFLAGS="$CPPFLAGS -I/usr/local/include"
193
194         #
195         # Arrange that we search for libraries in "/usr/local/lib", as we'll
196         # be testing whether zlib has gzgets, and we need to be able to find
197         # zlib even if it's in "/usr/local/lib".
198         #
199         # We do this after checking for GLib; see above.
200         #
201         LDFLAGS="$LDFLAGS -L/usr/local/lib"
202 else
203         AC_MSG_RESULT(no)
204 fi
205
206 dnl Checks for header files
207 AC_HEADER_STDC
208 AC_CHECK_HEADERS(sys/time.h netinet/in.h unistd.h fcntl.h sys/stat.h sys/types.h)
209
210 #
211 # Define WS_VAR_IMPORT appropriately for declarations of external
212 # variables exported from dynamically-linked libraries.
213 #
214 AC_DEFINE(WS_VAR_IMPORT, extern, [Define as the string to precede external variable declarations in dynamically-linked libraries])
215
216 # We must know our byte order
217 AC_C_BIGENDIAN
218
219 #
220 # Does GLib define G_GINT64_MODIFIER?
221 #
222 AC_MSG_CHECKING([[whether glib.h defines the G_GINT64_MODIFIER macro]])
223 AC_COMPILE_IFELSE(
224   [
225     AC_LANG_SOURCE(
226       [[
227         #include <glib.h>
228         #if GTK_MAJOR_VERSION >= 2
229         #include <glib/gprintf.h>
230         #endif
231         #include <stdio.h>
232
233         main()
234         {
235           char strbuf[16+1];
236           g_snprintf(strbuf, sizeof strbuf, "%" G_GINT64_MODIFIER "x\n", (gint64)1);
237         }
238       ]])
239   ],
240   [
241     AC_MSG_RESULT(yes)
242   ],
243   [
244     AC_MSG_RESULT(no)
245     AC_WIRETAP_CHECK_64BIT_FORMAT(ll,
246       [
247         AC_WIRETAP_CHECK_64BIT_FORMAT(L,
248           [
249             AC_WIRETAP_CHECK_64BIT_FORMAT(q,
250               [
251                 AC_MSG_ERROR([neither %llx nor %Lx nor %qx worked on a 64-bit integer])
252               ])
253           ])
254       ])
255   ])
256
257 #
258 # Look for libpcap, so we can include <pcap.h> in libpcap.c if it's
259 # found.
260 #
261 # "--with-pcap" is merely done to allow the user to specify a directory
262 # in which to look for <pcap.h> (and so that specifying it to the
263 # top-level Wireshark configure script specifies it to the Wiretap
264 # configure script as well); we search for it regardless of whether
265 # "--without-pcap" was specified, as Wiretap isn't linked with it and
266 # there's no benefit to not looking for the header.
267 #
268 AC_ARG_WITH(pcap,
269 [  --with-pcap=DIR         libpcap is located in directory DIR.],
270 [
271         if test $withval != yes -a $withval != no
272         then
273                 pcap_dir=$withval
274         fi
275 ],[
276         pcap_dir=
277 ])
278 AC_WIRETAP_PCAP_CHECK
279
280 dnl zlib check
281 AC_MSG_CHECKING(whether to use zlib for reading compressed capture files)
282
283 AC_ARG_WITH(zlib,
284 [  --with-zlib[=DIR]       use zlib (located in directory DIR, if supplied) to read compressed data.  [default=yes, if present]],
285 [
286         if test $withval = no
287         then
288                 want_zlib=no
289         elif test $withval = yes
290         then
291                 want_zlib=yes
292         else
293                 want_zlib=yes
294                 zlib_dir=$withval
295         fi
296 ],[
297         #
298         # Use zlib if it's present, otherwise don't.
299         #
300         want_zlib=ifpresent
301         zlib_dir=
302 ])
303 if test "x$want_zlib" = "xno" ; then
304         AC_MSG_RESULT(no)
305 else
306         AC_MSG_RESULT(yes)
307         AC_WIRETAP_ZLIB_CHECK
308         if test "x$want_zlib" = "xno" ; then
309                 AC_MSG_RESULT(zlib not found - disabling compressed capture file support)
310         fi
311 fi
312
313 AC_OUTPUT(Makefile)