Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to document a makefile?

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.

like image 885
J.N. Avatar asked Jan 17 '12 02:01

J.N.


People also ask

What is $? In makefile?

$? : The names of all prerequisites that are newer than the target, separated by spaces. $^ : The filenames of all the prerequisites, separated by spaces.

How do I run a makefile in terminal?

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.


2 Answers

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.
like image 108
Frelling Avatar answered Sep 30 '22 17:09

Frelling


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 :

enter image description here

like image 21
Rose Avatar answered Sep 30 '22 19:09

Rose