views:

461

answers:

2

Is there a way set flags on a per-file basis with automake?
In particular, if I have a c++ project and want to compile with -WAll all the files except one for which I want to disable a particular warning, what could I do?

I tried something like:

CXXFLAGS = -WAll ...
bin_PROGRAMS = test
test_SOURCES = main.cpp utility.cpp
utility_o_CXXFLAGS = $(CXXFLAGS) -Wno-unused-value

but it didn't work.

EDITED: removed reference to automake manual, which was actually misleading (thanks to Douglas Leeder).

+1  A: 

You've got confused - that section is referring to options to automake itself.

It's a way of setting the automake command-line options:

-W CATEGORY --warnings=category Output warnings falling in category. category can be one of:

gnu
    warnings related to the GNU Coding Standards (see Top).
obsolete
    obsolete features or constructions
override
    user redefinitions of Automake rules or variables
portability
    portability issues (e.g., use of make features that are known to be not portable)
syntax
    weird syntax, unused variables, typos
unsupported
    unsupported or incomplete features
all
    all the warnings
none
    turn off all the warnings
error
    treat warnings as errors

A category can be turned off by prefixing its name with ‘no-’. For instance, -Wno-syntax will hide the warnings about unused variables.

The categories output by default are ‘syntax’ and ‘unsupported’. Additionally, ‘gnu’ and ‘portability’ are enabled in --gnu and --gnits strictness.

The environment variable WARNINGS can contain a comma separated list of categories to enable. It will be taken into account before the command-line switches, this way -Wnone will also ignore any warning category enabled by WARNINGS. This variable is also used by other tools like autoconf; unknown categories are ignored for this reason.

The per-file listed in section 17 refers to per-Makefile not source file.

I'm not aware of any per-source file flag setting, but you can set the option for each result binary with:

binaryname_CXXFLAGS
Douglas Leeder
+1  A: 

Automake only supports per-target flags, while you want per-object flags. One way around is to create a small library that contains your object:

CXXFLAGS = -Wall ...
bin_PROGRAMS = test
test_SOURCES = main.cpp
test_LDADD = libutility.a
noinst_LIBRARIES = libutility.a
libutility_a_SOURCES = utility.cpp
libutility_a_CXXFLAGS = $(CXXFLAGS) -Wno-unused-value
adl