Skip to content

Instantly share code, notes, and snippets.

@vrcca
Last active November 27, 2018 16:50
Show Gist options
  • Save vrcca/4898d1b493c998fec306994f895d735b to your computer and use it in GitHub Desktop.
Save vrcca/4898d1b493c998fec306994f895d735b to your computer and use it in GitHub Desktop.
Add the "help" rule to your Makefile
# Install: Save this file to a directory, then add: `include DocumentationMakefile.mk` at the top of your main Makefile.
# Adding docs: add a comment right after the target name following this pattern: ##@category_name description
# Usage: `make help`
#COLORS
GREEN := $(shell tput -Txterm setaf 2)
WHITE := $(shell tput -Txterm setaf 7)
YELLOW := $(shell tput -Txterm setaf 3)
RESET := $(shell tput -Txterm sgr0)
HELP_DOCS = \
%help; \
while(<>) { push @{$$help{$$2 // 'options'}}, [$$1, $$3] if /^([a-zA-Z\-]+)\s*:.*\#\#(?:@([a-zA-Z\-]+))?\s(.*)$$/ }; \
print "usage: make [target]\n\n"; \
for (sort keys %help) { \
print "${WHITE}$$_:${RESET}\n"; \
for (@{$$help{$$_}}) { \
$$sep = " " x (32 - length $$_->[0]); \
print " ${YELLOW}$$_->[0]${RESET}$$sep${GREEN}$$_->[1]${RESET}\n"; \
}; \
print "\n"; }
help: ##@other Show this help.
@perl -e '$(HELP_DOCS)' $(MAKEFILE_LIST)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment