Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting per-file flags with automake

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

like image 219
Paolo Tedesco Avatar asked Sep 29 '08 15:09

Paolo Tedesco


People also ask

How do I enable flags in Makefile?

The only way of doing that is to edit the makefile to change the options. There is no convenient way to override the options without modifying the makefile . This is where make flags come into play. Flags in make are just variables containing options that should be passed to the tools used in the compilation process.

What is an automake file?

Automake is a tool for automatically generating Makefile.in s from files called Makefile.am . Each Makefile.am is basically a series of make variable definitions1, with rules being thrown in occasionally. The generated Makefile.in s are compliant with the GNU Makefile standards.


1 Answers

You can't do this with automake... but can do with make =) Add following line to your Makefile.am:

utility.$(OBJEXT) : CXXFLAGS += -Wno-unused-value

See GNU Make documentation : Target-specific Variable Values for details.

like image 176
Andrey Starodubtsev Avatar answered Sep 19 '22 14:09

Andrey Starodubtsev