运行此命令:
GITIGNORE_CONTENTS = $(shell while read -r line; do printf "$$line "; done < "$(.gitignore)")
all:
echo $(GITIGNORE_CONTENTS)
变量GITIGNORE_CONTENTS
的内容是我的.gitignore
文件上的忽略模式的扩展版本,即myfile.txt
而非*.txt
我使用此解决方案是因为问题Create a variable in a makefile by reading contents of another file的解决方案均无效。
此解决方案在make规则内工作以打印文件名,但不将其放在变量内:
all:
while read -r line; do \
printf "$$line "; \
done < ".gitignore"
echo $(GITIGNORE_CONTENTS)
答案 0 :(得分:1)
这是Shell的通配符扩展问题,而不是make的问题。考虑一下,
GITIGNORE_CONTENTS:=$(shell cat .gitignore)
.PHONY: all
all:
echo "$(GITIGNORE_CONTENTS)"
# or alternatively:
#/bin/echo $(GITIGNORE_CONTENTS)
答案 1 :(得分:0)
运行此命令:
GITIGNORE_CONTENTS = $(shell while read -r line; do printf "$$line "; done < ".gitignore")
all:
echo "$(GITIGNORE_CONTENTS)"
带有以下.gitignore
文件:
*.txt
*.var
# Comment
*.xml
*.html
它正确输出:
echo "*.txt *.var # Comment *.xml *.html "
*.txt *.var # Comment *.xml *.html