feat(make): add makefile help and idiomatic cleanup#139
Closed
feat(make): add makefile help and idiomatic cleanup#139
Conversation
Add a `make help` target that uses an awk script to parse structured
comments in the Makefile itself. `##` comments describe individual
targets; `###` comments act as section headers. The output is grouped
into four sections: Build, Test, Code quality, and Graph generation.
Internal helper targets (like `check-graphviz` and
`rustup-clear-toolchain`) are intentionally left without `##` comments
so they stay hidden from the help output.
Idiomatic fixes applied across the board:
- `.DEFAULT_GOAL := build` replaces the old `default: build` target.
The old approach created a real target called `default` that showed
up in tab-completion and could collide with other tooling;
`.DEFAULT_GOAL` is the built-in make mechanism for this.
- `$(MAKE)` replaces bare `make` in the `golden` target. When make is
invoked with flags (e.g., `make -j4`), a bare `make` in a recipe
starts a fresh make process that loses those flags and, critically,
the jobserver file descriptors. `$(MAKE)` preserves both.
- `.PHONY` is now declared immediately above every phony target. A
phony target is one that doesn't produce a file of the same name
(i.e., `make build` doesn't create a file called `build`). Without
the declaration, if a file named `build` or `clean` happened to
exist, make would see it as up-to-date and skip the target entirely.
Previously several targets (`build`, `clean`, `golden`, `format`,
`style-check`) were missing their declarations.
- Variable references normalized from `${VAR}` to `$(VAR)`. Both work
identically in GNU make, but `$(VAR)` is the conventional style.
`${VAR}` is visually ambiguous with shell variable expansion inside
recipes, so reserving curly braces for shell context (like `$${rust}`)
and parens for make context makes it easier to tell which layer is
doing the expansion.
- `TOOLCHAIN_NAME=''` fixed to `TOOLCHAIN_NAME=`. Unlike in shell,
make does not interpret quotes as delimiters: the old value was
literally the two-character string `''`, not empty. This happened to
be harmless (rustup would just fail to find a toolchain named `''`)
but was misleading.
- Removed the `ECHO_CMD=echo` variable, which was only used once and
added indirection with no benefit. Replaced with a direct `@echo`.
There was a problem hiding this comment.
Pull request overview
Adds a self-documenting make help target to expose supported developer workflows directly from structured comments in the Makefile, while also tightening Make idioms to avoid common invocation and phony-target pitfalls.
Changes:
- Added a
helptarget that parses##(target descriptions) and###(section headers) fromMakefilevia awk and prints grouped help output. - Replaced
default: buildwith.DEFAULT_GOAL := buildand switched recursive make invocation to$(MAKE)for jobserver/flag preservation. - Normalized Make variable references and expanded
.PHONYdeclarations across targets; fixedTOOLCHAIN_NAME’s empty default value.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
`\s` is not POSIX awk; BSD awk (macOS default) treats it as a literal `s`. The patterns worked anyway because the comments are always at column 0, but this was a latent portability bug. Use bare `^##` / `^###` anchors instead. Addresses review feedback on PR #139.
Collaborator
Author
|
Replaced by #142 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You can make it if you try
Add a
make helptarget that uses an awk script to parse structured comments in the Makefile itself.##comments describe individual targets;###comments act as section headers. The output is grouped into four sections: Build, Test, Code quality, and Graph generation. Internal helper targets (likecheck-graphvizandrustup-clear-toolchain) are intentionally left without##comments so they stay hidden from the help output.Idiomatic fixes applied across the board:
.DEFAULT_GOAL := buildreplaces the olddefault: buildtarget. The old approach created a real target calleddefaultthat showed up in tab-completion and could collide with other tooling;.DEFAULT_GOALis the built-in make mechanism for this.$(MAKE)replaces baremakein thegoldentarget. When make is invoked with flags (e.g.,make -j4), a baremakein a recipe starts a fresh make process that loses those flags and, critically, the jobserver file descriptors.$(MAKE)preserves both..PHONYis now declared immediately above every phony target. A phony target is one that doesn't produce a file of the same name (i.e.,make builddoesn't create a file calledbuild). Without the declaration, if a file namedbuildorcleanhappened to exist, make would see it as up-to-date and skip the target entirely. Previously several targets (build,clean,golden,format,style-check) were missing their declarations.Variable references normalized from
${VAR}to$(VAR). Both work identically in GNU make, but$(VAR)is the conventional style.${VAR}is visually ambiguous with shell variable expansion inside recipes, so reserving curly braces for shell context (like$${rust}) and parens for make context makes it easier to tell which layer is doing the expansion.TOOLCHAIN_NAME=''fixed toTOOLCHAIN_NAME=. Unlike in shell, make does not interpret quotes as delimiters: the old value was literally the two-character string'', not empty. This happened to be harmless (rustup would just fail to find a toolchain named'') but was misleading.Removed the
ECHO_CMD=echovariable, which was only used once and added indirection with no benefit. Replaced with a direct@echo.