A “simple” make
rule that allows pretty-printing short documentation for the
rules inside a Makefile:
Easy: simply copy everything starting at .DEFAULT_GOAL := show-help
to the end
of your own Makefile (or include show-help-minified.make
, and copy that file
into your project). Then document any rules by adding a single line starting
with ##
immediately before the rule. E.g.:
## Run unit tests
test:
./run-tests
Displaying the documentation is done by simply executing make
. This overrides
any previously set default command — you may not wish to do so; in that case,
simply remove the line that sets the .DEFAULT_GOAL
. You can then display the
help via make show-help
. This makes it less discoverable, of course.
@amotl I considered using
fold
but couldn’t get it to work satisfactorily (IIRC due to lack of support for hanging indents).Rendering comments as-is (including multiline comments) is, in a way, much easier since you don’t need to care about line breaks etc., but it’s fundamentally incompatible with the automatic line breaking approach: You’d need to choose either one or the other.