Skip to content

Instantly share code, notes, and snippets.

@sirn
Created March 13, 2020 08:35
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 sirn/cb83a686ed618763a1120e1848716a89 to your computer and use it in GitHub Desktop.
Save sirn/cb83a686ed618763a1120e1848716a89 to your computer and use it in GitHub Desktop.
amazing-makefile

tl;dr running make help prints:

Usage: make TARGET
help:
        Print this help
hello:
        Print hello and exit
        Really, that's pretty much it.
        
world:
        Print world and exit
help:
@: # Print this help
@printf 'Usage: make TARGET\n'
@awk ' \
/^[^\t:]+:/ { \
split($$0, s, ":"); \
cmd=s[1]; \
} /^\t@: #/ { \
split($$0, t, ": # "); \
body=t[2]; \
doprnt=1; \
} { \
if (doprnt == 1) { \
if (cmd != "") { \
printf("\n\033[33m%s\033[0m:\n", cmd); \
cmd="" \
}; \
printf("\t%s\n", body); \
doprnt=0; \
body=""; \
}; \
} \
' Makefile
hello:
@: # Print hello and exit
@: #
@: # Really, that's pretty much it.
echo hello
world:
@: # Print world and exit
echo world
.PHONY: help hello world
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment