-
Notifications
You must be signed in to change notification settings - Fork 4
/
common.mk
62 lines (57 loc) · 1.72 KB
/
common.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
BLUE := $(shell tput -Txterm setaf 4)
GREEN := $(shell tput -Txterm setaf 2)
TURQUOISE := $(shell tput -Txterm setaf 6)
WHITE := $(shell tput -Txterm setaf 7)
YELLOW := $(shell tput -Txterm setaf 3)
GREY := $(shell tput -Txterm setaf 1)
RESET := $(shell tput -Txterm sgr0)
SMUL := $(shell tput smul)
RMUL := $(shell tput rmul)
# Add the following 'help' target to your Makefile
# And add help text after each target name starting with '\#\#'
# A category can be added with @category
HELP_FUN = \
%help; \
use Data::Dumper; \
while(<>) { \
if (/^([a-zA-Z\-]+)\s*:.*\#\#(?:@([a-zA-Z\-_\s]+))?\t(.*)$$/ \
|| /^([a-zA-Z\-]+)\s*:.*\#\#(?:@([a-zA-Z\-]+))?\s(.*)$$/) { \
$$c = $$2; $$t = $$1; $$d = $$3; \
push @{$$help{$$c}}, [$$t, $$d, $$ARGV] unless grep { grep { grep /^$$t$$/, $$_->[0] } @{$$help{$$_}} } keys %help; \
} \
}; \
for (sort keys %help) { \
printf("${WHITE}%24s:${RESET}\n\n", $$_); \
for (@{$$help{$$_}}) { \
printf("%s%25s${RESET}%s %s${RESET}\n", \
( $$_->[2] eq "Makefile" || $$_->[0] eq "help" ? "${YELLOW}" : "${GREY}"), \
$$_->[0], \
( $$_->[2] eq "Makefile" || $$_->[0] eq "help" ? "${GREEN}" : "${GREY}"), \
$$_->[1] \
); \
} \
print "\n"; \
}
# make
.DEFAULT_GOAL := help
# Variable wrapper
define defw
custom_vars += $(1)
$(1) ?= $(2)
export $(1)
shell_env += $(1)="$$($(1))"
endef
.PHONY: help
help:: ##@Other Show this help.
@echo ""
@printf "%30s " "${BLUE}VARIABLES"
@echo "${RESET}"
@echo ""
@printf "${BLUE}%25s${RESET}${TURQUOISE} ${SMUL}%s${RESET}\n" $(foreach v, $(custom_vars), $v $($(v)))
@echo ""
@echo ""
@echo ""
@printf "%30s " "${YELLOW}TARGETS"
@echo "${RESET}"
@echo ""
@perl -e '$(HELP_FUN)' $(MAKEFILE_LIST)