-
Notifications
You must be signed in to change notification settings - Fork 0
/
Function.mk
106 lines (77 loc) · 2.18 KB
/
Function.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
V ?= 1
ifeq ($(V),4)
define CMD-INFO
$(info $(1))
endef
endif
define NOSLASH
$(if $(filter %/, $(1)), \
$(call NOSLASH, $(patsubst %/, %, $(1))), \
$(1))
endef
define __FIND
$(1) $(foreach e, $(1), \
$(call FIND, $(wildcard $(strip $(e))/*)))
endef
define FIND
$(if $(1), $(strip $(call __FIND, $(call NOSLASH, $(1)))))
endef
define __SPLIT
$(if $(filter-out ., $(call NOSLASH, $(1))), \
$(call __SPLIT, $(dir $(call NOSLASH, $(1))), \
$(notdir $(call NOSLASH, $(1))) $(2)), \
$(2))
endef
define __CUMULATE
$(if $(filter 1, $(words $(1))), $(2) $(1), \
$(call __CUMULATE, \
$(word 1, $(1))/$(word 2, $(1)) $(wordlist 3, $(words $(1)), $(1)), \
$(2) $(word 1, $(1))))
endef
define PREFIXES
$(strip \
$(call __CUMULATE, $(call __SPLIT, $(1))))
endef
define REVERSE
$(if $(strip $(1)), \
$(call REVERSE, $(wordlist 2, $(words $(1)),$(1)), $(word 1, $(1)) $(2)), \
$(2))
endef
REQUIRE-DIR-DONE := .
define __GENERATE-DIR-TEMPLATE
$(call CMD-INFO, $(strip $(1)): | $(strip $(call NOSLASH, $(dir $(1)))))
$(call CMD-INFO, $$(call cmd-mkdir, $$@))
$(1): | $(call NOSLASH, $(dir $(1)))
$$(call cmd-mkdir, $$@)
REQUIRE-DIR-DONE += $(1)
$(call GENERATE-DIR, $(call NOSLASH, $(dir $(1))))
endef
define __GENERATE-DIR
$(if $(filter $(1), $(REQUIRE-DIR-DONE)), , \
$(eval $(call __GENERATE-DIR-TEMPLATE, $(1))))
endef
define GENERATE-DIR
$(foreach elm, $(call NOSLASH, $(1)), \
$(call __GENERATE-DIR, $(elm)))
endef
define __REQUIRE-DIR-TEMPLATE
$(call CMD-INFO, $(strip $(1)): | $(strip $(call NOSLASH, $(dir $(1)))))
$(1): | $(call NOSLASH, $(dir $(1)))
$(call GENERATE-DIR, $(call NOSLASH, $(dir $(1))))
endef
define REQUIRE-DIR
$(foreach elm, $(call NOSLASH, $(1)), \
$(eval $(call __REQUIRE-DIR-TEMPLATE, $(elm))))
endef
define __AUTODEP-RULE
$(call CMD-INFO, .depends: $(strip $(1)))
$(call CMD-INFO, $(strip $(1)): $(strip $(2)) .generated)
$(call CMD-INFO)
.depends: $(1)
$(1): $(2) .generated
$(call REQUIRE-DIR, $(1))
endef
define REQUIRE-DEP
$(foreach o, $(1), \
$(eval $(call __AUTODEP-RULE, $(patsubst %, .depends.d/%.d, $(o)), $(o))))
endef