Skip to content

Instantly share code, notes, and snippets.

@bluebrown
Last active July 30, 2026 19:33
Show Gist options
  • Select an option

  • Save bluebrown/2ec155902622b5e46e2bfcbaff342eb9 to your computer and use it in GitHub Desktop.

Select an option

Save bluebrown/2ec155902622b5e46e2bfcbaff342eb9 to your computer and use it in GitHub Desktop.
awk script to generate a help text from a Makefile

Makehelp

Generates help text for makefiles based on comment annotations.

Usage

Fetch the script and point it at one or more makefiles

curl -#fSLO https://gist.githubusercontent.com/bluebrown/2ec155902622b5e46e2bfcbaff342eb9/raw/Makehelp.awk
awk -f Makehelp.awk Makefile

Or from within the Makefile:

help:  ## show this help message
    @awk -f Makehelp.awk $(MAKEFILE_LIST)
##@ Options
fruits ?= lime strawberry pineapple
##@ Commands
help: ## show this help message
@./Makehelp.awk $(MAKEFILE_LIST)
smoothie: $(fruits) ## make a soomthie using $fruits
@shuf -e $^
$(fruits): # single # undcoumented no op
#!/usr/bin/env -S awk -f
BEGIN { FS = "[[:space:]]*(#?##@|:.*##|\\?=)[[:space:]]*" }
# ##@ <heading>
/^#?##@/ { printf("\n%s\n", $2); next }
# <target>: ## <description>
/^[a-zA-Z_0-9/-]+:.*##/ { printf(" %-20s%s\n", $1, $2); next }
# [export] <variable> ?= [<default>]
/^(export[[:space:]]+)?[a-zA-Z_0-9/-]+[[:space:]]*\?=/ {
sub(/^export[ \t]+/, "", $1); printf(" %-20s%s\n", $1, $2)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment