Pull in darkstat-3.0.718
[darkstat-debian] / configure.ac
1 # Need at least 2.64 for PACKAGE_URL
2 AC_PREREQ([2.64])
3 AC_INIT(darkstat, 3.0.718, , , http://unix4lyfe.org/darkstat/)
4 AC_CONFIG_SRCDIR([darkstat.c])
5 AC_CONFIG_HEADER([config.h])
6
7 RULE="------------------------------------------------------------"
8
9 # Allow configure-time override of PRIVDROP_USER.
10 AC_ARG_WITH(privdrop-user, AS_HELP_STRING([--with-privdrop-user],
11  [specify which user to drop privileges to (default: nobody)]),
12  [_pdu="$withval"],
13  [_pdu="nobody"])
14 AC_DEFINE_UNQUOTED(PRIVDROP_USER, "$_pdu", [User to privdrop to.])
15
16 # Checks for programs.
17 AC_PROG_INSTALL
18 AC_PROG_CC
19
20 m4_pattern_allow([^AM_DEFAULT_VERBOSITY$])
21 AC_ARG_ENABLE([silent-rules],
22 [  --enable-silent-rules          less verbose build output (undo: 'make V=1')
23   --disable-silent-rules         verbose build output (undo: 'make V=0')])
24 case $enable_silent_rules in
25 no)  AM_DEFAULT_VERBOSITY=1;;
26 *)   AM_DEFAULT_VERBOSITY=0;;
27 esac
28 AC_SUBST([AM_DEFAULT_VERBOSITY])
29
30 # Let user disable debugging symbols so we create smaller binaries.
31 AC_MSG_CHECKING(if we want debug code)
32 AC_ARG_ENABLE(debug, AS_HELP_STRING([--disable-debug],
33  [turn off debugging code and asserts]),
34  [if test "x$enableval" = "xno" ; then
35    CFLAGS="$CFLAGS -DNDEBUG -g0"
36    AC_MSG_RESULT(nope)
37   elif test "x$enableval" = "xyes" ; then
38    AC_MSG_RESULT(sure)
39   else
40    CFLAGS="$CFLAGS -g$enableval"
41    AC_MSG_RESULT(sure ($enableval))
42   fi],
43  [AC_MSG_RESULT(sure)])
44
45 # Augment CFLAGS for fun.
46 echo "int main(void){return 1;}" > conftest.$ac_ext
47
48 AC_MSG_CHECKING(if your C compiler wants a hit off the pipe)
49 save_cflags="$CFLAGS"
50 CFLAGS="-pipe $CFLAGS"
51 if (eval $ac_link) 2>/dev/null; then
52  AC_MSG_RESULT(sure does)
53 else
54  AC_MSG_RESULT(no)
55  CFLAGS="$save_cflags"
56 fi
57
58 AC_MSG_CHECKING(if your C compiler has a link-time optimizer)
59 if test x$GCC = xyes; then
60  save_cflags="$CFLAGS"
61  CFLAGS="-flto $CFLAGS"
62  if (eval $ac_link) 2>/dev/null; then
63   AC_MSG_RESULT(sure does)
64  else
65   AC_MSG_RESULT(no)
66   CFLAGS="$save_cflags"
67  fi
68 else
69  AC_MSG_RESULT(skipped)
70 fi
71
72 AC_ARG_ENABLE(warnings, AS_HELP_STRING([--enable-warnings],
73  [turn on lots of compile-time warnings,
74   these are only useful for development]),
75  [if test "x$enableval" = "xyes" ; then
76    AC_MSG_CHECKING(if your C compiler has gcc-like --extra-warnings)
77    save_cflags="$CFLAGS"
78    CFLAGS="$CFLAGS -fdiagnostics-show-option --all-warnings --extra-warnings"
79    if (eval $ac_link) 2>/dev/null; then
80     AC_MSG_RESULT(yes)
81    else
82     AC_MSG_RESULT(no)
83     CFLAGS="$save_cflags"
84    fi
85
86    AC_MSG_CHECKING(if your C compiler has clang-like -Weverything)
87    save_cflags="$CFLAGS"
88    CFLAGS="$CFLAGS -Weverything"
89    if (eval $ac_link) 2>/dev/null; then
90     AC_MSG_RESULT(yes)
91    else
92     AC_MSG_RESULT(no)
93     CFLAGS="$save_cflags"
94    fi
95   fi])
96
97 rm -f conftest.$ac_objext conftest.$ac_ext
98
99
100
101 # Check for zlib.
102 AC_CHECK_LIB(z, deflate,, [
103  cat <<END
104 $RULE
105
106 I can't link to zlib.  You really can't have a modern
107 operating system without zlib.
108
109 If you are using a package-based operating system (like
110 something with RPMs), see if there is a zlib-devel package
111 that you can install, to provide the zlib headers and
112 libraries.
113
114 $RULE
115 END
116  AC_MSG_ERROR([can't find usable zlib])])
117
118
119
120 # Check for Solaris.
121 # Must do at least socket and nsl before checking for libpcap.
122 AC_SEARCH_LIBS(gethostbyname, [nsl], [],
123   [AC_MSG_ERROR([gethostbyname() not found])])
124 AC_SEARCH_LIBS(socket, [socket], [],
125   [AC_MSG_ERROR([socket() not found])])
126 AC_SEARCH_LIBS(hstrerror, [resolv], [],
127   [AC_MSG_ERROR([hstrerror() not found])])
128
129 # Solaris need sys/filio.h for FIONBIO
130 AC_CHECK_HEADERS(sys/filio.h)
131
132 # This is the modern way.  Older systems use the ioctl method.
133 AC_SEARCH_LIBS(getifaddrs, [c],
134   [AC_CHECK_HEADERS(ifaddrs.h)])
135
136
137
138 # Some OSes (Solaris) need sys/sockio.h for SIOCGIFADDR
139 AC_CHECK_HEADERS(sys/sockio.h)
140
141 # Check for libpcap
142 AC_ARG_WITH(pcap, AS_HELP_STRING([--with-pcap=DIR],
143  [prefix to libpcap installation]),
144  [if test "$withval" = yes ; then
145    AC_MSG_ERROR([must specify a path, as in --with-pcap=DIR])
146   fi
147   if test "$withval" != no ; then
148    PCAP_HOME="$withval"
149   fi])
150
151 if test -n "$PCAP_HOME" ; then
152  LDFLAGS="$LDFLAGS -L$PCAP_HOME/lib"
153  CPPFLAGS2="$CPPFLAGS -I$PCAP_HOME/include/pcap"
154  CPPFLAGS="$CPPFLAGS -I$PCAP_HOME/include"
155 else
156  CPPFLAGS2="$CPPFLAGS -I/usr/include/pcap"
157 fi
158
159 AC_CHECK_LIB(pcap, pcap_loop,, PCAP_BROKEN="yes")
160
161 if test -z "$PCAP_BROKEN" ; then
162   AC_CHECK_HEADERS(pcap.h,,
163   [# Couldn't find headers, try include/pcap
164    CPPFLAGS="$CPPFLAGS2"
165    AC_MSG_NOTICE([checking in include/pcap])
166    unset ac_cv_header_pcap_h
167    AC_CHECK_HEADERS(pcap.h,
168     AC_MSG_RESULT([I hate you.]),
169     PCAP_BROKEN="yes")])
170 fi
171
172 if test -n "$PCAP_BROKEN" ; then
173  cat <<END_MSG
174 $RULE
175
176 darkstat absolutely requires libpcap to be installed.  On Debian
177 systems, apt-get install libpcap-dev.  On RPM systems like RedHat, try
178 installing the libpcap-devel package.
179
180 If libpcap is installed into a prefix that isn't being picked up by
181 configure, for example /usr/local, re-run configure and add
182 --with-pcap=/usr/local
183
184 Failing all of the above, go to http://www.tcpdump.org/ and download the
185 source distribution of libpcap and build it yourself.
186
187 $RULE
188 END_MSG
189  AC_MSG_ERROR([can't find usable libpcap])
190 fi
191
192 # If not in libc, we might find these in libbsd.
193 AC_SEARCH_LIBS(setproctitle, [bsd],
194  AC_DEFINE(HAVE_SETPROCTITLE, 1,
195   [Define to 1 if you have setproctitle().]))
196 AC_SEARCH_LIBS(strlcpy, [bsd],
197  AC_DEFINE(HAVE_STRLCPY, 1,
198   [Define to 1 if you have strlcpy().]))
199 AC_SEARCH_LIBS(strlcat, [bsd],
200  AC_DEFINE(HAVE_STRLCAT, 1,
201   [Define to 1 if you have strlcat().]))
202
203 AC_CHECK_HEADERS(bsd/string.h)
204 AC_CHECK_HEADERS(bsd/unistd.h)
205
206 AC_SEARCH_LIBS(clock_gettime, rt)
207
208 AC_CONFIG_FILES([Makefile darkstat.8])
209 AC_OUTPUT