Skip to content

Instantly share code, notes, and snippets.

@creichert
Last active September 10, 2018 01:24
Show Gist options
  • Save creichert/b4ff0c5be4d1ee161a20b26f4a4c8890 to your computer and use it in GitHub Desktop.
Save creichert/b4ff0c5be4d1ee161a20b26f4a4c8890 to your computer and use it in GitHub Desktop.
Self-documenting Makefile
$ make help
target help
------ ----
foo this is a doc
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