How can I set the value of a variable in a makefile depending on a MAKEFLAG?
My makefile is compiling my program for debugging. By that I mean that it passes -g -D DEBUG
to the compiler. I want to be able to pass -nd
for not debug or -p
for production to make thus removing the debug flags from the compiler. To do this I'd need some way of putting this into make syntax: "If MAKEFLAGS is not nd then set CFLAGS to -g -D DEBUG
otherwise leave it empty"
How can 开发者_运维问答I do this?
If all you care about is -nd
, this will do it:
ifeq (,$(findstring nd,$(MAKEFLAGS)))
FOO = -g -D DEBUG
endif
If you also care about -p
, it's not quite as clean:
FOO = -g -D DEBUG
ifneq (,$(findstring nd,$(MAKEFLAGS)))
FOO =
endif
ifneq (,$(findstring p,$(MAKEFLAGS)))
FOO =
endif
精彩评论