Makefile $ (command) does not work, but `command` did

The fact is that when I wrote the Makefile for my project, when I needed to determine the current name of the branch, in make make I did this:

check_branch:
    if [ "$(git rev-parse --abbrev-ref HEAD)" == "master" ]; then \
    echo "In master"
    else \
    echo "Not in master"; \
    fi

When I called make check_branch, "$ (git rev-parse --abbrev-ref HEAD)" did not work, it returned "" an empty string. But instead, when I changed $ () to ,, it worked fine.

check_branch:
    if [ "`git rev-parse --abbrev-ref HEAD`" == "master" ]; then \
    echo "In master"
    else \
    echo "Not in master"; \
    fi

Why does $ () not work, but did? For git team only.

Note that in my Makefile I usually used $ () in many rules.

Thank:)

+5
source share
2 answers

, . Make $(git ...) (, ).

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

, script. .

, Make git , , :

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

, , :

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

- .

+3

All Articles