Skip to content

Instantly share code, notes, and snippets.

@elfsternberg
Created October 3, 2019 20:22
Show Gist options
  • Save elfsternberg/992f5de76c1d7b5af7f5e6daf32688ce to your computer and use it in GitHub Desktop.
Save elfsternberg/992f5de76c1d7b5af7f5e6daf32688ce to your computer and use it in GitHub Desktop.
A Makefile recipe for attaching short help messages to targets
.PHONY: default help
default: help
help: ## Print this help message
@M=$$(perl -ne 'm/^((\w|-)*):.*##/ && print length($$1)."\n"' Makefile | \
sort -nr | head -1) && \
perl -ne "m/^((\w|-)*):.*##\s*(.*)/ && print(sprintf(\"%s: %s\t%s\n\", \$$1, \" \"x($$M-length(\$$1)), \$$3))" Makefile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment