Last active
February 2, 2022 15:25
-
-
Save shqld/7ed8e07b0242de5c52f94c7460557bb0 to your computer and use it in GitHub Desktop.
'make help' for self-documenting Makefile
This file contains hidden or 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
CUR := $(dir $(abspath $(firstword $(MAKEFILE_LIST)))) | |
NULL := /dev/null | |
define touch | |
@mkdir -p $(@D); touch $(@) | |
endef | |
.DEFAULT_GOAL := help | |
help: ## Self-documented Makefile | |
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) \ | |
$(foreach val, $(MAKEFILE_LIST), | sed 's|$(val):||') \ | |
| sort \ | |
| awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' |
$(foreach val, $(MAKEFILE_LIST), | sed 's|$(val):||') \
This line is for trimming the filenames of all included Makefiles that are implicitly prepended and verbose.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage
pbpaste > help.mk
include 'help.mk'
Example
https://github.com/shqld/ops/blob/fcc8f8663ee6d08edc9f2d4a566abd5241eed802/Makefile#L1
https://github.com/shqld/ops/blob/fcc8f8663ee6d08edc9f2d4a566abd5241eed802/lib.mk#L10-L16