From f1bd5f97310c2c5ec2e150179137217afa92957d Mon Sep 17 00:00:00 2001 From: Jan Engelhardt Date: Mon, 31 Mar 2025 19:10:34 +0200 Subject: [PATCH] build: do not modify user-provided CFLAGS variable ``` $ ./configure CFLAGS="-U_FORTIFY_SOURCE -g3" && grep ^CFLAGS Makefile && make ... CFLAGS = -std=gnu11 -U_FORTIFY_SOURCE -g3 -U_FORTIFY_SOURCE -fstack-protector-strong -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -mfunction-return=keep -mindirect-branch=keep -Wall -W -Wmissing-prototypes -Wmissing-declarations -Wpointer-arith -Wchar-subscripts -Wformat=2 -Wbad-function-cast -fno-builtin-strftime -Wstrict-aliasing=2 ... /usr/include/features.h:435:4: warning: #warning _FORTIFY_SOURCE requires compiling with optimization (-O) [-Wcpp] 435 | # warning _FORTIFY_SOURCE requires compiling with optimization (-O) ``` This is not how `./configure CFLAGS=...` should work. As per https://www.gnu.org/software/automake/manual/html_node/User-Variables.html CFLAGS is reserved for the user and should not be changed. AM_CFLAGS is the right variable to use here. --- configure.ac | 10 ++++++---- m4/dovecot.m4 | 25 ++++++++++++------------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/configure.ac b/configure.ac index 8c711964de..1a41711034 100644 --- a/configure.ac +++ b/configure.ac @@ -266,7 +266,7 @@ LT_INIT AM_ICONV # SIZE_MAX is missing without this -CXXFLAGS="$CXXFLAGS -D__STDC_LIMIT_MACROS" +AM_CXXFLAGS="$AM_CXXFLAGS -D__STDC_LIMIT_MACROS" # Use the first x.y.z numbers of the version. Also allow x.y numbering. AS_IF([echo "$PACKAGE_VERSION" | grep '^[[0-9]]*\.[[0-9]]*\.[[0-9]]'], [ @@ -772,8 +772,10 @@ SETTING_LINKED_FILES=`echo $libdovecot_c_files | $SED -e s,$srcdir/src,./src,g - AC_SUBST(SETTING_FILES) AC_SUBST(SETTING_LINKED_FILES) -CFLAGS="$CFLAGS $EXTRA_CFLAGS" -CXXFLAGS="$CXXFLAGS $EXTRA_CFLAGS" +AM_CFLAGS="$AM_CFLAGS $EXTRA_CFLAGS" +AM_CXXFLAGS="$AM_CXXFLAGS $EXTRA_CFLAGS" +AC_SUBST([AM_CFLAGS]) +AC_SUBST([AM_CXXFLAGS]) BINARY_LDFLAGS="$PIE_LDFLAGS $RELRO_LDFLAGS" BINARY_CFLAGS="$PIE_CFLAGS" @@ -940,7 +942,7 @@ echo "userdbs ........ :$userdb" if test "$not_userdb" != ""; then echo " :$not_userdb" fi -echo "CFLAGS ......... : $CFLAGS" +echo "AM_CFLAGS ...... : $AM_CFLAGS" if test "$systemdsystemunitdir" != ""; then echo "SYSTEMD ........ : $systemdservicetype - $systemdsystemunitdir/dovecot.service"; diff --git a/m4/dovecot.m4 b/m4/dovecot.m4 index cc4f8d4ae6..0b66ec1965 100644 --- a/m4/dovecot.m4 +++ b/m4/dovecot.m4 @@ -18,7 +18,7 @@ AC_DEFUN([AC_CC_D_FORTIFY_SOURCE],[ case "$host" in *) gl_COMPILER_OPTION_IF([-O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2], [ - CFLAGS="$CFLAGS -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2" + AM_CFLAGS="$AM_CFLAGS -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2" ], [], [AC_LANG_PROGRAM()] @@ -43,20 +43,19 @@ AC_DEFUN([DC_DOVECOT_CFLAGS],[ CFLAGS="-std=$mystd" AC_COMPILE_IFELSE([AC_LANG_PROGRAM() ], [ - CFLAGS="$CFLAGS $old_cflags" + AM_CFLAGS="$AM_CFLAGS $CFLAGS" std=$mystd break - ], [ - CFLAGS="$old_cflags" ]) done AC_MSG_RESULT($std) + CFLAGS="$old_cflags" AS_IF([test "x$ac_cv_c_compiler_gnu" = "xyes"], [ dnl -Wcast-qual -Wcast-align -Wconversion -Wunreachable-code # too many warnings dnl -Wstrict-prototypes -Wredundant-decls # may give warnings in some systems dnl -Wmissing-format-attribute -Wmissing-noreturn -Wwrite-strings # a couple of warnings - CFLAGS="$CFLAGS -Wall -W -Wmissing-prototypes -Wmissing-declarations -Wpointer-arith -Wchar-subscripts -Wformat=2 -Wbad-function-cast" + AM_CFLAGS="$AM_CFLAGS -Wall -W -Wmissing-prototypes -Wmissing-declarations -Wpointer-arith -Wchar-subscripts -Wformat=2 -Wbad-function-cast" AS_IF([test "$have_clang" = "yes"], [ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ @@ -65,11 +64,11 @@ AC_DEFUN([DC_DOVECOT_CFLAGS],[ #endif ]], [[]])],[],[ dnl clang 3.3+ unfortunately this gives warnings with hash.h - CFLAGS="$CFLAGS -Wno-duplicate-decl-specifier" + AM_CFLAGS="$AM_CFLAGS -Wno-duplicate-decl-specifier" ]) ], [ dnl This is simply to avoid warning when building strftime() wrappers.. - CFLAGS="$CFLAGS -fno-builtin-strftime" + AM_CFLAGS="$AM_CFLAGS -fno-builtin-strftime" ]) AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ @@ -78,7 +77,7 @@ AC_DEFUN([DC_DOVECOT_CFLAGS],[ #endif ]], [[]])],[ dnl gcc4 - CFLAGS="$CFLAGS -Wstrict-aliasing=2" + AM_CFLAGS="$AM_CFLAGS -Wstrict-aliasing=2" ],[]) ]) ]) @@ -210,12 +209,12 @@ AC_DEFUN([AC_CC_RETPOLINE],[ case "$host" in *) gl_COMPILER_OPTION_IF([-mfunction-return=$with_retpoline], - [CFLAGS="$CFLAGS -mfunction-return=$with_retpoline"], + [AM_CFLAGS="$AM_CFLAGS -mfunction-return=$with_retpoline"], [], [AC_LANG_PROGRAM()] ) gl_COMPILER_OPTION_IF([-mindirect-branch=$with_retpoline], [ - CFLAGS="$CFLAGS -mindirect-branch=$with_retpoline" + AM_CFLAGS="$AM_CFLAGS -mindirect-branch=$with_retpoline" ], [], [AC_LANG_PROGRAM()] @@ -234,11 +233,11 @@ AC_DEFUN([AC_CC_F_STACK_PROTECTOR],[ case "$host" in *) gl_COMPILER_OPTION_IF([-fstack-protector-strong], [ - CFLAGS="$CFLAGS -fstack-protector-strong" + AM_CFLAGS="$AM_CFLAGS -fstack-protector-strong" ], [ gl_COMPILER_OPTION_IF([-fstack-protector], [ - CFLAGS="$CFLAGS -fstack-protector" + AM_CFLAGS="$AM_CFLAGS -fstack-protector" ], [], [AC_LANG_PROGRAM()]) ], [AC_LANG_PROGRAM()] @@ -310,7 +309,7 @@ AC_DEFUN([DC_DOVECOT_FUZZER],[ with_fuzzer=$withval, with_fuzzer=no) AS_IF([test x$with_fuzzer = xclang], [ - CFLAGS="$CFLAGS -fsanitize=fuzzer-no-link" + AM_CFLAGS="$AM_CFLAGS -fsanitize=fuzzer-no-link" # use $LIB_FUZZING_ENGINE for linking if it exists FUZZER_LDFLAGS=${LIB_FUZZING_ENGINE--fsanitize=fuzzer} # May need to use CXXLINK for linking, which wants sources to