diff options
author | Sami Kerola <kerolasa@iki.fi> | 2014-11-25 21:16:19 +0000 |
---|---|---|
committer | Alexandra Yates <alexandra.yates@linux.intel.com> | 2014-11-25 15:01:52 -0800 |
commit | b8ce814394ca73afb6f3c962c4e47112024b108d (patch) | |
tree | 8c3f4a815f8e1158e993b8c92e915a8ad450f5ba | |
parent | bc67fd3fe72a114a3a42642cef406e4bf9792e50 (diff) | |
download | powertop-2.0-b8ce814394ca73afb6f3c962c4e47112024b108d.tar.gz |
powertop.m4: GCC_FORTIFY_SOURCE_CC copy idea of macro from Archlinux pacman
The powertop.m4 is a collection file for autoconf m4 helper macros, such
as GCC_FORTIFY_SOURCE_CC. The macro in case will define feature
_FORTIFY_SOURCE=2 when it is possible, instead of trying to enable when
it will not work, such as at times when optimization is turned off.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
-rw-r--r-- | configure.ac | 2 | ||||
-rw-r--r-- | m4/gcc_fortify_source_cc.m4 | 29 | ||||
-rw-r--r-- | src/Makefile.am | 1 |
3 files changed, 31 insertions, 1 deletions
diff --git a/configure.ac b/configure.ac index 1859553..b9ee05a 100644 --- a/configure.ac +++ b/configure.ac @@ -34,6 +34,7 @@ AC_PROG_LIBTOOL AC_PROG_CC AC_PROG_INSTALL AM_PROG_CC_C_O +GCC_FORTIFY_SOURCE_CC # Checks for libraries. AX_PTHREAD([ @@ -145,4 +146,5 @@ AC_SEARCH_LIBS([inet_aton], [resolv], [], [ AC_MSG_ERROR([libresolv is required but was not found]) ], []) + AC_OUTPUT diff --git a/m4/gcc_fortify_source_cc.m4 b/m4/gcc_fortify_source_cc.m4 new file mode 100644 index 0000000..1206672 --- /dev/null +++ b/m4/gcc_fortify_source_cc.m4 @@ -0,0 +1,29 @@ +dnl GCC_FORTIFY_SOURCE_CC +dnl checks -D_FORTIFY_SOURCE with the C++ compiler, if it exists then +dnl updates CXXCPP +AC_DEFUN([GCC_FORTIFY_SOURCE_CC],[ + AC_LANG_ASSERT([C++]) + AS_IF([test "X$CXX" != "X"], [ + AC_MSG_CHECKING([for FORTIFY_SOURCE support]) + fs_old_cxxcpp="$CXXCPP" + fs_old_cxxflags="$CXXFLAGS" + CXXCPP="$CXXCPP -D_FORTIFY_SOURCE=2" + CXXFLAGS="$CXXFLAGS -Werror" + AC_COMPILE_IFELSE([ + AC_LANG_PROGRAM([[]], [[ + int main(void) { + #if !(__GNUC_PREREQ (4, 1) ) + #error No FORTIFY_SOURCE support + #endif + return 0; + } + ]], [ + AC_MSG_RESULT([yes]) + ], [ + AC_MSG_RESULT([no]) + CXXCPP="$fs_old_cxxcpp" + ]) + ]) + CXXFLAGS="$fs_old_cxxflags" + ]) +]) diff --git a/src/Makefile.am b/src/Makefile.am index ecb9b89..59830c7 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -136,7 +136,6 @@ powertop_CXXFLAGS = \ powertop_CPPFLAGS = \ -DLOCALEDIR=\"$(localedir)\" \ - -D_FORTIFY_SOURCE=2 \ $(GLIB2_CFLAGS) \ $(LIBNL_CFLAGS) \ $(LIBZ_CFLAGS) \ |