折腾:
【已解决】更新gitbook发布脚本Makefile忽略某些book
期间,接着需要想办法如何从字符串获取到列表
或者去判断,某个字符串 是否在 一个字符串中
deploy_ignore_book_crifan_com.txt
test_book_name_1 scientific_network_summary test_book_name_2
然后希望拿到一个变量是scientific_network_summary
能够判断,是否在上述的字符串中
makefile check contain string
Makefile : contains string – Stack Overflow
findstring
貌似就够用了?
GNU-make check if element exists in list/array – Stack Overflow
说是用filter
“$(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.
$(filter pattern…,text)
Returns all whitespace-separated words in text that do match any of the pattern words, removing any words that do not match. The patterns are written using ‘%’, just like the patterns used in the patsubst function above.
The filter function can be used to separate out different types of strings (such as file names) in a variable. For example:
sources := foo.c bar.c baz.s ugh.h
foo: $(sources)
cc $(filter %.c %.s,$(sources)) -o foo
says that foo depends of foo.c, bar.c, baz.s and ugh.h but only foo.c, bar.c and baz.s should be specified in the command to the compiler.”
突然发现:findstring
不适合此处,此处的in是要一个list才行
How to check whether a variable contains spaces in a Makefile ? – Stack Overflow
先去试试再说
$(info IGNORE_FILE_CONTENT=$(IGNORE_FILE_CONTENT)) $(info BOOK_NAME=$(BOOK_NAME)) FOUND_BOOK = $(findstring $(BOOK_NAME), $(IGNORE_FILE_CONTENT)) $(info FOUND_BOOK=$(FOUND_BOOK))
是可以找到的:
IGNORE_FILE_CONTENT=test_book_name_1 scientific_network_summary test_book_name_2 BOOK_NAME=scientific_network_summary FOUND_BOOK=scientific_network_summary
后续继续去判断是否为空
【总结】
最后用:
FOUND_BOOK := $(findstring $(BOOK_NAME), $(IGNORE_FILE_CONTENT))
实现了,去判断
BOOK_NAME=scientific_network_summary
的确是在:
IGNORE_FILE_CONTENT
的值是:
scientific_network_summary
能够找到,并返回
scientific_network_summary
否则就返回Empty=None=null=空
注意不是空字符串。