-
Notifications
You must be signed in to change notification settings - Fork 2
/
help.mk
63 lines (60 loc) · 1.91 KB
/
help.mk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
###############################################################################
#
# Help text generator for .PHONY targets.
# Place two pound symbols between the .PHONY line and the actual
# definition of the recipe.
#
###############################################################################
.PHONY: help
# Based on https://gist.github.com/rcmachado/af3db315e31383502660
## Display this help text.
help:/
$(info Available targets)
$(info -----------------)
@awk '/^[a-zA-Z\-0-9]+:/ { \
helpMessage = match(lastLine, /^## (.*)/); \
helpCommand = substr($$1, 0, index($$1, ":")-1); \
if (helpMessage) { \
helpMessage = substr(lastLine, RSTART + 3, RLENGTH); \
gsub(/##/, "\n ", helpMessage); \
} else { \
helpMessage = "(No documentation)"; \
} \
printf "%-35s - %s\n", helpCommand, helpMessage; \
lastLine = "" \
} \
{ hasComment = match(lastLine, /^## (.*)/); \
if(hasComment) { \
lastLine=lastLine$$0; \
} \
else { \
lastLine = $$0 \
} \
}' $(MAKEFILE_LIST)
.PHONY: help-html
# Based on https://gist.github.com/rcmachado/af3db315e31383502660
## Display this help text as an HTML definition list for better documentation generation
help-html:/
$(info Available targets)
@echo "<dl>"
@awk '/^[a-zA-Z\-0-9]+:/ { \
helpMessage = match(lastLine, /^## (.*)/); \
helpCommand = substr($$1, 0, index($$1, ":")-1); \
if (helpMessage) { \
helpMessage = substr(lastLine, RSTART + 3, RLENGTH); \
gsub(/##/, "<br/>\n", helpMessage); \
} else { \
helpMessage = "(No documentation)"; \
} \
printf "<dt><code>%s</code></dt><dd>%s</dd>\n", helpCommand, helpMessage; \
lastLine = "</dl>" \
} \
{ hasComment = match(lastLine, /^## (.*)/); \
if(hasComment) { \
lastLine=lastLine$$0; \
} \
else { \
lastLine = $$0 \
} \
}' $(MAKEFILE_LIST)
@echo "</dl>"