0

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) 

2 Answers 2

1

This is an issue of shell's wildcard expansion, not of make's. Consider this,

GITIGNORE_CONTENTS:=$(shell cat .gitignore) .PHONY: all all: echo "$(GITIGNORE_CONTENTS)" # or alternatively: #/bin/echo $(GITIGNORE_CONTENTS) 
Sign up to request clarification or add additional context in comments.

Comments

0

By running this:

GITIGNORE_CONTENTS = $(shell while read -r line; do printf "$$line "; done < ".gitignore") all: echo "$(GITIGNORE_CONTENTS)" 

With the following .gitignore file:

*.txt *.var # Comment *.xml *.html 

It correctly outputs:

echo "*.txt *.var # Comment *.xml *.html " *.txt *.var # Comment *.xml *.html 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.