@@ -111,6 +111,10 @@ dnl NOTE: this option should not be passed via the fourth argument of the macro,
111111dnl or it ends up in the flags too, possibly during the "pop"; have to use the
112112dnl GOOD_FLAG instead :\
113113 COMPILERFLAG="$1 "
114+ dnl GCC will silently accept warning disable options, but then if there is an issue, warn about the option, i.e.
115+ dnl "cc1: note: unrecognized command-line option '-Wno-unknown-warning-option' may have been intended to silence earlier diagnostics"
116+ dnl Instead try the enable option to check if it is valid
117+ COMPILERTESTFLAG="`echo $1 | sed 's/^-Wno-/-W/'`"
114118
115119dnl We also try to run an actual build since tools called from that might
116120dnl complain if they are forwarded unknown flags accepted by the front-end.
@@ -119,14 +123,22 @@ dnl complain if they are forwarded unknown flags accepted by the front-end.
119123 AC_MSG_NOTICE ( [ Starting check compile flag for '${COMPILERFLAG}'; now CFLAGS='${CFLAGS}' and CXXFLAGS='${CXXFLAGS}'] )
120124
121125 AC_LANG_PUSH ( [ C] )
126+ dnl Use a simple program with out previous #defines so we don't cause errors on clang with -Wreserved-identifier
127+ m4_pushdef ( [ AC_LANG_CONFTEST ( C ) ] , [ m4_ifdef ( [ AC_LANG_DEFINES_PROVIDED] , [ AC_LANG_DEFINES_PROVIDED] )
128+ cat << _ACEOF > conftest.$ac_ext
129+ int main(void) { return 0; }
130+ _ACEOF
131+ ] )
122132 GOOD_FLAG=no
123- AX_CHECK_COMPILE_FLAG ( [ ${COMPILERFLAG}] ,
133+ # CFLAGS="-Werror $CFLAGS"
134+ AX_CHECK_COMPILE_FLAG ( [ ${COMPILERTESTFLAG}] ,
124135 [ CFLAGS="-Werror $NUT_SAVED_CFLAGS ${COMPILERFLAG}"
125136 AC_MSG_CHECKING ( [ whether the flag '${COMPILERFLAG}' is still supported in CC linker mode] )
126137 AX_RUN_OR_LINK_IFELSE([ AC_LANG_PROGRAM ( [ ] ,[ ] ) ] ,
127138 [ GOOD_FLAG=yes] ,[ ] )
128139 AC_MSG_RESULT ( [ ${GOOD_FLAG}] )
129140 ] , [ ] , [ ] )
141+ m4_popdef ( [ AC_LANG_CONFTEST ( C ) ] )
130142 AC_LANG_POP ( [ C] )
131143 AS_IF ( [ test x"${GOOD_FLAG}" = xyes] ,
132144 [ CFLAGS="$NUT_SAVED_CFLAGS ${COMPILERFLAG}"] ,
@@ -135,14 +147,22 @@ dnl complain if they are forwarded unknown flags accepted by the front-end.
135147 AC_MSG_NOTICE ( [ ${GOOD_FLAG} for C '${COMPILERFLAG}'; now CFLAGS=${CFLAGS}] )
136148
137149 AC_LANG_PUSH ( [ C++] )
150+ dnl Use a simple program with out previous #defines so we don't cause errors on clang with -Wreserved-identifier
151+ m4_pushdef ( [ AC_LANG_CONFTEST ( C++ ) ] , [ m4_ifdef ( [ AC_LANG_DEFINES_PROVIDED] , [ AC_LANG_DEFINES_PROVIDED] )
152+ cat << _ACEOF > conftest.$ac_ext
153+ int main(void) { return 0; }
154+ _ACEOF
155+ ] )
138156 GOOD_FLAG=no
139- AX_CHECK_COMPILE_FLAG ( [ ${COMPILERFLAG}] ,
157+ # CXXFLAGS="-Werror $CXXFLAGS"
158+ AX_CHECK_COMPILE_FLAG ( [ ${COMPILERTESTFLAG}] ,
140159 [ CXXFLAGS="-Werror $NUT_SAVED_CXXFLAGS ${COMPILERFLAG}"
141160 AC_MSG_CHECKING ( [ whether the flag '${COMPILERFLAG}' is still supported in CXX linker mode] )
142161 AX_RUN_OR_LINK_IFELSE([ AC_LANG_PROGRAM ( [ ] ,[ ] ) ] ,
143162 [ GOOD_FLAG=yes] ,[ ] )
144163 AC_MSG_RESULT ( [ ${GOOD_FLAG}] )
145164 ] , [ ] , [ ] )
165+ m4_popdef ( [ AC_LANG_CONFTEST ( C++ ) ] )
146166 AC_LANG_POP ( [ C++] )
147167 AS_IF ( [ test x"${GOOD_FLAG}" = xyes] ,
148168 [ CXXFLAGS="$NUT_SAVED_CXXFLAGS ${COMPILERFLAG}"] ,
0 commit comments