]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Add an --enable-fortify-source configure option
authorRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 9 Jan 2023 09:35:32 +0000 (10:35 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 9 Jan 2023 09:35:32 +0000 (10:35 +0100)
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.

m4/pdns_d_fortify_source.m4

index 4a3322519fdd57d94e89511fc40e6791badfffad..fec605ea403a6099a7969b927642a58446a32fd2 100644 (file)
@@ -19,16 +19,51 @@ dnl <http://www.gnu.org/licenses/>.
 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 <stdio.h>]],[])])
-         ]
-      , [AC_LANG_PROGRAM([[#include <stdio.h>]],[])])
+      ], [enable_fortify_source=2],
+      [AC_LANG_PROGRAM([[#include <stdio.h>]],[])])
+    ])
+
+    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 <stdio.h>]],[])])
+    ])
+
+    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 <stdio.h>]],[])])
+    ])
+
+  ], [])
+
+  AC_MSG_RESULT([$enable_fortify_source])
 ])