Created
March 14, 2021 23:37
-
-
Save CGuichard/2eb3b784e1b6ec0eceac415d1efa4dd0 to your computer and use it in GitHub Desktop.
Self-documented Makefile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
##@ Welcome, this Makefile is an example of self-documented | |
##@ Makefile. Here are the features: | |
##@ - Add "##@" followed by a text to write the Makefile header text. | |
##@ You can also write the Makefile header inside a MAKEFILE_HELP variable. | |
##@ The last way is to write a Makefile.help file inside the same folder. | |
##@ - Add "##" next to one of the Makefile's target to document it. | |
.PHONY: default run | |
# ======================================================= # | |
default: run | |
run: ## Run the project. | |
@echo "Running..." | |
# ======================================================= # | |
HELP_COLUMN=5 | |
help: ## Show this help. | |
@printf "\033[1m################\n# Help #\n################\033[0m\n" | |
@if [ -n "$(MAKEFILE_HELP)" ]; then echo "\n$(MAKEFILE_HELP)"; fi; | |
@if [ -f Makefile.help ]; then echo && cat Makefile.help && echo; fi; | |
@awk 'BEGIN {FS = ":.*##@"; printf "\n"} /^##@/ { printf "%s\n", substr($$0, 5) } ' $(MAKEFILE_LIST) | |
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n\n make \033[36m<target>\033[0m\n\n"} /^[$$()% a-zA-Z_-]+:.*?##/ { printf " \033[36m%-$(HELP_COLUMN)s\033[0m %s\n", $$1, $$2 } ' $(MAKEFILE_LIST) | |
@printf "\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment