I have a simple project with a simple configure.ac
script:
AC_INIT(...)
AM_INIT_AUTOMAKE([-Wall -Werror foreign])
AC_PROG_CC
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_FILES(...)
AC_OUTPUT
using GNU Autoconf version 2.69 (OpenSUSE Linux with gcc 9.2.1), but gcc is being called with no warning flags:
gcc -DHAVE_CONFIG_H -I. -I.. -g -O2 -MT aprog.o -MD -MP -MF .deps/aprog.Tpo -c -o aprog.o aprog.c
mv ...
gcc -g -O2 -o aprog aprog.o -lgmp
In particular, I found -Wformat
not working. Shouldn't -Wall
include -Wformat
? And shouldn't all warnings appear on the make line? If I run gcc line directly with -Wformat
the warning shows in compile but it doesn't when I run autoconf
, configure
and make
.
What I'm doing wrong?
The -Wall
flag in the AM_INIT_AUTOMAKE(...)
invocation refers to warnings from automake and related tools like aclocal, not to compiler warnings. You will see these warnings when you are running autoreconf
.
Note that while you can also add -Werror
to AM_INIT_AUTOMAKE(...)
to make your autoreconf
run fail on warnings, many common macros (like those shipped with gettext or libtool) will still use deprecated macros which generates a warning, so -Werror
means you cannot use this standard set of tools, so -Werror
is not very useful in many cases.
If you want to add compiler options, there are a third party macros (e.g. AX_CHECK_COMPILE_FLAG
) which test whether the compiler recognizes a given compile option and you can then add them to some variable and use that in places. That is a different stackoverflow question, though.