Imported Debian patch 3.0.715-1
[darkstat-debian] / configure.ac
1 AC_INIT(darkstat, 3.0.715, , , http://unix4lyfe.org/darkstat/)
2 AC_CONFIG_SRCDIR([darkstat.c])
3 AC_CONFIG_HEADER([config.h])
4
5 RULE="------------------------------------------------------------"
6
7 # Let user specify CHROOT_DIR, or else autodetect it, or else die.
8 AC_ARG_WITH(chroot-dir, AS_HELP_STRING([--with-chroot-dir],
9  [specify the chroot directory (default: /var/empty)]),
10  [if test "x$withval" = "xyes"; then
11    AC_MSG_ERROR([please specify --with-chroot-dir=/path/to/darkstat/chroot])
12   fi
13   _chd="$withval"],
14  [# Find an "empty" directory to serve as the chroot.
15   _chd="/var/empty"
16   AC_MSG_CHECKING([for $_chd])
17   if test -d $_chd ; then
18    AC_MSG_RESULT(found it)
19   else
20    AC_MSG_RESULT(not there)
21    _chd="/var/lib/empty"
22    AC_MSG_CHECKING([for $_chd])
23    if test -d $_chd ; then
24     AC_MSG_RESULT(found it)
25    else
26     AC_MSG_RESULT(not there either)
27     AC_MSG_ERROR([please specify --with-chroot-dir=/path/to/darkstat/chroot])
28    fi
29   fi])
30 AC_DEFINE_UNQUOTED(CHROOT_DIR, "$_chd", [Default chroot directory.])
31
32 # Allow configure-time override of PRIVDROP_USER.
33 AC_ARG_WITH(privdrop-user, AS_HELP_STRING([--with-privdrop-user],
34  [specify which user to drop privileges to (default: nobody)]),
35  [_pdu="$withval"],
36  [_pdu="nobody"])
37 AC_DEFINE_UNQUOTED(PRIVDROP_USER, "$_pdu", [User to privdrop to.])
38
39 # Checks for programs.
40 AC_PROG_INSTALL
41 AC_PROG_CC
42
43 m4_pattern_allow([^AM_DEFAULT_VERBOSITY$])
44 AC_ARG_ENABLE([silent-rules],
45 [  --enable-silent-rules          less verbose build output (undo: 'make V=1')
46   --disable-silent-rules         verbose build output (undo: 'make V=0')])
47 case $enable_silent_rules in
48 no)  AM_DEFAULT_VERBOSITY=1;;
49 *)   AM_DEFAULT_VERBOSITY=0;;
50 esac
51 AC_SUBST([AM_DEFAULT_VERBOSITY])
52
53 # Let user disable debugging symbols so we create smaller binaries.
54 AC_MSG_CHECKING(if we want debug code)
55 AC_ARG_ENABLE(debug, AS_HELP_STRING([--disable-debug],
56  [turn off debugging code and asserts]),
57  [if test "x$enableval" = "xno" ; then
58    CFLAGS="$CFLAGS -DNDEBUG -g0"
59    AC_MSG_RESULT(nope)
60   elif test "x$enableval" = "xyes" ; then
61    AC_MSG_RESULT(sure)
62   else
63    CFLAGS="$CFLAGS -g$enableval"
64    AC_MSG_RESULT(sure ($enableval))
65   fi],
66  [AC_MSG_RESULT(sure)])
67
68 # Augment CFLAGS for fun.
69 echo "int main(void){return 1;}" > conftest.$ac_ext
70
71 AC_MSG_CHECKING(if your C compiler wants a hit off the pipe)
72 save_cflags="$CFLAGS"
73 CFLAGS="-pipe $CFLAGS"
74 if (eval $ac_link) 2>/dev/null; then
75  AC_MSG_RESULT(sure does)
76 else
77  AC_MSG_RESULT(no)
78  CFLAGS="$save_cflags"
79 fi
80
81 AC_MSG_CHECKING(if your C compiler has a link-time optimizer)
82 if test x$GCC = xyes; then
83  save_cflags="$CFLAGS"
84  CFLAGS="-flto $CFLAGS"
85  if (eval $ac_link) 2>/dev/null; then
86   AC_MSG_RESULT(sure does)
87  else
88   AC_MSG_RESULT(no)
89   CFLAGS="$save_cflags"
90  fi
91 else
92  AC_MSG_RESULT(skipped)
93 fi
94
95 AC_ARG_ENABLE(mad-warnings, AS_HELP_STRING([--enable-mad-warnings],
96  [turn on lots of compile-time warnings, these are GCC-specific and only
97  really useful for development]),
98  [if test "x$enableval" = "xyes" ; then
99    AC_MSG_CHECKING(if your C compiler can emit certain warnings)
100    save_cflags="$CFLAGS"
101    CFLAGS="$CFLAGS -fdiagnostics-show-option \
102 -Waddress \
103 -Waggregate-return \
104 -Wall \
105 -Wbad-function-cast \
106 -Wcast-align \
107 -Wcast-qual \
108 -Wchar-subscripts \
109 -Wcomment \
110 -Wdeclaration-after-statement \
111 -Wdisabled-optimization \
112 -Wextra \
113 -Wfloat-equal \
114 -Wformat \
115 -Wformat=2 \
116 -Wformat-nonliteral \
117 -Wformat-security \
118 -Wformat-y2k \
119 -Wimplicit \
120 -Wimplicit-function-declaration \
121 -Wimplicit-int \
122 -Winit-self \
123 -Winline \
124 -Winvalid-pch \
125 -Wmain \
126 -Wmissing-braces \
127 -Wmissing-declarations \
128 -Wmissing-field-initializers \
129 -Wmissing-format-attribute \
130 -Wmissing-include-dirs \
131 -Wmissing-noreturn \
132 -Wmissing-prototypes \
133 -Wnested-externs \
134 -Wnonnull \
135 -Wold-style-definition \
136 -Wpacked \
137 -Wparentheses \
138 -Wpointer-arith \
139 -Wpointer-sign \
140 -Wredundant-decls \
141 -Wreturn-type \
142 -Wsequence-point \
143 -Wshadow \
144 -Wsign-compare \
145 -Wstrict-aliasing -fstrict-aliasing \
146 -Wstrict-overflow=5 -fstrict-overflow \
147 -Wstrict-prototypes \
148 -Wswitch \
149 -Wswitch-default \
150 -Wswitch-enum \
151 -Wtrigraphs \
152 -Wundef \
153 -Wuninitialized \
154 -Wunknown-pragmas \
155 -Wunsafe-loop-optimizations \
156 -Wunused \
157 -Wunused-function \
158 -Wunused-label \
159 -Wunused-parameter \
160 -Wunused-value \
161 -Wunused-variable \
162 -Wvariadic-macros \
163 -Wvolatile-register-var \
164 -Wwrite-strings \
165 "
166 # The above are valid for gcc version 4.2.1.
167
168    if (eval $ac_link) 2>/dev/null; then
169     AC_MSG_RESULT(yes)
170
171     AC_MSG_CHECKING(if your C compiler can emit certain other warnings)
172     save_cflags="$CFLAGS"
173     CFLAGS="$CFLAGS \
174 -Warray-bounds \
175 -Wclobbered \
176 -Wcoverage-mismatch \
177 -Wempty-body \
178 -Wignored-qualifiers \
179 -Wlogical-op \
180 -Wmissing-parameter-type \
181 -Wold-style-declaration \
182 -Wpacked-bitfield-compat \
183 -Wsync-nand \
184 -Wtype-limits \
185 -Wvla \
186 "
187 # The above are valid for gcc version 4.4.3.
188 # We skip the following entirely:
189 #-pedantic
190 #-Wabi
191 #-Wc++-compat
192 #-Wconversion
193 #-Wfatal-errors
194 #-Wlong-long
195 #-Wpadded
196 #-Wsign-conversion
197 #-Wstack-protector
198 #-Wsystem-headers
199 #-Wtraditional
200 #-Wtraditional-conversion
201 #-Wunreachable-code
202
203     if (eval $ac_link) 2>/dev/null; then
204      AC_MSG_RESULT(yes)
205     else
206      AC_MSG_RESULT(no)
207      CFLAGS="$save_cflags"
208     fi
209
210    else
211     AC_MSG_RESULT(no)
212     CFLAGS="$save_cflags"
213    fi
214   fi])
215
216 rm -f conftest.$ac_objext conftest.$ac_ext
217
218
219
220 # Check for zlib.
221 AC_CHECK_LIB(z, deflate,, [
222  cat <<END
223 $RULE
224
225 I can't link to zlib.  You really can't have a modern
226 operating system without zlib.
227
228 If you are using a package-based operating system (like
229 something with RPMs), see if there is a zlib-devel package
230 that you can install, to provide the zlib headers and
231 libraries.
232
233 $RULE
234 END
235  AC_MSG_ERROR([can't find usable zlib])])
236
237
238
239 # Check for Solaris.
240 # Must do at least socket and nsl before checking for libpcap.
241 AC_SEARCH_LIBS(gethostbyname, [nsl], [],
242   [AC_MSG_ERROR([gethostbyname() not found])])
243 AC_SEARCH_LIBS(socket, [socket], [],
244   [AC_MSG_ERROR([socket() not found])])
245 AC_SEARCH_LIBS(hstrerror, [resolv], [],
246   [AC_MSG_ERROR([hstrerror() not found])])
247
248 # Solaris need sys/filio.h for FIONBIO
249 AC_CHECK_HEADERS(sys/filio.h)
250
251 # Debian GNU/kFreeBSD needs net/if_ether.h for ETH_P_IPV6
252 AC_CHECK_HEADERS(net/if_ether.h)
253
254 # This is the modern way.  Older systems use the ioctl method.
255 AC_CHECK_HEADERS(ifaddrs.h)
256
257 # Some OSes (Solaris) need sys/sockio.h for SIOCGIFADDR
258 AC_CHECK_HEADERS(sys/sockio.h)
259
260 # Check for libpcap
261 AC_ARG_WITH(pcap, AS_HELP_STRING([--with-pcap=DIR],
262  [prefix to libpcap installation]),
263  [if test "$withval" = yes ; then
264    AC_MSG_ERROR([must specify a path, as in --with-pcap=DIR])
265   fi
266   if test "$withval" != no ; then
267    PCAP_HOME="$withval"
268   fi])
269
270 if test -n "$PCAP_HOME" ; then
271  LDFLAGS="$LDFLAGS -L$PCAP_HOME/lib"
272  CPPFLAGS2="$CPPFLAGS -I$PCAP_HOME/include/pcap"
273  CPPFLAGS="$CPPFLAGS -I$PCAP_HOME/include"
274 else
275  CPPFLAGS2="$CPPFLAGS -I/usr/include/pcap"
276 fi
277
278 AC_CHECK_LIB(pcap, pcap_loop,, PCAP_BROKEN="yes")
279
280 if test -z "$PCAP_BROKEN" ; then
281   AC_CHECK_HEADERS(pcap.h,,
282   [# Couldn't find headers, try include/pcap
283    CPPFLAGS="$CPPFLAGS2"
284    AC_MSG_NOTICE([checking in include/pcap])
285    unset ac_cv_header_pcap_h
286    AC_CHECK_HEADERS(pcap.h,
287     AC_MSG_RESULT([I hate you.]),
288     PCAP_BROKEN="yes")])
289 fi
290
291 if test -n "$PCAP_BROKEN" ; then
292  cat <<END_MSG
293 $RULE
294
295 darkstat absolutely requires libpcap to be installed.  If
296 it's installed into a prefix that isn't being picked up by
297 configure, for example /usr/local, re-run configure and add
298 --with-pcap=/usr/local
299
300 If you are using a package-based operating system (like
301 something with RPMs), see if there is a pcap-devel or
302 libpcap-devel package that you can install, to provide the
303 pcap headers and libraries.
304
305 Failing all of the above, go to http://www.tcpdump.org/ and
306 download the source distribution of libpcap and build it
307 yourself.
308
309 $RULE
310 END_MSG
311  AC_MSG_ERROR([can't find usable libpcap])
312 fi
313
314 # If not in libc, we might find these in libbsd.
315 AC_SEARCH_LIBS(setproctitle, [bsd],
316  AC_DEFINE(HAVE_SETPROCTITLE, 1,
317   [Define to 1 if you have setproctitle().]))
318 AC_SEARCH_LIBS(strlcpy, [bsd],
319  AC_DEFINE(HAVE_STRLCPY, 1,
320   [Define to 1 if you have strlcpy().]))
321 AC_SEARCH_LIBS(strlcat, [bsd],
322  AC_DEFINE(HAVE_STRLCAT, 1,
323   [Define to 1 if you have strlcat().]))
324
325 AC_CHECK_HEADERS(bsd/string.h)
326 AC_CHECK_HEADERS(bsd/unistd.h)
327
328 AC_CONFIG_FILES([Makefile darkstat.8])
329 AC_OUTPUT