Autodocumenting Makefiles
daniel.feldroy.com
daniel.feldroy.com
.PHONY: help
help: ## Display this help
@grep -E '^[ a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "%-30s %s\n", $$1, $$2}'
This was from HN a couple years ago .PHONY: help
help: # Show this help screen
@ack '^[a-zA-Z_-]+:.*?# .*$$' $(MAKEFILE_LIST) |\
sort -k1,1 |\
awk 'BEGIN {FS = ":.*?# "}; {printf "\033[1m%-30s\033[0m %s\n", $$1, $$2}'[1] https://www.thapaliya.com/en/writings/well-documented-makefi...
It has this functionality built-in, and avoids a lot of Make's idiosyncrasies. (Not affiliated, just a fan.)
Make is fiddly, has gotchas and is far from perfect, from the development side - but it's certainly "good enough", and it's great once you've got your Makefile done. And it's available, or at least easily attainable, pretty much everywhere. I even use it on Windows.
If you're on another OS where neither make nor python3 nor node.js are there by default, then sure you're already going to manually install make, so the choice of python3 or node.js is basically identical.
I use makefiles for my Rust code with just default+test+install targets that do no dependency tracking (since Rust's build system already does that much better). But if I need to add a target for, say, validating some OpenAPI spec that only needs to run if the spec file updates, then that can go in the same Makefile.
> GNU Make is a tool which controls the generation of executables and other non-source files of a program from the program's source files.
What is idiosyncratic is to think Make is first a command runner, and only after a file generator, and complain that it is doing a poor job at the former when it clearly says it is focusing on the latter.
I read the "idiosyncrasies" section on the just README and they are all performance related targeting file generation. All of those can be learned in one minute, as part of "I'll always find Makefiles in the wild, it's good to know the basics".
1. There are reasons, like consistency of interface which I value even more than autodocumentation, but that is outside the scope of this discussion.
2. For small orders of help.
You can easily write DVC stage files by hand as a straightforward Makefile replacement, and integrate other features into your workflow as needed/desired.
PS: quite feature complete but not yet well marketed so to speak. I'm actually recording an asciinema session this week in order for a visitor to grasp quicker the mentioned benefits.
It has sections and categorization.
I don't use make often, so it also contains beginner friendly comments about the syntax
.PHONY: help
help: # Display this help message
@awk 'BEGIN { \
FS = ": #"; \
printf "App name\n\n"; \
printf "Usage:\n make \033[38;5;141m<target>\033[0m\n\nTargets:\n" \
} /^(.+)\: #\ (.+)/ { \
printf " \033[38;5;141m%-11s\033[0m %s\n", $$1, $$2 \
}' $(MAKEFILE_LIST)I published my self-documenting docker Makefiles here:
(Now if I could integrate that into the autotools we use for some of our stuff....)