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