summaryrefslogtreecommitdiff
path: root/Makefile
diff options
context:
space:
mode:
authorJoel Challis <git@zvecr.com>2022-01-25 00:50:35 +0000
committerGitHub <noreply@github.com>2022-01-25 11:50:35 +1100
commit7df371750f297480ba5e78559ad3314b2d580888 (patch)
tree618281768d39f31c4764126f93af1db287e40f68 /Makefile
parent5f233458869bc5fd2d91b24f59c8519d5f99c9a6 (diff)
Workaround in Makefile for recursive rule matching (#15988)
* Bodge for recursive rule matching * Bodge for recursive rule matching - force python3 * Tidy up
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile51
1 files changed, 9 insertions, 42 deletions
diff --git a/Makefile b/Makefile
index b435837d30..22c79880a3 100644
--- a/Makefile
+++ b/Makefile
@@ -87,53 +87,20 @@ endef
87# a function that returns the value 87# a function that returns the value
88COMPARE_AND_REMOVE_FROM_RULE = $(eval $(call COMPARE_AND_REMOVE_FROM_RULE_HELPER,$1))$(RULE_FOUND) 88COMPARE_AND_REMOVE_FROM_RULE = $(eval $(call COMPARE_AND_REMOVE_FROM_RULE_HELPER,$1))$(RULE_FOUND)
89 89
90 90# Try to find a match for the start of the rule to be checked
91# Recursively try to find a match for the start of the rule to be checked
92# $1 The list to be checked
93# If a match is found, then RULE_FOUND is set to true
94# and MATCHED_ITEM to the item that was matched
95define TRY_TO_MATCH_RULE_FROM_LIST_HELPER3
96 ifneq ($1,)
97 ifeq ($$(call COMPARE_AND_REMOVE_FROM_RULE,$$(firstword $1)),true)
98 MATCHED_ITEM := $$(firstword $1)
99 else
100 $$(eval $$(call TRY_TO_MATCH_RULE_FROM_LIST_HELPER3,$$(wordlist 2,9999,$1)))
101 endif
102 endif
103endef
104
105# A recursive helper function for finding the longest match
106# $1 The list to be checked
107# It works by always removing the currently matched item from the list
108define TRY_TO_MATCH_RULE_FROM_LIST_HELPER2
109 # Stop the recursion when the list is empty
110 ifneq ($1,)
111 RULE_BEFORE := $$(RULE)
112 $$(eval $$(call TRY_TO_MATCH_RULE_FROM_LIST_HELPER3,$1))
113 # If a match is found in the current list, otherwise just return what we had before
114 ifeq ($$(RULE_FOUND),true)
115 # Save the best match so far and call itself recursively
116 BEST_MATCH := $$(MATCHED_ITEM)
117 BEST_MATCH_RULE := $$(RULE)
118 RULE_FOUND := false
119 RULE := $$(RULE_BEFORE)
120 $$(eval $$(call TRY_TO_MATCH_RULE_FROM_LIST_HELPER2,$$(filter-out $$(MATCHED_ITEM),$1)))
121 endif
122 endif
123endef
124
125
126# Recursively try to find the longest match for the start of the rule to be checked
127# $1 The list to be checked 91# $1 The list to be checked
128# If a match is found, then RULE_FOUND is set to true 92# If a match is found, then RULE_FOUND is set to true
129# and MATCHED_ITEM to the item that was matched 93# and MATCHED_ITEM to the item that was matched
130define TRY_TO_MATCH_RULE_FROM_LIST_HELPER 94define TRY_TO_MATCH_RULE_FROM_LIST_HELPER
131 BEST_MATCH := 95 # Split on ":", padding with empty strings to avoid indexing issues
132 $$(eval $$(call TRY_TO_MATCH_RULE_FROM_LIST_HELPER2,$1)) 96 TOKEN1:=$$(shell python3 -c "import sys; print((sys.argv[1].split(':',1)+[''])[0])" $$(RULE))
133 ifneq ($$(BEST_MATCH),) 97 TOKENr:=$$(shell python3 -c "import sys; print((sys.argv[1].split(':',1)+[''])[1])" $$(RULE))
98
99 FOUNDx:=$$(shell echo $1 | tr " " "\n" | grep -Fx $$(TOKEN1))
100 ifneq ($$(FOUNDx),)
101 RULE := $$(TOKENr)
134 RULE_FOUND := true 102 RULE_FOUND := true
135 RULE := $$(BEST_MATCH_RULE) 103 MATCHED_ITEM := $$(TOKEN1)
136 MATCHED_ITEM := $$(BEST_MATCH)
137 else 104 else
138 RULE_FOUND := false 105 RULE_FOUND := false
139 MATCHED_ITEM := 106 MATCHED_ITEM :=