在gnu Makefile中组合多个ifeq和ifneq [英] combine multiple ifeq and ifneq in a gnu Makefile

查看:924
本文介绍了在gnu Makefile中组合多个ifeq和ifneq的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果语法类似于

ifeq ($(VAR1),some-string)

ifneq ($(VAR2),some-other-string)

结合更多...

有一个班轮吗?像(幻想代码):

Is there a one liner? Like (fantasycode):

ifeq $VAR1=some-string and not $VAR2=some-other-string

我找到了这个答案在其中的ifeq语句中.

i found this answer which is not clear to me becauser there is no equation in the ifeq statement there.

推荐答案

不,条件语句没有and运算符(但是有一个and函数可以在条件语句中使用). ifandor条件函数认为空字符串为false,其他任何条件为true(包括仅包含空格的字符串).找到的答案中的第一个建议测试变量是否为空字符串.第二个测试是否定义了变量.在这两种情况下,它都不测试其值是否等于参考字符串.这可能就是为什么您现在还不清楚的原因.

No, there is no and operator for the conditionals (but there is a and function that can be used in conditionals). The if, and and or conditional functions consider that the empty string is false and that anything else is true (including strings containing only spaces). The first proposal in the answer you found tests whether variables are the empty string or not. The second tests whether variables are defined or not. In both cases it does not test whether their value is equal to a reference string. This may be the reason why it was not immediately clear to you.

在(简单)情况下,您可以嵌套条件:

In your (simple) case you can nest the conditionals:

ifeq ($(VAR1),some-string)
  ifneq ($(VAR2),some-other-string)
<do something>
  endif
endif

<do something>将在且仅当两个条件通过时才会考虑.

<do something> will be considered if and only if the two conditionals pass.

对于具有许多条件的复杂情况,您可以计算单个匹配变量:

For complex situations with many conditions you can compute individual matching variables:

MATCH1 := $(if $(strip $(VAR1)),$(patsubst some-string,,$(VAR1)),NO)

变量MATCH1将取值:

  • NO如果未定义VAR1,则为空字符串或空格字符串
  • 空字符串,如果它等于some-string
  • 否则为VAR1的值.
  • NO if VAR1 is undefined, is the empty string or a string of spaces,
  • empty string if it is equal to some-string,
  • else the value of VAR1.

因此,当且仅当VAR1 == some-string时,它将为空字符串.与NOMATCH1相同:

So, it will be the empty string if and only if VAR1 == some-string. Same for NOMATCH1:

MOMATCH1 := $(if $(strip $(VAR2)),$(patsubst some-other-string,,$(VAR2)),NO)

NOMATCH1将仅当VAR2 != some-other-string时为非空.

现在,您的主要条件可以使用条件函数表示:

Now, your main condition can be expressed using conditional functions:

ifeq ($(or $(MATCH1),$(MATCH2),...),)
  ifneq ($(and $(NOMATCH1),$(NOMATCH2),...),)
<do something>
  endif
endif

这篇关于在gnu Makefile中组合多个ifeq和ifneq的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆