使用automake设置每个文件的标志

时间:2020-03-06 14:52:54  来源:igfitidea点击:

有没有一种方法可以使用automake在每个文件的基础上设置标志?
特别是,如果我有一个c ++项目,并且想用-WAll编译除我要禁用特定警告的文件以外的所有文件,我该怎么办?

我尝试了类似的东西:

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

但这没用。

编辑:删除了对automake手册的引用,该手册实际上具有误导性(这要归功于Douglas Leeder)。

解决方案

我们会感到困惑的是,本节所指的是自动制作本身的选项。

这是设置automake命令行选项的一种方式:

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

第17节中列出的每个文件是指每个Makefile而不是源文件。

我不知道每个源文件的标志设置,但是我们可以使用以下命令为每个结果二进制文件设置选项:

binaryname_CXXFLAGS

当我们需要按对象标记时,Automake仅支持按目标标记。一种解决方法是创建一个包含对象的小型库:

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