I want to know inside a Makefile if my repo is clean or not. I found that git status --porcelain
can be my friend. I see it working within bash but I can't get it work in Makefile.
I want to set a variable in a Makefile depending on the status of git status --porcelain
.
# check if return value of shell is true or false works:
$(shell true)
ifneq ($(.SHELLSTATUS),0)
DIRTY=YES
else
DIRTY=NO
endif
$(shell test -z "$(git status --porcelain)" )
$(info $(.SHELLSTATUS))
But the last line of the Makefile always return 0
independent of the status of my repo. Maybe some missing escape sequences?
$
is special in Makefiles. You need to double it to propagate it to the underlying shell:
$(shell test -z "$$(git status --porcelain)" )
# ~~