By running this:
GITIGNORE_CONTENTS = $(shell while read -r line; do printf "$$line "; done < "$(.gitignore)") all: echo $(GITIGNORE_CONTENTS) The contents of the variable GITIGNORE_CONTENTS are the expanded version of the ignore patterns on my .gitignore file, i.e., myfile.txt instead of *.txt
I am using this solution because none of the solution on the question Create a variable in a makefile by reading contents of another file work.
This solution works inside a make rule to print the file names, but not put them inside a variable:
all: while read -r line; do \ printf "$$line "; \ done < ".gitignore" echo $(GITIGNORE_CONTENTS)