summaryrefslogtreecommitdiffstats
path: root/Makefile
diff options
context:
space:
mode:
authorFred Sundvik <fsundvik@gmail.com>2016-08-21 12:10:34 +0200
committerFred Sundvik <fsundvik@gmail.com>2016-08-21 12:10:34 +0200
commit1c69acb7d518893ee77e326342d4603da87470e5 (patch)
treec02eec69c7e483a4ca203f6d671593da1b9ddc55 /Makefile
parentb26ded3ab1c09e2a127feb5f4e22e97242ce77d7 (diff)
downloadqmk_firmware-1c69acb7d518893ee77e326342d4603da87470e5.tar.gz
qmk_firmware-1c69acb7d518893ee77e326342d4603da87470e5.tar.xz
Add longest match to the rule-checking
This fixes cases where you have several keyboards with a common prefix, like algernon, and algernon-master
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile43
1 files changed, 41 insertions, 2 deletions
diff --git a/Makefile b/Makefile
index d70ac9a3b..c8122e576 100644
--- a/Makefile
+++ b/Makefile
@@ -152,13 +152,52 @@ COMPARE_AND_REMOVE_FROM_RULE = $(eval $(call COMPARE_AND_REMOVE_FROM_RULE_HELPER
# $1 The list to be checked
# If a match is found, then RULE_FOUND is set to true
# and MATCHED_ITEM to the item that was matched
-define TRY_TO_MATCH_RULE_FROM_LIST_HELPER
+define TRY_TO_MATCH_RULE_FROM_LIST_HELPER3
ifneq ($1,)
ifeq ($$(call COMPARE_AND_REMOVE_FROM_RULE,$$(firstword $1)),true)
MATCHED_ITEM := $$(firstword $1)
else
- $$(eval $$(call TRY_TO_MATCH_RULE_FROM_LIST_HELPER,$$(wordlist 2,9999,$1)))
+ $$(eval $$(call TRY_TO_MATCH_RULE_FROM_LIST_HELPER3,$$(wordlist 2,9999,$1)))
+ endif
+ endif
+endef
+
+# A recursive helper function for finding the longest match
+# $1 The list to be checed
+# It works by always removing the currently matched item from the list
+# and call itself recursively, until a match is found
+define TRY_TO_MATCH_RULE_FROM_LIST_HELPER2
+ # Stop the recursion when the list is empty
+ ifneq ($1,)
+ RULE_BEFORE := $$(RULE)
+ $$(eval $$(call TRY_TO_MATCH_RULE_FROM_LIST_HELPER3,$1))
+ # If a match is found in the current list, otherwise just return what we had before
+ ifeq ($$(RULE_FOUND),true)
+ # Save the best match so far and call itself recursivel
+ BEST_MATCH := $$(MATCHED_ITEM)
+ BEST_MATCH_RULE := $$(RULE)
+ RULE_FOUND := false
+ RULE := $$(RULE_BEFORE)
+ $$(eval $$(call TRY_TO_MATCH_RULE_FROM_LIST_HELPER2,$$(filter-out $$(MATCHED_ITEM),$1)))
endif
+ endif
+endef
+
+
+# Recursively try to find the longest match for the start of the rule to be checked
+# $1 The list to be checked
+# If a match is found, then RULE_FOUND is set to true
+# and MATCHED_ITEM to the item that was matched
+define TRY_TO_MATCH_RULE_FROM_LIST_HELPER
+ BEST_MATCH :=
+ $$(eval $$(call TRY_TO_MATCH_RULE_FROM_LIST_HELPER2,$1))
+ ifneq ($$(BEST_MATCH),)
+ RULE_FOUND := true
+ RULE := $$(BEST_MATCH_RULE)
+ MATCHED_ITEM := $$(BEST_MATCH)
+ else
+ RULE_FOUND := false
+ MATCHED_ITEM :=
endif
endef