build: add make help menu listing all targets

GNU make reserves 'make --help' for its own options, so a project cannot
override that flag; the idiomatic equivalent is 'make help'. Add a
self-maintaining help target that parses the Makefile (via
scripts/make_help.py) and lists every target with a one-line description,
so it stays in sync when targets are added/removed. Also add the missing
external-fix / external-fix-apply rows to the README make-command table.

Verified: 'make help' lists all 16 targets (exit 0); default build unchanged.
This commit is contained in:
noether committed 2026-11-01 22:29:39 -07:00
1 parent 9ae82dcd57
commit 6149a156cd
3 files changed
+75 -5

No files matched your search

+59
View File
@@ -0,0 +1,59 @@
#!/usr/bin/env python3
"""Print a help menu of this project's make targets.
Parses the repo Makefile and lists every target with the first line of its
preceding comment block as the description. Self-maintaining: add a target plus
a comment and it appears here automatically -- no list to keep in sync.
Run via `make help` (GNU make reserves `make --help` for its own options, so a
project cannot override that flag).
"""
import os
import re
# The Makefile lives at the repo root; this script is in scripts/.
MAKEFILE = os.path.join(
os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "Makefile"
)
# A target line: name at column 0, optional whitespace, ':' NOT immediately
# followed by '=' (which would make it a variable assignment like `HUGO := hugo`).
# Names starting with '.' (e.g. the .PHONY line) are excluded.
TARGET_RE = re.compile(r"^([A-Za-z0-9_-]+)[ \t]*:(?!=)")
def parse_targets(path):
"""Return an ordered list of (name, first_comment_line) for each target."""
targets = []
comment_buf = []
with open(path) as f:
for line in f:
stripped = line.lstrip()
if stripped.startswith("#"):
comment_buf.append(stripped.lstrip("#").strip())
continue
if not line[0].isspace():
m = TARGET_RE.match(line)
if m:
targets.append((m.group(1), comment_buf[0] if comment_buf else ""))
comment_buf = []
continue
# Any other non-comment line resets the pending comment block.
comment_buf = []
return targets
def main():
targets = parse_targets(MAKEFILE)
width = max((len(name) for name, _ in targets), default=0)
print("Liberty Tools -- available make targets:")
print()
for name, desc in targets:
print(f" make {name:<{width}} {desc}")
print()
print("Note: `make --help` is reserved by GNU make; use `make help` for this menu.")
print("Toolchain is pinned in .tools/ (run `make bootstrap` once). See README.md for details.")
if __name__ == "__main__":
main()