A make
rule that allows pretty-printing short documentation for the rules inside a Makefile,
which supports multi-line documentation, for either targets and variables (defined globally, via define, or via a target definition),
and sorting by categories.
$ make help
Usage: make [TARGET [TARGET ...]] [ARGUMENT=VALUE [ARGUMENT=VALUE ...]]
Targets and Arguments:
cache-clear
delete the cache
help
show the help
Tests:
tests
run the tests
tests CACHE_RESULT (default: )
cache the test results
tests FILTERS (default: )
execute only the tests matching the given filter
tests STOP_ON_DEFECT (default: )
stop testing at first defect / failure
A target or a variable can be documented by adding one or multiple ##
before a target or a variable like so:
## a target which does something
target:
@echo "does something"
## a value used for disabling stuff
VARIABLE = value
A category can also be added to the documentation by using the tag @category
. The all line will then be used as the category's name.
## @category A specific category
## a documentation
## on multiple lines
target-with-category:
@echo "target on a category"
It uses 2 sed and 1 sort, and is made of 3 steps :
- The first sed is used to
- append the documentation after the target or the variable definition (thanks to klmr)
- parse the makefiles into an "html like" tag format. e.g. a variable's value would be prefixed and suffixed by
<value>
and</value>
- the categories are searched in the documentation comments, and is added at the begining of the line. If no category can be found, a default one is added
- The result is then sorted. Because the tags are "named" correctly, the
sort
command orders the lines like so- the default category is place before any other categories
- the global variables
- the target
- the target's variables
- A final
sed
is then used to render the help in the wanted final format, by replacing the "tags" with indentation and colors
Currently, it is necessary to add the @category
tag to both targets and variables documentations in order for them to be categorized in the same group. It might be possible to avoid this by adding yet another sed
after the first sort
, which would regroup the targets and their variables on the same line, and extract the categories and putting them at the beginning of the line, for being re-sorted yet again.
Based on a gist of klmr Which is based on an idea by @marmelab