Created
October 17, 2017 21:27
-
-
Save denibertovic/9644dbdd88fe9c09e730edbac43892b9 to your computer and use it in GitHub Desktop.
Self documenting 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
.PHONY: help cmd1 cmd2 | |
.DEFAULT_GOAL = help | |
## Runs cmd 1. | |
cmd1: | |
@echo "Running cmd one..." | |
## Runs cmd 2. | |
cmd2: | |
@echo "Running cmd two..." | |
## Show help screen. | |
help: | |
@echo "Please use \`make <target>' where <target> is one of\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 "%-30s %s\n", helpCommand, helpMessage; \ | |
} \ | |
} \ | |
{ lastLine = $$0 }' $(MAKEFILE_LIST) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment