Skip to content

Instantly share code, notes, and snippets.

@depressiveRobot
Forked from rcmachado/Makefile
Last active October 17, 2017 16:07
Show Gist options
  • Save depressiveRobot/46002002beabe2e7b4fd to your computer and use it in GitHub Desktop.
Save depressiveRobot/46002002beabe2e7b4fd to your computer and use it in GitHub Desktop.
Help target for self-documentation of a Makefile
.PHONY: # add tasks here to avoid timestamp checks
default: help
# Based on https://gist.github.com/prwhite/8168133#comment-1313022
## Another dummy task
dummy-task:
echo dummy
## 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 "%-30s %s\n", helpCommand, helpMessage; \
} \
} \
{ lastLine = $$0 }' $(MAKEFILE_LIST)
@mixman68
Copy link

helpCommand = substr($$1, 0, index($$1, ":")-1); truncated last letter of my command, need to remove -1 on my debian 9

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