Is there a way to write "standard" comments in a Makefile to later feed them to a Doxygen-like program so as to output a nice (HTML or man for instance) documentation ? I'd like to have a clear overview of my main targets somewhere but nothing too fancy.
$? : The names of all prerequisites that are newer than the target, separated by spaces. $^ : The filenames of all the prerequisites, separated by spaces.
Before running a Makefile in Windows, it is required to install the make command first by using the “Mingw-get install mingw32-make” command on the Command Prompt. Then, create a Makefile, remove the “. txt” extension, and use the “make” command to run the specified Makefile in Windows.
The following is a simpler solution that does not require defining user functions or aggregating help text away from the rules they document.
# This is a regular comment, that will not be displayed
## ----------------------------------------------------------------------
## This is a help comment. The purpose of this Makefile is to demonstrate
## a simple help mechanism that uses comments defined alongside the rules
## they describe without the need of additional help files or echoing of
## descriptions. Help comments are displayed in the order defined within
## the Makefile.
## ----------------------------------------------------------------------
help: ## Show this help.
@sed -ne '/@sed/!s/## //p' $(MAKEFILE_LIST)
build: ## Build something.
install: ## Install something.
deploy: ## Deploy something.
format: ## Help comments are display with their leading whitespace. For
## example, all comments in this snippet are aligned with spaces.
Running make
or make help
results in the following:
----------------------------------------------------------------------
This is a help comment. The purpose of this Makefile is to demonstrate
a simple help mechanism that uses comments defined alongside the rules
they describe without the need of additional help files or echoing of
descriptions. Help comments are displayed in the order defined within
the Makefile.
----------------------------------------------------------------------
help: Show this help.
build: Build something.
install: Install something.
deploy: Deploy something.
format: Help comments are display with their leading whitespace. For
example, all comments in this snippet are aligned with spaces.
In a makefile such as :
install: ## Do a
@echo "foo"
start: ## Do b
@echo "bar"
test: ## Do c
@echo "baz"
help:
@egrep -h '\s##\s' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m %-30s\033[0m %s\n", $$1, $$2}'
Will output :
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With