Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1800727
  • 博文数量: 306
  • 博客积分: 3133
  • 博客等级: 中校
  • 技术积分: 3932
  • 用 户 组: 普通用户
  • 注册时间: 2009-04-19 16:50
文章分类

全部博文(306)

文章存档

2018年(7)

2017年(18)

2016年(39)

2015年(35)

2014年(52)

2013年(39)

2012年(22)

2011年(29)

2010年(53)

2009年(12)

分类: LINUX

2015-05-27 14:53:02

In my Makefile I would like to check the following complex condition:

ifdef VAR1 || VAR2 || VAR3
action
endif 

however the documentation says the syntax like that is not supported. So the only simple workaround that came to my mind is to use the concatenation:

ifneq ($(VAR1)$(VAR2)$(VAR3),)
action
endif 

Are there any other more correct solutions?

For the following case:

ifdef VAR1 && VAR2 && VAR3
action
endif 

one need to write

ifdef VAR1
ifdef VAR2
ifdef VAR3
action
endif
endif
endif 

which is also ugly. Are there more elegant alternatives?

up vote10down voteaccepted

If your make is GNU-make and all the defined variables include a non-space character,

ifdef VAR1 && VAR2 && VAR3 

can be written as

ifneq ($(and $(VAR1),$(VAR2),$(VAR3)),) 

On a related note, probably and function requires version 3.81 or later.

In case some defined variables may be empty strings, if we prepare the following functions:

ifndef_any_of = $(filter undefined,$(foreach v,$(1),$(origin $(v))))
ifdef_any_of = $(filter-out undefined,$(foreach v,$(1),$(origin $(v)))) 

then the following conditions:

ifdef VAR1 || VAR2
ifdef VAR1 && VAR2 

can be written respectively as:

ifneq ($(call ifdef_any_of,VAR1 VAR2),)
ifeq ($(call ifndef_any_of,VAR1 VAR2),)
阅读(9125) | 评论(0) | 转发(0) |
0

上一篇:msdu_mpdu之名词释义

下一篇:ht-operations-ie

给主人留下些什么吧!~~