Created
August 26, 2016 10:14
-
-
Save sjparkinson/f0413d429b12877ecb087c6fc30c1f0a to your computer and use it in GitHub Desktop.
Automatic help target using ## comments.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
help: ## Show this help message. | |
echo "usage: make [target] ..." | |
echo "" | |
echo "targets:" | |
fgrep --no-filename "##" ${MAKEFILE_LIST} | head -n '-1' | column -s ':#' -t -c 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For example:
Would output the following when calling
make help
:How it Works
1.
fgrep --no-filename "##" ${MAKEFILE_LIST}
${MAKEFILE_LIST}
is a special variable that contains a list of the Makefile file names. From this we usefgrep
to find all lines containing##
in the Makefiles.2.
head -n '-1'
Removes the last line of output, which is the
fgrep
one.3.
column -s ':#' -t -c 2
Pretty prints out the targets into columns, removing the colons and comment symbols.