Hacker News new | ask | show | jobs
by b5n 978 days ago
I've found this to come in handy, and it is easy to modify to immediate needs.

  .DEFAULT_GOAL = help

  .PHONY: help
  ##@ HELP
  help: ## display this help
          @awk 'BEGIN {FS = ":.*##"; \
          printf "\033[1mUSAGE\n\033[0m  make \033[36m<TARGET>\033[0m\n"} \
          /^[a-zA-Z_-]+\.*[a-zA-Z]*:.*?##/ {printf "  \033[36m%-12s\033[0m %s\n", $$1, $$2} \
          /^##@/ {printf "\n\033[1m%s\033[0m\n", substr($$0, 5)} \
          /^###/ {printf "\033[0m\t\t %s\033[0m\n", substr($$0, 4)}' $(MAKEFILE_LIST)

  .PHONY: foo bar baz
  ##@ DEMO
  foo: bar ## foo target
  ### additional foo target details
          @echo foo

  bar: ## bar target
          @echo bar

  baz: ## baz target
          @echo baz
1 comments

Lots of other good Makefile `help` target suggestions here.

   https://gist.github.com/prwhite/8168133
My favorite is (since it only depends on a recent bash):

   SHELL:=/bin/bash
   .PHONY: help help_target-funky+names.0k and_with_2_targets_and_spaces_like_bison
   help_target-funky+names.0k and_with_2_targets_and_spaces_like_bison: ## Funky ones & bison dual target display ok
           echo "bad - why are you not displaying?"
   help: ## bash help
   help: ## moar bash help
           @RE='^[a-zA-Z0-9 ._+-]*:[a-zA-Z0-9 ._+-]*##' ; while read line ; do [[ "$$line" =~ $$RE ]] && echo "$$line" ; done <$(MAKEFILE_LIST) ; RE=''