Makefile $(command) not working but `command` did

后端 未结 2 719
鱼传尺愫
鱼传尺愫 2021-01-12 05:19

The thing is when I was writing a Makefile for my project, when I needed to detect the current branch name, in a make rule I did this :

check_branch:
    if         


        
2条回答
  •  情书的邮戳
    2021-01-12 05:23

    Inside recipes you have to escape dollar signs in order to get them interpreted by the shell. Otherwise, Make treats $(git ...) as a built-in command or a variable and tries to evaluate it (of course, unsuccessfully).

    check_branch:
        if [ "$$(git rev-parse --abbrev-ref HEAD)" == "master" ]; then \
        ...
    

提交回复
热议问题