Skip to content

Instantly share code, notes, and snippets.

@rcmachado
Last active February 7, 2024 06:04
Show Gist options
  • Star 32 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save rcmachado/af3db315e31383502660 to your computer and use it in GitHub Desktop.
Save rcmachado/af3db315e31383502660 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
@mbarkhau
Copy link

mbarkhau commented Nov 2, 2018

Some more variations here: https://gist.github.com/prwhite/8168133

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment