configure.ac : Add hardening compile options.
authorErik de Castro Lopo <erikd@mega-nerd.com>
Tue, 5 Mar 2013 10:53:18 +0000 (21:53 +1100)
committerErik de Castro Lopo <erikd@mega-nerd.com>
Tue, 5 Mar 2013 20:39:24 +0000 (07:39 +1100)
Extra compile options are detected at configure time with new
XIPH_ADD_*FLAGS m4 macros.

Options enabled include -Wextra, -D_FORTIFY_SOURCE=2 and stack
protection.

configure.ac
m4/add_cflags.m4 [new file with mode: 0644]
m4/add_cxxflags.m4 [new file with mode: 0644]

index ac35de2..b99f402 100644 (file)
@@ -356,6 +356,10 @@ fi
 
 XIPH_GCC_VERSION
 
+XIPH_ADD_CFLAGS([-Wextra])
+XIPH_ADD_CFLAGS([-D_FORTIFY_SOURCE=2])
+XIPH_ADD_CFLAGS([-fstack-protector --param ssp-buffer-size=4])
+
 if test x$ac_cv_c_compiler_gnu = xyes ; then
        if test x$enable_gcc_werror = "xyes" ; then
                CFLAGS="-Wall -Wextra -Werror $CFLAGS"
diff --git a/m4/add_cflags.m4 b/m4/add_cflags.m4
new file mode 100644 (file)
index 0000000..08f4a40
--- /dev/null
@@ -0,0 +1,18 @@
+dnl @synopsis XIPH_ADD_CFLAGS
+dnl
+dnl Add the given option to CFLAGS, if it doesn't break the compiler
+
+AC_DEFUN([XIPH_ADD_CFLAGS],
+[AC_MSG_CHECKING([if $CC accepts $1])
+       ac_add_cflags__old_cflags="$CFLAGS"
+       CFLAGS="$1"
+       AC_TRY_LINK([
+                       #include <stdio.h>
+                       ],
+               [puts("Hello, World!"); return 0;],
+               AC_MSG_RESULT([yes])
+                       CFLAGS="$ac_add_cflags__old_cflags $1",
+               AC_MSG_RESULT([no])
+                       CFLAGS="$ac_add_cflags__old_cflags"
+               )
+])# XIPH_ADD_CFLAGS
diff --git a/m4/add_cxxflags.m4 b/m4/add_cxxflags.m4
new file mode 100644 (file)
index 0000000..8197dc2
--- /dev/null
@@ -0,0 +1,19 @@
+dnl @synopsis XIPH_ADD_CXXFLAGS
+dnl
+dnl Add the given option to CXXFLAGS, if it doesn't break the compiler
+
+AC_DEFUN([XIPH_ADD_CXXFLAGS],
+[AC_MSG_CHECKING([if $CXX accepts $1])
+       AC_LANG_ASSERT([C++])
+       ac_add_cxxflags__old_cxxflags="$CXXFLAGS"
+       CXXFLAGS="$1"
+       AC_TRY_LINK([
+                       #include <cstdio>
+                       ],
+               [puts("Hello, World!"); return 0;],
+               AC_MSG_RESULT([yes])
+                       CXXFLAGS="$ac_add_cxxflags__old_cxxflags $1",
+               AC_MSG_RESULT([no])
+                       CXXFLAGS="$ac_add_cxxflags__old_cxxflags"
+               )
+])# XIPH_ADD_CXXFLAGS