In my Makefile, I'm assigning some variables based on the contents of a file, and I'd like to define a new variable by doing a string replacement on the contents of the file.
I have a file called .file-a in my project directory with the following contents:
foo-bar
And my Makefile looks like this:
FILE_A_NAME := .file-a
FILE_A_CONTENTS := `cat $(FILE_A_NAME)`
NEW_VAR := $(subst -,_, $(FILE_A_CONTENTS))
.PHONY: foo
foo:
@echo $(NEW_VAR)
I'd like make foo to echo foo_bar, but instead, I'm getting:
cat: .file_a: No such file or directory
It seems like NEW_VAR is doing the substitution on FILE_A_NAME. How can I get the substitution to work on FILE_A_CONTENTS?