Note: This article has a newer, extended version. Find it here:  Print Makefile targets to CLI .

Are you using Makefiles to create shortcuts for specific commands? Would you like to print a list of available directives in your CLI? You can!

Add the help directive below to your Makefile. I put it right at the top of my files, including the developer note.

# Developer note:
# If you add a new command, add a help text using by adding a comment on the
# same line as the command name. You should use the following structure:
# `<command name>  ## <help text>`
#
# See also:
# https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html

help:  ## Shows available Makefile commands in a list
    @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

On the first line of each directive, append two spaces, two number signs, a space, and an informative text (<command name> ## <help text>). When you execute make help on your CLI, you will see a list of all directive names followed by their informational text.

Want to know more about the command or how to customize it? Check out the article “Self-Documented Makefile” by Marmelab (external link, opens in the same browser tab).