From: Remi Gacogne Date: Mon, 9 Jan 2023 09:35:32 +0000 (+0100) Subject: Add an --enable-fortify-source configure option X-Git-Tag: dnsdist-1.8.0-rc1~110^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cd68e313502e830ce23f0900bfe9b4d79e17e86d;p=thirdparty%2Fpdns.git Add an --enable-fortify-source configure option The option defaults to 2 to keep the existing behaviour, but 3 and auto are supported, with auto trying to select the highest version supported by the compiler. --- diff --git a/m4/pdns_d_fortify_source.m4 b/m4/pdns_d_fortify_source.m4 index 4a3322519f..fec605ea40 100644 --- a/m4/pdns_d_fortify_source.m4 +++ b/m4/pdns_d_fortify_source.m4 @@ -19,16 +19,51 @@ dnl . dnl AC_DEFUN([AC_CC_D_FORTIFY_SOURCE],[ - OLD_CXXFLAGS="$CXXFLAGS" - CXXFLAGS="-Wall -W -Werror $CXXFLAGS" + AC_MSG_CHECKING([whether FORTIFY_SOURCE is supported]) + AC_ARG_ENABLE([fortify-source], + AS_HELP_STRING([--enable-fortify-source], [enable FORTIFY_SOURCE support @<:@default=2@:>@]), + [enable_fortify_source=$enableval], + [enable_fortify_source=2] + ) + + AS_IF([test "x$enable_fortify_source" != "xno"], [ + + OLD_CXXFLAGS="$CXXFLAGS" + CXXFLAGS="-Wall -W -Werror $CXXFLAGS" + + dnl Auto means the highest version we support, which is currently 3 + AS_IF([test "x$enable_fortify_source" == "xauto"], + [enable_fortify_source=3], + [] + ) + + dnl If 3 is not supported, we try to fallback to 2 + AS_IF([test "x$enable_fortify_source" == "x3"], [ gl_COMPILER_OPTION_IF([-D_FORTIFY_SOURCE=3], [ CFLAGS="-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3 $CFLAGS" CXXFLAGS="-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3 $OLD_CXXFLAGS" - ], [ - gl_COMPILER_OPTION_IF([-D_FORTIFY_SOURCE=2], [ - CFLAGS="-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 $CFLAGS" - CXXFLAGS="-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 $OLD_CXXFLAGS" - ], [CXXFLAGS="$OLD_CXXFLAGS"], [AC_LANG_PROGRAM([[#include ]],[])]) - ] - , [AC_LANG_PROGRAM([[#include ]],[])]) + ], [enable_fortify_source=2], + [AC_LANG_PROGRAM([[#include ]],[])]) + ]) + + dnl If 2 is not supported, we try to fallback to 1 + AS_IF([test "x$enable_fortify_source" == "x2"], [ + gl_COMPILER_OPTION_IF([-D_FORTIFY_SOURCE=2], [ + CFLAGS="-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 $CFLAGS" + CXXFLAGS="-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 $OLD_CXXFLAGS" + ], [enable_fortify_source=1], + [AC_LANG_PROGRAM([[#include ]],[])]) + ]) + + AS_IF([test "x$enable_fortify_source" == "x1"], [ + gl_COMPILER_OPTION_IF([-D_FORTIFY_SOURCE=1], [ + CFLAGS="-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 $CFLAGS" + CXXFLAGS="-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 $OLD_CXXFLAGS" + ], [enable_fortify_source=no], + [AC_LANG_PROGRAM([[#include ]],[])]) + ]) + + ], []) + + AC_MSG_RESULT([$enable_fortify_source]) ])