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.
If someone is interested, here is an adaptation of this help which supports multi-line documentation comments for both targets and variables (either defined globally, via define, or via a target), and categories (by adding a
@category The category
annotation in a doc comment).It uses two seds and a sort. The first sed is used to retrieve and parse the documentation into a 'tag' like format. The second sed is here to render the documentation properly. It might be possible to change the sort order by changing the names of the tags. I used two sed instead of one sed and one awk because it seems that the sed command is faster that the awk on the os I use.
Which whould print something lite this
Hope this helps.
If someone has any improvements, I'm all ears.