最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【已解决】Makefile中判断变量是否为空无效

makefile crifan 9634浏览 0评论

折腾:

【已解决】Makefile中如何判断一个字符串变量存在另外一个字符串或列表中

期间,对于findstring

GNU make: Text Functions

“$(findstring find,in)

Searches in for an occurrence of find. If it occurs, the value is find; otherwise, the value is empty. You can use this function in a conditional to test for the presence of a specific substring in a given string. Thus, the two examples,

$(findstring a,a b c)

$(findstring a,b c)

produce the values ‘a’ and ‘’ (the empty string), respectively. See Testing Flags, for a practical application of findstring.”

中返回的empty的话,接着去判断是否为空

结果用:

$(info BOOK_NAME=$(BOOK_NAME))
FOUND_BOOK := $(findstring $(BOOK_NAME), $(IGNORE_FILE_CONTENT))
$(info FOUND_BOOK=$(FOUND_BOOK))
ifeq ($(FOUND_BOOK), "")
$(info not found $(BOOK_NAME) in $(IGNORE_FILE_CONTENT))
# else
# $(info is found $(BOOK_NAME) in $(IGNORE_FILE_CONTENT))
endif

结果输出不对:没有输出。

后来自己研究了,发现是:

【总结】

要么不加””

ifeq ($(FOUND_BOOK), )

要么都加””

ifeq ("$(FOUND_BOOK)", "")

不能写成:

ifeq ($(FOUND_BOOK), "")

否则本身是空的empty的,逻辑是是null,但是和一个空字符串””去比较,就不对了。

转载请注明:在路上 » 【已解决】Makefile中判断变量是否为空无效

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
83 queries in 0.172 seconds, using 22.05MB memory