Skip to content

Instantly share code, notes, and snippets.

@shiva
Forked from prwhite/Makefile
Last active November 1, 2015 23:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shiva/28883094c951098a7708 to your computer and use it in GitHub Desktop.
Save shiva/28883094c951098a7708 to your computer and use it in GitHub Desktop.
Add a help target to a Makefile that will allow all targets to be self documenting
# Add the following 'help' target to your Makefile
# And add help text after each target name starting with '\#\#'
help: ## Show help
@IFS=$$'\n' ; \
help_lines=(`fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##/:/'`); \
printf "%-10s %s\n" "target" "help" ; \
printf "%-10s %s\n" "------" "----" ; \
for help_line in $${help_lines[@]}; do \
IFS=$$':' ; \
help_split=($$help_line) ; \
help_command=`echo $${help_split[0]} | sed -e 's/^ *//' -e 's/ *$$//'` ; \
help_info=`echo $${help_split[2]} | sed -e 's/^ *//' -e 's/ *$$//'` ; \
printf '\033[36m'; \
printf "%-10s %s" $$help_command ; \
printf '\033[0m'; \
printf "%s\n" $$help_info; \
done
# Everything below is an example
target00: ## This message will show up when typing 'make help'
@echo does nothing
target01: ## This message will also show up when typing 'make help'
@echo does something
# Remember that targets can have multiple entries (if your target specifications are very long, etc.)
target02: ## This message will show up too!!!
target02: target00 target01
@echo does even more
@shiva
Copy link
Author

shiva commented Nov 1, 2015

Help in ANSI color

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment