Skip to content

Instantly share code, notes, and snippets.

@shqld
Last active February 2, 2022 15:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shqld/7ed8e07b0242de5c52f94c7460557bb0 to your computer and use it in GitHub Desktop.
Save shqld/7ed8e07b0242de5c52f94c7460557bb0 to your computer and use it in GitHub Desktop.
'make help' for self-documenting Makefile
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}'
@shqld
Copy link
Author

shqld commented Feb 2, 2022

		$(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