-
Notifications
You must be signed in to change notification settings - Fork 1
/
help.mk
38 lines (34 loc) · 1.61 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
#
# This is the Help Support
#
# Original is from: https://codereview.stackexchange.com/questions/94307/built-in-help-in-a-makefile
#
# Howto:
# Label the `target: ` with a double hashed (##) comment. @category prefix is optional.
#
.PHONY: help
help: ## @other Show this help.
@perl -e '$(HELP_FUNC)' $(MAKEFILE_LIST)
# Colours for the Help
#
GREEN := $(shell tput -Txterm setaf 2)
WHITE := $(shell tput -Txterm setaf 7)
YELLOW := $(shell tput -Txterm setaf 3)
RESET := $(shell tput -Txterm sgr0)
#
# main function in Perl, which reads the Makefile, extracting the Help text
#
HELP_FUNC = \
while(<>) { \
push @{$$hyy{$$2 // 'options'}}, [$$1, $$3] if \
/^([\$$\(\)a-zA-Z0-9\-\.%\/_]+)\s*:.*\#\#(?:\s?@([a-zA-Z0-9_\-]+))?\s(.*)$$/ \
}; \
print "usage make [target]\n\n"; \
for (sort keys %hyy) { \
print "${WHITE}$$_:${RESET}\n"; \
for (@{$$hyy{$$_}}) { \
$$sep = " " x (32 - length $$_->[0]); \
print " ${YELLOW}$$_->[0]${RESET}$$sep${GREEN}$$_->[1]${RESET}\n"; \
}; \
print "\n"; \
}