How to strip out a -D for just one file in a gnu makefile?

懵懂的女人 提交于 2020-01-05 07:13:54

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!