4

I need to set "-Wall -Werror" as CPPFLAGS for all the source files in my project. Is there a way to do that in autotools?

I have tried the following in configure.ac:

AC_SUBST([AM_CPPFLAGS], [-Wall -Wextra])

It doesn't seem to work.

EDIT: I found an m4 macro called AX_CXXFLAGS_WARN_ALL here: http://www.gnu.org/software/autoconf-archive/ax_cflags_warn_all.html However I get the following error when I try to use it:

configure.ac:10: /usr/bin/m4: ERROR: recursion limit of 1024 exceeded, use -L<N> to change it
autom4te: /usr/bin/m4 failed with exit status: 1
aclocal: autom4te failed with exit status: 1
autoreconf: aclocal failed with exit status: 1

My configure.ac is as follows:

AC_INIT([foo], [1.0], [bar@baz.com])
m4_include([m4/ax_cflags_warn_all.m4])
m4_include([m4/ax_append_flag.m4])
m4_include([m4/ax_lib_oracle_oci.m4])
m4_include([m4/ax_check_openssl.m4])
AM_INIT_AUTOMAKE([foreign subdir-objects])
AM_PROG_CC_C_O
AC_PROG_CXX
AC_PROG_LIBTOOL
AX_CFLAGS_WARN_ALL
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_FILES([Makefile])
AX_LIB_ORACLE_OCI([11.0])
AX_CHECK_OPENSSL
AC_SUBST([AM_CXXFLAGS], [-fpic])
AC_OUTPUT
chotchki
  • 4,258
  • 5
  • 34
  • 55
  • 2
    Do you really need to set `-Wall -Werror` for your project to work? Or do you just want it as your *personal* default? In the latter case, pass it to `configure` in your personal build and leave it out of `Makefile.am`, doing distributors and other receivers of your distributed source a favor. – thiton Jan 18 '12 at 11:53

4 Answers4

3

> env CXXFLAGS="$CXXFLAGS -Wall -Werror" ./configure [options]

I use this for all sorts of sanity checks - making sure I'm not getting away with any sloppy assumptions. This should work with CPPFLAGS and CFLAGS as well, provided they understand the options. I might add strict "-ansi" or some other standard, as well as "-pedantic" for more checks.

This way, you can leave your configure.ac and Makefile.am files alone when permissive flags are used - knowing it can be built correctly under strict options.

Brett Hale
  • 21,653
  • 2
  • 61
  • 90
2

In Makefile.am:

AM_CPPFLAGS = -Wall -Wextra

You can also add in substitutes, e.g.

#Makefile.am
AM_CPPFLAGS = ${my_CPPFLAGS}

#configure.ac
my_CPPFLAGS="-Wall -Wextra"
AC_SUBST([my_CPPFLAGS])

Note that not all -W flags are for the preprocessor, but the compiler. Only preprocessor flags should go into *CPPFLAGS, while compiler flags are to go into *CFLAGS. The recipe for CFLAGS is the same as with CPPFLAGS.

jørgensen
  • 10,149
  • 2
  • 20
  • 27
  • 2
    Also note that not all compilers accept -Wall and -Wextra. If you assign them in configure.ac without checking that CC recognizes them, you break the build. – William Pursell Jan 18 '12 at 16:58
0

In my case below error was coming :"configure.in recursion limit of 1024 exceeded, use -L<>"

package compilation was being ordered from a makefile. So "-L" option is to be given to "make" as an compilation option.

With below diff , error was resolved.

"-" cd $(SNMP_ROOT)/ucd-snmp-4.2 $(SEP) make "CC=$(CPP)" install

"+" cd $(SNMP_ROOT)/ucd-snmp-4.2 $(SEP) make "CC=$(CPP) " -L install

0

In Makefile.am:

AM_CFLAGS = -Wall -Wextra
Jack Kelly
  • 18,264
  • 2
  • 56
  • 81