Created
September 27, 2023 17:26
-
-
Save elfsternberg/49ec1f8e0a1ff3b53d97f1c60013493f to your computer and use it in GitHub Desktop.
A much simpler "make help"
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
# make help | |
# | |
# Usage: Download this file and put it somewhere. In a GNU Makefile, add the | |
# following line near the top of your Makefile: | |
# | |
# ``` | |
# include /path/to/help.mk | |
# ``` | |
# | |
# Alternatively, you could just cut and paste the code from this gist into your | |
# Makefile. Any target that ends with "## description of target" will be shown | |
# with a helpful description. Including this one! Example: | |
# | |
# ``` | |
# $ make help | |
# | |
# Specify a command. The choices are: | |
# | |
# help: show this help | |
# | |
# $ | |
# ``` | |
# | |
# I firmly believe that Makefiles are documentation, and having a convenient and | |
# well-maintained documentation system embedded in your Makefiles is an important | |
# step to developer bliss. | |
# | |
HELP_WIDTH := $(shell grep '^[a-z][^ ]*:.*\#\#' Makefile 2>/dev/null | cut -d':' -f1 | awk '{printf "%d\n", length}' | sort -rn | head -1) | |
help: ## Show this help | |
@echo "\nSpecify a command. The choices are:\n" | |
@grep -Eh '^[0-9a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | \ | |
awk 'BEGIN {FS = ":.*?## "}; {printf " \033[0;36m%-$(HELP_WIDTH)s \033[m %s\n", $$1, $$2}' | \ | |
sort | |
@echo "" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment