Subproject parsing

Does not handle keyboards without subprojects correctly yet.
This commit is contained in:
Fred Sundvik 2016-08-07 14:33:49 +03:00
parent 9ee6d4a23d
commit 1df6498721

View file

@ -51,6 +51,7 @@ $(info Keyboards: $(KEYBOARDS))
# Otherwise the RULE_FOUND variable is set to false
# The function is a bit tricky, since there's no built in $(startswith) function
define COMPARE_AND_REMOVE_FROM_RULE
RULE_FOUND := false
ifeq ($1,$$(RULE))
RULE:=
RULE_FOUND := true
@ -70,11 +71,13 @@ endef
# 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
$$(eval $$(call COMPARE_AND_REMOVE_FROM_RULE,$$(firstword $1)))
ifeq ($$(RULE_FOUND),true)
MATCHED_ITEM := $$(firstword $1)
else ifneq ($1,)
$$(eval $$(call TRY_TO_MATCH_RULE_FROM_LIST,$$(wordlist 2,9999,$1)))
ifneq ($1,)
$$(eval $$(call COMPARE_AND_REMOVE_FROM_RULE,$$(firstword $1)))
ifeq ($$(RULE_FOUND),true)
MATCHED_ITEM := $$(firstword $1)
else
$$(eval $$(call TRY_TO_MATCH_RULE_FROM_LIST,$$(wordlist 2,9999,$1)))
endif
endif
endef
@ -96,10 +99,18 @@ define PARSE_ALL_KEYMAPS
$$(eval $$(call PARSE_ALL_IN_LIST,PARSE_KEYMAP,$$(KEYMAPS)))
endef
# $1 = Keyboard
define PARSE_KEYBOARD
CURRENT_KB := $1
KEYMAPS := $(notdir $(patsubst %/.,%,$(wildcard $(ROOT_DIR)/keyboards/$1/keymaps/*/.)))
define PARSE_ALL_SUBPROJECTS
ifeq ($$(SUBPROJECTS),)
$$(eval $$(call PARSE_SUBPROJECT,))
else
$$(eval $$(call PARSE_ALL_IN_LIST,PARSE_SUBPROJECT,$$(SUBPROJECTS)))
endif
endef
# $1 Subproject
define PARSE_SUBPROJECT
CURRENT_SP := $1
KEYMAPS := $$(notdir $$(patsubst %/.,%,$$(wildcard $(ROOT_DIR)/keyboards/$$(CURRENT_KB)/keymaps/*/.)))
$$(eval $$(call COMPARE_AND_REMOVE_FROM_RULE,allkm))
ifeq ($$(RULE_FOUND),true)
$$(eval $$(call PARSE_ALL_KEYMAPS))
@ -111,11 +122,27 @@ define PARSE_KEYBOARD
endif
endef
# $1 = Keyboard
define PARSE_KEYBOARD
CURRENT_KB := $1
# A subproject is any keyboard subfolder with a makefile
SUBPROJECTS := $$(notdir $$(patsubst %/Makefile,%,$$(wildcard $(ROOT_DIR)/keyboards/$$(CURRENT_KB)/*/Makefile)))
$$(eval $$(call COMPARE_AND_REMOVE_FROM_RULE,allsp))
ifeq ($$(RULE_FOUND),true)
$$(eval $$(call PARSE_ALL_SUBPROJECTS))
else
$$(eval $$(call TRY_TO_MATCH_RULE_FROM_LIST,$$(SUBPROJECTS)))
ifeq ($$(RULE_FOUND),true)
$$(eval $$(call PARSE_SUBPROJECT,$$(MATCHED_ITEM)))
endif
endif
endef
# $1 Keymap
define PARSE_KEYMAP
CURRENT_KM = $1
COMMANDS += KEYBOARD_$$(CURRENT_KB)_KEYMAP_$$(CURRENT_KM)
COMMAND_KEYBOARD_$$(CURRENT_KB)_KEYMAP_$$(CURRENT_KM) := Keyboard $$(CURRENT_KB), Keymap $$(CURRENT_KM)
COMMANDS += KEYBOARD_$$(CURRENT_KB)_SUBPROJECT_$$(CURRENT_SP)_KEYMAP_$$(CURRENT_KM)
COMMAND_KEYBOARD_$$(CURRENT_KB)_SUBPROJECT_$(CURRENT_SP)_KEYMAP_$$(CURRENT_KM) := Keyboard $$(CURRENT_KB), Subproject $$(CURRENT_SP), Keymap $$(CURRENT_KM)
endef
define PARSE_RULE