Makefile variable assignment error in echo

前端 未结 2 1557
没有蜡笔的小新
没有蜡笔的小新 2020-12-19 17:14

I have make file target like this

foo: 
    i = 1
    @echo $(i)

when I run the make file like this:

$ make foo 

2条回答
  •  别那么骄傲
    2020-12-19 17:57

    In the first case you instruct the make to run a shell command: i = 1.

    If you want a variable inside Makefile you should set without leading spaces/tabs.

    I assume you use GNU's make and you want to check Recipe Syntax (or similar for other makes):

    A variable definition in a “rule context” which is indented by a tab as the first character on the line, will be considered part of a recipe, not a make variable definition, and passed to the shell.

提交回复
热议问题