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:
1 parent
9ae82dcd57
commit
6149a156cd
3 files changed
+75
-5
No files matched your search
@@ -13,8 +13,9 @@ LYCHEE_VERSION := 0.24.2
|
||||
TOOLS_BIN := $(CURDIR)/.tools/bin
|
||||
export PATH := $(TOOLS_BIN):$(PATH)
|
||||
|
||||
.PHONY: all build index serve run link-check link-fix external-check external-fix external-fix-apply serve-lan clean bootstrap tool-versions preflight
|
||||
.PHONY: all build index serve run link-check link-fix external-check external-fix external-fix-apply serve-lan clean bootstrap tool-versions preflight help
|
||||
|
||||
# Default target: build content + search index (same as `make index`).
|
||||
all: index
|
||||
|
||||
# ONE-TIME per machine: install the pinned hugo/node/lychee into .tools/bin.
|
||||
@@ -45,6 +46,7 @@ index: build
|
||||
serve: index
|
||||
$(PAGEFIND) --site $(OUT) --serve
|
||||
|
||||
# Alias for `serve` (build + index + serve with search on :1414).
|
||||
run: serve
|
||||
|
||||
# DEAD LINKS -- internal (offline, fast): scan the SOURCE markdown; internal links
|
||||
@@ -88,8 +90,14 @@ external-fix-apply:
|
||||
serve-lan: preflight
|
||||
python3 scripts/serve_lan.py
|
||||
|
||||
# NOTE: clean does NOT remove .tools/ -- the pinned toolchain is expensive to
|
||||
# reinstall and independent of build output. Remove it manually if ever needed.
|
||||
|
||||
# Remove build output (public/ and linkcheck/).
|
||||
# NOTE: does NOT remove .tools/ -- the pinned toolchain is expensive to reinstall
|
||||
# and independent of build output. Remove it manually if ever needed.
|
||||
clean:
|
||||
rm -rf $(OUT) linkcheck
|
||||
|
||||
# List every make target with a one-line description (self-maintaining menu).
|
||||
# NOTE: `make --help` is reserved by GNU make (it prints make's own options and
|
||||
# cannot run a project target); use `make help` for this project's targets.
|
||||
help:
|
||||
@python3 scripts/make_help.py
|
||||
@@ -284,8 +284,11 @@ Run from the project root. `public/`, `linkcheck/`, `resources/_gen/`, and
|
||||
| `make link-check` | **Offline** scan of *internal* links in `content/` → `linkcheck/internal.json`. Fast, no network. |
|
||||
| `make link-fix` | Comment out confirmed dead *internal* links, then rebuild content + index. |
|
||||
| `make external-check` | **Network** scan of all *external* links in `content/` → console report + `linkcheck/external_dead.txt`. Report-only; always exits 0. |
|
||||
| `make clean` | Remove `public/` and `linkcheck/`. |
|
||||
| `make external-fix` | Preview which external links are truly dead (DNS failed / host unreachable). Report-only; changes nothing. Run `make external-check` first. |
|
||||
| `make external-fix-apply` | Comment out the truly-dead external links, then rebuild content + index. 404s/SSL/5xx/redirects/refused go to `linkcheck/manual_review_external.txt` (manual review). |
|
||||
| `make clean` | Remove `public/` and `linkcheck/` (does NOT remove `.tools/`). |
|
||||
| `make all` | `build` + `index` (the default target). |
|
||||
| `make help` | List every make target with a one-line description. (GNU make reserves `make --help` for its own options, so this project uses `make help`.) |
|
||||
|
||||
Notes on the targets:
|
||||
|
||||
|
||||
@@ -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()
|
||||
Reference in new issue
Block a user