Last active
September 10, 2018 01:24
-
-
Save creichert/b4ff0c5be4d1ee161a20b26f4a4c8890 to your computer and use it in GitHub Desktop.
Self-documenting Makefile
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
$ make help | |
target help | |
------ ---- | |
foo this is a doc | |
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
SHELL := /bin/bash | |
foo: ## this is a doc | |
echo "foo" | |
.DEFAULT_GOAL := help | |
.PHONY: help | |
help: | |
@IFS=$$'\n' ; \ | |
help_lines=(`fgrep -h "##" $(MAKEFILE_LIST) \ | |
| fgrep -v fgrep \ | |
| grep -v '^\#' \ | |
| sed -e 's/\\$$//' \ | |
| sed -e 's/\#\#/:/'`); \ | |
printf "%-30s %s\n" "target" "help" ; \ | |
printf "%-30s %s\n" "------" "----" ; \ | |
for help_line in $${help_lines[@]}; do \ | |
IFS=$$':' ; \ | |
help_split=($$help_line) ; \ | |
help_command=` \ | |
echo $${help_split[0]} \ | |
| sed -e 's/^ *//' -e 's/ *$$//'`; \ | |
help_info=` \ | |
echo $${help_split[2]} \ | |
| sed -e 's/^ *//' -e 's/ *$$//'`; \ | |
printf "\033[36m%-30s\033[0m%s %s\n" $$help_command $$help_info; \ | |
done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment