for an autotools-based C project, I'd like to get some more warnings from the compiler (e.g. at least -Wall in CFLAGS). What is the prefered way to enable compiler flags without breaking anything? Is there a m4 macro that tests if a given compiler flag is understood by the compiler? With such a macro I could do
TEST_AND_USE(-Wall -Wextra <other flags>)
Thanks
You can just use AC_TRY_COMPILE
:
AC_MSG_CHECKING(whether compiler understands -Wall)
old_CFLAGS="$CFLAGS"
CFLAGS="$CFLAGS -Wall"
AC_TRY_COMPILE([],[],
AC_MSG_RESULT(yes),
AC_MSG_RESULT(no)
CFLAGS="$old_CFLAGS")
2015 addition: AC_TRY_COMPILE
is now deprecated, instead you should use AC_COMPILE_IFELSE
:
AC_MSG_CHECKING(whether compiler understands -Wall)
old_CFLAGS="$CFLAGS"
CFLAGS="$CFLAGS -Wall"
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[])],
AC_MSG_RESULT(yes),
AC_MSG_RESULT(no)
CFLAGS="$old_CFLAGS")
Don't bother changing the configure.ac
at all. Just call ./configure
with the CFLAGS
you care about:
./configure CFLAGS='-Wall -Wextra -O2 -g'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With