In order to generate a help text for the makefile, the makefile can be
read with something like awk. In addition, comments can be used to
provide contextual information about a given goal. For example, the
kubebuilder
projects generates an arcane looking one
liner.
This gist inspired by that one liner. It is its own executable script that can be called from the makefile. This help with readability.
It allows to write the documentation for the makefile in the makefile itself.
##@ Options
GITHUB_SHA ?= $(shell git rev-parse main)
DOKTRI_AUTHROR ?= Nico Braun
DOKTRI_CHROMA_STYLE ?= tokyonight-moon
export DOKTRI_AUTHROR DOKTRI_CHROMA_STYLE
##@ Commands
help: $(CURDIR)/Makehelp ## show this help message
@$< $(MAKEFILE_LIST)
dev: ## run the development server
doktri serve
Makehelp:
curl -Lo $@ https://gist.githubusercontent.com/bluebrown/2ec155902622b5e46e2bfcbaff342eb9/raw/Makehelp.awk
chmod +x $@
When invoking make with the defaut or help
command, the help message
will be printed. The help message will look like this. Note that the
colors are not shown here, but they will be in the terminal.
$ make
Usage:
make [ command ] [ option=value ]...
Options:
GITHUB_SHA (default: $(shell git rev-parse main))
DOKTRI_AUTHROR (default: Nico Braun)
DOKTRI_CHROMA_STYLE (default: tokyonight-moon)
Commands:
help show this help message
dev run the development server