-
-
Save kwk/1f757db07cf188ff1b803b37c9e0dec1 to your computer and use it in GitHub Desktop.
Add a help target to a Makefile that will allow all targets to be self documenting
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
.SILENT: | |
.PHONY: help | |
# Based on https://gist.github.com/prwhite/8168133#comment-1313022 | |
## This help screen | |
help: | |
printf "Available targets\n\n" | |
awk '/^[a-zA-Z\-\_0-9]+:/ { \ | |
helpMessage = match(lastLine, /^## (.*)/); \ | |
if (helpMessage) { \ | |
helpCommand = substr($$1, 0, index($$1, ":")-1); \ | |
helpMessage = substr(lastLine, RSTART + 3, RLENGTH); \ | |
printf "%-15s %s\n", helpCommand, helpMessage; \ | |
} \ | |
} \ | |
{ lastLine = $$0 }' $(MAKEFILE_LIST) | |
## Another dummy task | |
another-dummy-task: | |
echo dummy |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment