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