Improve error message when binding http port.
[darkstat] / configure.ac
index 1b68124..30c5f08 100644 (file)
@@ -1,4 +1,4 @@
-AC_INIT(darkstat, 3.0.0-git)
+AC_INIT(darkstat, 3.0.0-git, , , http://unix4lyfe.org/darkstat/)
 AC_CONFIG_SRCDIR([darkstat.c])
 AC_CONFIG_HEADER([config.h])
 
@@ -40,6 +40,31 @@ AC_DEFINE_UNQUOTED(PRIVDROP_USER, "$_pdu", [User to privdrop to.])
 AC_PROG_INSTALL
 AC_PROG_CC
 
+m4_pattern_allow([^AM_DEFAULT_VERBOSITY$])
+AC_ARG_ENABLE([silent-rules],
+[  --enable-silent-rules          less verbose build output (undo: 'make V=1')
+  --disable-silent-rules         verbose build output (undo: 'make V=0')])
+case $enable_silent_rules in
+no)  AM_DEFAULT_VERBOSITY=1;;
+*)   AM_DEFAULT_VERBOSITY=0;;
+esac
+AC_SUBST([AM_DEFAULT_VERBOSITY])
+
+# Let user disable debugging symbols so we create smaller binaries.
+AC_MSG_CHECKING(if we want debug code)
+AC_ARG_ENABLE(debug, AS_HELP_STRING([--disable-debug],
+ [turn off debugging code and asserts]),
+ [if test "x$enableval" = "xno" ; then
+   CFLAGS="$CFLAGS -DNDEBUG -g0"
+   AC_MSG_RESULT(nope)
+  elif test "x$enableval" = "xyes" ; then
+   AC_MSG_RESULT(sure)
+  else
+   CFLAGS="$CFLAGS -g$enableval"
+   AC_MSG_RESULT(sure ($enableval))
+  fi],
+ [AC_MSG_RESULT(sure)])
+
 # Augment CFLAGS for fun.
 echo "int main(void){return 1;}" > conftest.$ac_ext
 
@@ -53,19 +78,135 @@ else
  CFLAGS="$save_cflags"
 fi
 
-AC_ARG_WITH(mad-warnings, AS_HELP_STRING([--with-mad-warnings],
- [turn on lots of compile-time warnings, this needs GCC and is only
+AC_MSG_CHECKING(if your C compiler has a link-time optimizer)
+if test x$GCC = xyes; then
+ save_cflags="$CFLAGS"
+ CFLAGS="-flto $CFLAGS"
+ if (eval $ac_link) 2>/dev/null; then
+  AC_MSG_RESULT(sure does)
+ else
+  AC_MSG_RESULT(no)
+  CFLAGS="$save_cflags"
+ fi
+else
+ AC_MSG_RESULT(skipped)
+fi
+
+AC_ARG_ENABLE(mad-warnings, AS_HELP_STRING([--enable-mad-warnings],
+ [turn on lots of compile-time warnings, these are GCC-specific and only
  really useful for development]),
- [if test "$withval" = yes ; then
-   AC_MSG_CHECKING(if your C compiler throws mad warnings)
+ [if test "x$enableval" = "xyes" ; then
+   AC_MSG_CHECKING(if your C compiler can emit certain warnings)
    save_cflags="$CFLAGS"
-   CFLAGS="$CFLAGS -Wall -Wredundant-decls -Wnested-externs \
--Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith \
--Winline -Wcast-qual -W -Wbad-function-cast -Wcast-align \
--Wchar-subscripts -Wshadow -Wwrite-strings \
--Wuninitialized -Winline"
+   CFLAGS="$CFLAGS -fdiagnostics-show-option \
+-Waddress \
+-Waggregate-return \
+-Wall \
+-Wbad-function-cast \
+-Wcast-align \
+-Wcast-qual \
+-Wchar-subscripts \
+-Wcomment \
+-Wdeclaration-after-statement \
+-Wdisabled-optimization \
+-Wextra \
+-Wfloat-equal \
+-Wformat \
+-Wformat=2 \
+-Wformat-nonliteral \
+-Wformat-security \
+-Wformat-y2k \
+-Wimplicit \
+-Wimplicit-function-declaration \
+-Wimplicit-int \
+-Winit-self \
+-Winline \
+-Winvalid-pch \
+-Wmain \
+-Wmissing-braces \
+-Wmissing-declarations \
+-Wmissing-field-initializers \
+-Wmissing-format-attribute \
+-Wmissing-include-dirs \
+-Wmissing-noreturn \
+-Wmissing-prototypes \
+-Wnested-externs \
+-Wnonnull \
+-Wold-style-definition \
+-Wpacked \
+-Wparentheses \
+-Wpointer-arith \
+-Wpointer-sign \
+-Wredundant-decls \
+-Wreturn-type \
+-Wsequence-point \
+-Wshadow \
+-Wsign-compare \
+-Wstrict-aliasing -fstrict-aliasing \
+-Wstrict-overflow=5 -fstrict-overflow \
+-Wstrict-prototypes \
+-Wswitch \
+-Wswitch-default \
+-Wswitch-enum \
+-Wtrigraphs \
+-Wundef \
+-Wuninitialized \
+-Wunknown-pragmas \
+-Wunsafe-loop-optimizations \
+-Wunused \
+-Wunused-function \
+-Wunused-label \
+-Wunused-parameter \
+-Wunused-value \
+-Wunused-variable \
+-Wvariadic-macros \
+-Wvolatile-register-var \
+-Wwrite-strings \
+"
+# The above are valid for gcc version 4.2.1.
+
    if (eval $ac_link) 2>/dev/null; then
-    AC_MSG_RESULT(sure does)
+    AC_MSG_RESULT(yes)
+
+    AC_MSG_CHECKING(if your C compiler can emit certain other warnings)
+    save_cflags="$CFLAGS"
+    CFLAGS="$CFLAGS \
+-Warray-bounds \
+-Wclobbered \
+-Wcoverage-mismatch \
+-Wempty-body \
+-Wignored-qualifiers \
+-Wlogical-op \
+-Wmissing-parameter-type \
+-Wold-style-declaration \
+-Wpacked-bitfield-compat \
+-Wsync-nand \
+-Wtype-limits \
+-Wvla \
+"
+# The above are valid for gcc version 4.4.3.
+# We skip the following entirely:
+#-pedantic
+#-Wabi
+#-Wc++-compat
+#-Wconversion
+#-Wfatal-errors
+#-Wlong-long
+#-Wpadded
+#-Wsign-conversion
+#-Wstack-protector
+#-Wsystem-headers
+#-Wtraditional
+#-Wtraditional-conversion
+#-Wunreachable-code
+
+    if (eval $ac_link) 2>/dev/null; then
+     AC_MSG_RESULT(yes)
+    else
+     AC_MSG_RESULT(no)
+     CFLAGS="$save_cflags"
+    fi
+
    else
     AC_MSG_RESULT(no)
     CFLAGS="$save_cflags"
@@ -97,11 +238,24 @@ END
 
 # Check for Solaris.
 # Must do at least socket and nsl before checking for libpcap.
-AC_CHECK_LIB(nsl, gethostbyname)
-AC_CHECK_LIB(socket, socket)
-AC_CHECK_LIB(resolv, inet_aton)
+AC_SEARCH_LIBS(gethostbyname, [nsl], [],
+  [AC_MSG_ERROR([gethostbyname() not found])])
+AC_SEARCH_LIBS(socket, [socket], [],
+  [AC_MSG_ERROR([socket() not found])])
+AC_SEARCH_LIBS(hstrerror, [resolv], [],
+  [AC_MSG_ERROR([hstrerror() not found])])
+
+# Solaris need sys/filio.h for FIONBIO
+AC_CHECK_HEADERS(sys/filio.h)
+
+# GNU/kfreebsd needs net/if_ether.h for ETH_P_IPV6
+AC_CHECK_HEADERS(net/if_ether.h)
 
+# This is the modern way.  Older systems use the ioctl method.
+AC_CHECK_HEADERS(ifaddrs.h)
 
+# Some OSes (Solaris) need sys/sockio.h for SIOCGIFADDR
+AC_CHECK_HEADERS(sys/sockio.h)
 
 # Check for libpcap
 AC_ARG_WITH(pcap, AS_HELP_STRING([--with-pcap=DIR],
@@ -157,27 +311,19 @@ END_MSG
  AC_MSG_ERROR([can't find usable libpcap])
 fi
 
-
-
-# A real OS will have setproctitle()
-AC_CHECK_LIB(c, setproctitle,
+# If not in libc, we might find these in libbsd.
+AC_SEARCH_LIBS(setproctitle, [bsd],
  AC_DEFINE(HAVE_SETPROCTITLE, 1,
   [Define to 1 if you have setproctitle().]))
-
-# A real OS will have safe string functions
-AC_CHECK_LIB(c, strlcpy,
+AC_SEARCH_LIBS(strlcpy, [bsd],
  AC_DEFINE(HAVE_STRLCPY, 1,
   [Define to 1 if you have strlcpy().]))
-
-AC_CHECK_LIB(c, strlcat,
+AC_SEARCH_LIBS(strlcat, [bsd],
  AC_DEFINE(HAVE_STRLCAT, 1,
   [Define to 1 if you have strlcat().]))
 
-# Some OSes (Solaris) need sys/sockio.h for SIOCGIFADDR
-AC_CHECK_HEADERS(sys/sockio.h)
-
-# Some OSes (Solaris) need sys/filio.h for FIONBIO
-AC_CHECK_HEADERS(sys/filio.h)
+AC_CHECK_HEADERS(bsd/string.h)
+AC_CHECK_HEADERS(bsd/unistd.h)
 
 AC_CONFIG_FILES([Makefile darkstat.8])
 AC_OUTPUT