# make-help.awk # # Purpose: # Generate `make help` output by pairing: # - a comment line: `## Description...` # - the next target line: `target: ...` # # If you think in Python/JS terms: # - `pending_doc` is a small state variable (like a closure var in a parser loop). # - each input line is processed as a record. # - when we see `## ...`, we store it. # - when we see `target:`, we print `target -> stored description` and clear state. BEGIN { pending_doc = "" } # Capture human-facing docs from lines like: # ## Build the image. /^## / { pending_doc = substr($0, 4) next } # Match make targets like: # build: deps... # Ignore special targets (.PHONY etc.) and variable assignments. /^[a-zA-Z0-9_.-]+:/ { if (pending_doc != "") { split($0, parts, ":") target = parts[1] printf " %-12s - %s\n", target, pending_doc pending_doc = "" } }