Skip to content

Instantly share code, notes, and snippets.

@denibertovic
Created October 17, 2017 21:27
Show Gist options
  • Save denibertovic/9644dbdd88fe9c09e730edbac43892b9 to your computer and use it in GitHub Desktop.
Save denibertovic/9644dbdd88fe9c09e730edbac43892b9 to your computer and use it in GitHub Desktop.
Self documenting Makefile
.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