Skip to content

Instantly share code, notes, and snippets.

@clarkphp
Created May 16, 2021 12:44
Show Gist options
  • Save clarkphp/8c2333c701de307d7bd797feec4aed7c to your computer and use it in GitHub Desktop.
Save clarkphp/8c2333c701de307d7bd797feec4aed7c to your computer and use it in GitHub Desktop.
A Makefile to illustrate display of help text
#!make
########################## Variables #####################
HERE := $(dir $(realpath $(firstword $(MAKEFILE_LIST))))
##########################################################
# I encountered this idea from my colleague Roman Basayev
.PHONY:
default: help
##@ Help
help: ## A Makefile to illustrate display of help text. As far as I know, Roman Basayev developed this idea.
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[0-9a-zA-Z_-]+:.*?##/ { printf " \033[36m%-40s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
##@ Makefile Recipes in Category One
target-one: ## Help text for target one
@cd "$(HERE)"
@printf "\n\033[92mDoing that thing indicated by target-one...\033[0m\n"
# This is a regular comment, not displayed as help text, but displayed when running recipe
@echo "Da-doo-run-run, da-doo-run-run"
@printf "\n\033[92mTarget one thing is done now!\033[0m\n"
target-two: ## Help text for target two
@cd "$(HERE)"
@printf "\n\033[92mDoing that target two thing...\033[0m\n"
@echo "Running a river through it"
@printf "\n\033[92mTarget two thing is done now!\033[0m\n"
do-all-category-one-stuff: target-one target-two ## Do Category One - note dependencies are not displayed as help text, but double-hash comments are. Cool.
##@ This is Category Two
target-three: ## Help text for target three
@cd "$(HERE)"
@printf "\n\033[92mDoing that thing indicated by target-three...\033[0m\n"
# This is a regular comment
@echo "Letting the river run"
@printf "\n\033[92mTarget three thing is done now!\033[0m\n"
target-four: ## Help text for target four
@cd "$(HERE)"
@printf "\n\033[92mDoing that target four thing...\033[0m\n"
@echo "Running on empty"
@printf "\n\033[92mTarget four thing is done now!\033[0m\n"
do-all-category-two-stuff: target-three target-four ## Do all the things in Category Two
##@ This is Category Two
i-can-haz-it-all: do-all-category-one-stuff do-all-category-two-stuff ## Run everything. All of it. NOW!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment