开发者

How can I set the value of a variable in a makefile depending on a MAKEFLAG?

开发者 https://www.devze.com 2023-04-12 03:04 出处:网络
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

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
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号