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)
Evandro Coan
  • 8,560
  • 11
  • 83
  • 144

2 Answers2

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)
Matt
  • 13,674
  • 1
  • 18
  • 27
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
Evandro Coan
  • 8,560
  • 11
  • 83
  • 144