0

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?

1 Answer 1

0

You need to use the shell function to run cat:

FILE_A_CONTENTS := $(shell cat $(FILE_A_NAME))
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .