问题
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)
回答1:
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))
回答2:
Okay, I figured it out for myself:
$O/just_one_file.o: CXXFLAGS := $(shell echo ${CXXFLAGS} | sed s/-Wredundant-decls//g)
来源:https://stackoverflow.com/questions/2726019/how-to-strip-out-a-d-for-just-one-file-in-a-gnu-makefile