With the following grep/sed combinations, you can keep the help for each target inline just above your target (or wherever you want it).
## Makefile for foo
## help: this clutter
help:
@grep -E '^## ' Makefile|grep -v ':'|sed 's,^## ,,g'
@echo This Makefile has the targets:
@grep -E '^## [.a-z]{2,}:' Makefile|sed 's,^## *,\t,g' |sed 's,: ,\t,g'
## tests: run the tests
tests: tests.exe
./tests.exe ${TESTNR}
Output of
$ make help
Makefile for foo
This Makefile has the targets:
help this clutter
all
tests run the tests
...
Nice, leet and meta. :-)
Some more words on Makefiles: You can use something like
CFLAGS=-O3 -Wall -Werror -Wextra -g -ansi -pedantic ${CCFLAGS}
and pass CCFLAGS from outside. This avoids having many many versions while trying to test things out. For example:
$ CCFLAGS="-DDEBUG -Os -DUSED_ALGORITHM=binsearch2" make tests
(if you didn’t notice yet, -DFOO lets you jump inside #ifdef FOO).
Recent Comments