Skip to content

Instantly share code, notes, and snippets.

@leothelocust
Created January 20, 2021 19:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leothelocust/e93336194a48dcf04fcbda0676d8467a to your computer and use it in GitHub Desktop.
Save leothelocust/e93336194a48dcf04fcbda0676d8467a to your computer and use it in GitHub Desktop.
An example Makefile with dynamic "help" command
COMMAND_COLOR = \033[36m
DESC_COLOR = \033[32m
CLEAR_COLOR = \033[0m
.PHONY: help
help: ## prints this message ## (and puts this on line 2)
@echo ""; \
echo "Usage: make <command>"; \
echo ""; \
echo "where <command> is one of the following:"; \
echo ""; \
grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | \
perl -nle '/(.*?): ## (.*?) ## (.*$$)/; if ($$3 eq "") { printf ( "$(COMMAND_COLOR)%-20s$(DESC_COLOR)%s$(CLEAR_COLOR)\n\n", $$1, $$2) } else { printf ( "$(COMMAND_COLOR)%-20s$(DESC_COLOR)%s$(CLEAR_COLOR)\n%-20s%s\n\n", $$1, $$2, " ", $$3) }';
.PHONY: other
other: ## This description doesn't have a second line, but must end with pound pound ##
@echo "Example command...";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment