Code

configure.ac: Added a copyright header.
[template.git] / configure.ac
index e0fd5dbcab30485e671c6c022012d05ac7e884fc..5539e7eae8c1ba52136fe7365028ac50eb5c4822 100644 (file)
@@ -1,4 +1,21 @@
 dnl Process this file with autoconf to produce a configure script.
+dnl
+dnl This is the foobar configure script.
+dnl
+dnl Copyright (C) 2009 Sebastian Harl <sh@tokkee.org>
+dnl
+dnl This program is free software; you can redistribute it and/or modify it
+dnl under the terms of the GNU General Public License as published by the
+dnl Free Software Foundation; only version 2 of the License is applicable.
+dnl
+dnl This program is distributed in the hope that it will be useful, but
+dnl WITHOUT ANY WARRANTY; without even the implied warranty of
+dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+dnl General Public License for more details.
+dnl
+dnl You should have received a copy of the GNU General Public License along
+dnl with this program; if not, write to the Free Software Foundation, Inc.,
+dnl 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
 
 AC_INIT([foobar],[m4_esyscmd(./version-gen.sh)],
                [Sebastian Harl <sh@tokkee.org>])
@@ -30,10 +47,13 @@ test_cc_flags() {
        return $ret
 }
 
-dnl Optionally stick to standard C99 and POSIX.1 2001 as close as possible.
+m4_divert_once([HELP_ENABLE], [
+Build options:])
+
+dnl Optionally stick to standard C99 and POSIX:2001 as close as possible.
 AC_ARG_ENABLE([standards],
                AS_HELP_STRING([--enable-standards],
-                               [Enable standards compliance mode]),
+                               [C99 / POSIX standards compliance mode @<:@default=no@:>@]),
                [enable_standards="$enableval"],
                [enable_standards="no"])
 
@@ -61,7 +81,45 @@ if test "x$enable_standards" = "xyes"; then
        done
 fi
 
-for flag in -Wall -Wextra -Werror; do
+dnl Hardening (see e.g. http://wiki.debian.org/Hardening for a motivation).
+AC_DEFINE([_FORTIFY_SOURCE], 2,
+               [Define to enable protection against static sized buffer overflows.])
+AC_ARG_ENABLE([hardening],
+               AS_HELP_STRING([--disable-hardening],
+                               [hardening options @<:@default=yes@:>@]),
+               [enable_hardening="$enableval"],
+               [enable_hardening="yes"])
+
+if test "x$enable_hardening" = "xyes"; then
+       hardening=0
+       hardening_tests=0
+       for flag in -Wformat -Wformat-security; do
+               hardening_tests=$(($hardening_tests + 1))
+               AC_MSG_CHECKING([whether $CC accepts $flag])
+
+               if test_cc_flags $flag; then
+                       CFLAGS="$CFLAGS $flag"
+                       hardening=$(($hardening + 1))
+                       AC_MSG_RESULT([yes])
+               else
+                       AC_MSG_RESULT([no])
+               fi
+       done
+       if test $hardening -ne $hardening_tests; then
+               AC_MSG_WARN(
+                               [Some hardening options are not supported by your compiler!])
+       fi
+fi
+
+dnl Strict checking for potential problems.
+AC_ARG_ENABLE([strict-checks],
+               AS_HELP_STRING([--disable-strict-checks],
+                               [strict compiler checks @<:@default=yes@:>@]),
+               [enable_strict_checks="$enableval"],
+               [enable_strict_checks="yes"])
+
+STRICT_CFLAGS=""
+for flag in -Wall -Werror; do
        AC_MSG_CHECKING([whether $CC accepts $flag])
 
        if test_cc_flags $flag; then
@@ -71,15 +129,52 @@ for flag in -Wall -Wextra -Werror; do
                AC_MSG_RESULT([no])
        fi
 done
+
+if test "x$enable_strict_checks" = "xyes"; then
+       for flag in -Wextra \
+                       -Wbad-function-cast \
+                       -Wcast-align \
+                       -Wcast-qual \
+                       -Wconversion \
+                       -Wdeclaration-after-statement \
+                       -Wmissing-prototypes \
+                       -Wpointer-arith \
+                       -Wshadow \
+                       -Wstrict-prototypes \
+                       -Wunreachable-code \
+                       -Wvla; do
+               AC_MSG_CHECKING([whether $CC accepts $flag])
+
+               if test_cc_flags $flag; then
+                       STRICT_CFLAGS="$STRICT_CFLAGS $flag"
+                       AC_MSG_RESULT([yes])
+               else
+                       AC_MSG_RESULT([no])
+               fi
+       done
+fi
 AC_SUBST([STRICT_CFLAGS])
 
 build_date="`date --utc '+%F %T'` (UTC)"
 AC_DEFINE_UNQUOTED([BUILD_DATE], ["$build_date"],
                [Define to the date the package has been built on.])
 
+dnl Version information provided by fb_features.h.
+FB_VERSION_MAJOR=`echo $PACKAGE_VERSION | cut -d'.' -f1`
+FB_VERSION_MINOR=`echo $PACKAGE_VERSION | cut -d'.' -f2`
+FB_VERSION_PATCH=`echo $PACKAGE_VERSION | cut -d'.' -f3`
+FB_VERSION_EXTRA=`echo $PACKAGE_VERSION | cut -d'.' -f4-`
+FB_VERSION_STRING="$FB_VERSION_MAJOR.$FB_VERSION_MINOR.$FB_VERSION_PATCH"
+
+AC_SUBST(FB_VERSION_MAJOR)
+AC_SUBST(FB_VERSION_MINOR)
+AC_SUBST(FB_VERSION_PATCH)
+AC_SUBST(FB_VERSION_EXTRA)
+AC_SUBST(FB_VERSION_STRING)
+
 AC_CHECK_HEADERS(libgen.h)
 
-AC_CONFIG_FILES([Makefile src/Makefile])
+AC_CONFIG_FILES([Makefile src/Makefile src/fb_features.h])
 AC_OUTPUT
 
 cat <<EOF;