Make commands with variables

I study makeand struggle to understand something. I have some rules with this general structure.

FILE = "myfile.txt"

test :
    YOUR = $(subst my,your,$(FILE));\
    cat $(FILE) $(YOUR)

I expect the final result to be executed by the command:

cat myfile.txt yourfile.txt

Instead, I get the following ...

YOUR = "yourfile.txt";\
    cat "myfile.txt" 
/bin/sh: YOUR: command not found
make: *** [test] Error 1

If instead of using the function substI just do YOUR="yourfile"in makefile, everything looks fine. Any suggestions or did I miss something quite fundamental? I must add that I use tabs, not spaces, to run lines for commands in a rule.

+4
source share
3 answers
FILE = "myfile.txt"

test :
    $(eval YOUR = $(subst my,your,$(FILE)))
    cp $(FILE) $(YOUR)

eval ( make )

+1

, make, , . YOUR = , , YOUR .

:

YOUR = $(subst my,your,$(FILE))

test:
    cat $(FILE) $(YOUR)

, ${}, $() : YOUR=${FILE/my/your} Bash (, make, $$ $, , make , ). $() , , : YOUR=$(echo "${FILE}" | sed 's/my/your/').

+1

, make, , eval ( ) .

:

FILE = "myfile.txt"

test :
    YOUR='$(subst my,your,$(FILE))';\
    cat $(FILE) "$${YOUR}"
0

Source: https://habr.com/ru/post/1568915/


All Articles