Skip to content

Instantly share code, notes, and snippets.

@sirn
Created March 25, 2020 15:12
Show Gist options
  • Save sirn/6a2f4c0b1cb917ef54b1fb813330d8e8 to your computer and use it in GitHub Desktop.
Save sirn/6a2f4c0b1cb917ef54b1fb813330d8e8 to your computer and use it in GitHub Desktop.
Making Makefile Awesome
help:
@: # Print this help
@printf 'Usage: make TARGET\n\n'
@printf 'You must run make with one of the following targets to continue:\n'
@printf 'Run make VERBOSE=1 TARGET for verbose log.\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
@sirn
Copy link
Author

sirn commented Mar 25, 2020

For VERBOSE=1 to work, you need this somewhere in Makefile:

$(VERBOSE).SILENT:

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