-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile.base.mk
65 lines (55 loc) · 979 Bytes
/
Makefile.base.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
64
65
.DEFAULT_GOAL := help
# -- cosmetics --
rs = \033[0m
ul = \033[4;37m
bd = \033[1;37m
rd = \033[1;31m
gr = \033[0;90m
gl = \033[4;90m
# -- functions --
define alias
$(1): $(2)
.PHONY: $(1)
endef
# -- help --
help:
@awk "$$HELP" $(MAKEFILE_LIST)
.PHONY: help
define HELP
BEGIN {
# set props
k_nsec = 0
# print header
print "$(gl)usage$(rs)"
print " $(bd)make <target>$(rs)\n"
print "$(gl)targets$(rs)"
}
# match and print sections
/^## -- .* --$$/ {
# parse name/desc
name = $$3
nlen = length(name)
desc = substr($$0, 7 + nlen, length($$0) - 9 - nlen)
# print section name
printf "%s $(ul)%s$(rs)%-*s$(gr) %s$(rs)\n",
(k_nsec == 0) ? "" : "\n",
name,
7 - nlen,
"",
desc
# incr section counter
k_nsec++
# consume line so next regex doesn't also match
getline
}
# match and print targets
/^## .*$$/ {
$$1 = ""
desc = $$0
getline;
sub(/:/, "", $$1)
name = $$1
printf " $(rd)%-$(help-colw)s$(gr) %s$(rs)\n", name, desc
}
endef
export HELP