Makefile Functions & Text Processing/Self-documenting help target

Extract target comments from the current makefile.

Section: Useful function recipes

Self-documenting help target

makefile
makefile
.PHONY: help
help:
	@grep -E '^[a-zA-Z0-9_.-]+:.*?## ' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "%-24s %s\n", $$1, $$2}'
Explanation

Popular pattern for `make help`.

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing Useful function recipes
Define whitespace helpers
Create reusable space or comma variables.
OpenIn sheetmakefilesame section
Use MAKECMDGOALS
Inspect requested goals.
OpenIn sheetmakefilesame section
Current makefile name
Get the most recently parsed makefile path.
OpenIn sheetmakefilesame section
subst replace text
Replace every occurrence of one string with another.
OpenIn sheetmakefile
if function
Select one of two expansions based on non-empty condition text.
OpenIn sheetmakefile
shell function
Capture shell command output at parse time.
OpenIn sheetmakefile