There are lots of resources out there on writing self-documenting
make help
. (For example, my version is based upon this
post.) However, most of these require modifying an existing
Makefile, which is tedious when you have many projects, and also perhaps
you don’t want to commit the changes to the Makefile. Here’s an approach
to have access to make help
for all Makefiles, but only
locally.
We’ll need two things: A Makefile defining the help
rule,
and a bash alias to include the custom Makefile when calling
make
. You can use any of the existing solutions out there
for self-documenting Makefiles, you can find mine in my dotfiles, .help.Makefile.
Often other self-documenting “help” rules will only document commented
rules; my version documents everything except rules prefixed with “.”
(such as .PHONY
) or any explicitly ignored with “##
@ignore
”.
Next, edit your “.aliases” file in your home directory to include one of these two lines:
alias make="make -f ~/.help.Makefile -f Makefile"
alias make="make -f Makefile -f ~/.help.Makefile"
The difference between these is the order - Make treats the separate
Makefiles as one joined file; so when including “.help.Makefile” first,
make help
will be the default
goal (so calling make
will trigger make
help
), whereas having “Makefile” first will not change the
default goal.
This work is licensed under
CC BY-NC 4.0