Skip to content

Instantly share code, notes, and snippets.

@kwk
Forked from rcmachado/Makefile
Created June 11, 2021 11:51
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 kwk/1f757db07cf188ff1b803b37c9e0dec1 to your computer and use it in GitHub Desktop.
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
.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