Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set default CPPFLAGS on autotools project

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], [[email protected]])
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
like image 335
chotchki Avatar asked Oct 20 '25 04:10

chotchki


2 Answers

> 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.

like image 196
Brett Hale Avatar answered Oct 23 '25 11:10

Brett Hale


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.

like image 21
jørgensen Avatar answered Oct 23 '25 12:10

jørgensen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!