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

后端 未结 2 717
鱼传尺愫
鱼传尺愫 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:26

    In shell lines, you write shell commands as you would in a shell script. That's why the second operation works.

    If you want Make to evaluate git command outside of the shell, you can enclose the operation in a shell function, as in:

    $(shell git rev-parse --abbrev-ref HEAD)
    

    And you ought to be good to go, though I often implement this kind of thing as:

    branch := $(shell git rev-parse --abbrev-ref HEAD)
    target:dep
         mkdir -p build/$(branch)
    

    Or something along those lines.

提交回复
热议问题