views:

40

answers:

2

I have '-Wredundant-decls' in my CXXFLAGS but for one file, I want it removed.

In my GNU makefile, how can I structure a rule to remove just that part of the CXXFLAGS.

I know how to add only for that file, I would do something like this:

$O/just_one_file.o: CXXFLAGS += -Wredundant-decls

So, ideally I'd do something like this (which doesn't work) to remove it:

$O/just_one_file.o: CXXFLAGS -= -Wredundant-decls

However, maybe with some $ magic, I can construct some kind of sed or perl script to strip out the -Wredundant-decls and set CXXFLAGS to the stripped value:

$O/just_one_file.o: CXXFLAGS = $(shell strip magic here for $CXXFLAGS)
+2  A: 

No need for the shell:

$O/just_one_file.o: CXXFLAGS := $(subst -Wredundant-decls,,$(CXXFLAGS))

or

$O/just_one_file.o: CXXFLAGS := $(filter-out -Wredundant-decls,$(CXXFLAGS))
Beta
Gnu make rejects this syntax. /bin/sh: -c: line 0: syntax error near unexpected token `)'
WilliamKF
The second one you added is rejected too. They are probably close, but there is some issue with the syntax. Seems the $CXXFLAGS is not expanding.
WilliamKF
Just remove the last `)` of the line, it's a typo.
Peter Kovacs
No, the typo was a missing (. Fixed.
Beta
A: 

Okay, I figured it out for myself:

$O/just_one_file.o: CXXFLAGS := $(shell echo ${CXXFLAGS} | sed s/-Wredundant-decls//g)
WilliamKF