Slight refactoring to remove some verbosity
This commit is contained in:
parent
1df6498721
commit
286b3b8057
39
Makefile
39
Makefile
@ -50,8 +50,7 @@ $(info Keyboards: $(KEYBOARDS))
|
|||||||
# and $1 is removed from the RULE variable
|
# and $1 is removed from the RULE variable
|
||||||
# Otherwise the RULE_FOUND variable is set to false
|
# Otherwise the RULE_FOUND variable is set to false
|
||||||
# The function is a bit tricky, since there's no built in $(startswith) function
|
# The function is a bit tricky, since there's no built in $(startswith) function
|
||||||
define COMPARE_AND_REMOVE_FROM_RULE
|
define COMPARE_AND_REMOVE_FROM_RULE_HELPER
|
||||||
RULE_FOUND := false
|
|
||||||
ifeq ($1,$$(RULE))
|
ifeq ($1,$$(RULE))
|
||||||
RULE:=
|
RULE:=
|
||||||
RULE_FOUND := true
|
RULE_FOUND := true
|
||||||
@ -66,21 +65,25 @@ define COMPARE_AND_REMOVE_FROM_RULE
|
|||||||
endif
|
endif
|
||||||
endef
|
endef
|
||||||
|
|
||||||
|
COMPARE_AND_REMOVE_FROM_RULE = $(eval $(call COMPARE_AND_REMOVE_FROM_RULE_HELPER,$1))$(RULE_FOUND)
|
||||||
|
|
||||||
|
|
||||||
# Recursively try to find a match
|
# Recursively try to find a match
|
||||||
# $1 The list to be checked
|
# $1 The list to be checked
|
||||||
# If a match is found, then RULE_FOUND is set to true
|
# If a match is found, then RULE_FOUND is set to true
|
||||||
# and MATCHED_ITEM to the item that was matched
|
# and MATCHED_ITEM to the item that was matched
|
||||||
define TRY_TO_MATCH_RULE_FROM_LIST
|
define TRY_TO_MATCH_RULE_FROM_LIST_HELPER
|
||||||
ifneq ($1,)
|
ifneq ($1,)
|
||||||
$$(eval $$(call COMPARE_AND_REMOVE_FROM_RULE,$$(firstword $1)))
|
ifeq ($$(call COMPARE_AND_REMOVE_FROM_RULE,$$(firstword $1)),true)
|
||||||
ifeq ($$(RULE_FOUND),true)
|
|
||||||
MATCHED_ITEM := $$(firstword $1)
|
MATCHED_ITEM := $$(firstword $1)
|
||||||
else
|
else
|
||||||
$$(eval $$(call TRY_TO_MATCH_RULE_FROM_LIST,$$(wordlist 2,9999,$1)))
|
$$(eval $$(call TRY_TO_MATCH_RULE_FROM_LIST_HELPER,$$(wordlist 2,9999,$1)))
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
endef
|
endef
|
||||||
|
|
||||||
|
TRY_TO_MATCH_RULE_FROM_LIST = $(eval $(call TRY_TO_MATCH_RULE_FROM_LIST_HELPER,$1))$(RULE_FOUND)
|
||||||
|
|
||||||
define ALL_IN_LIST_LOOP
|
define ALL_IN_LIST_LOOP
|
||||||
OLD_RULE$1 := $$(RULE)
|
OLD_RULE$1 := $$(RULE)
|
||||||
$$(eval $$(call $1,$$(ITEM$1)))
|
$$(eval $$(call $1,$$(ITEM$1)))
|
||||||
@ -111,15 +114,11 @@ endef
|
|||||||
define PARSE_SUBPROJECT
|
define PARSE_SUBPROJECT
|
||||||
CURRENT_SP := $1
|
CURRENT_SP := $1
|
||||||
KEYMAPS := $$(notdir $$(patsubst %/.,%,$$(wildcard $(ROOT_DIR)/keyboards/$$(CURRENT_KB)/keymaps/*/.)))
|
KEYMAPS := $$(notdir $$(patsubst %/.,%,$$(wildcard $(ROOT_DIR)/keyboards/$$(CURRENT_KB)/keymaps/*/.)))
|
||||||
$$(eval $$(call COMPARE_AND_REMOVE_FROM_RULE,allkm))
|
ifeq ($$(call COMPARE_AND_REMOVE_FROM_RULE,allkm),true)
|
||||||
ifeq ($$(RULE_FOUND),true)
|
|
||||||
$$(eval $$(call PARSE_ALL_KEYMAPS))
|
$$(eval $$(call PARSE_ALL_KEYMAPS))
|
||||||
else
|
else ifeq ($$(call TRY_TO_MATCH_RULE_FROM_LIST,$$(KEYMAPS)),true)
|
||||||
$$(eval $$(call TRY_TO_MATCH_RULE_FROM_LIST,$$(KEYMAPS)))
|
|
||||||
ifeq ($$(RULE_FOUND),true)
|
|
||||||
$$(eval $$(call PARSE_KEYMAP,$$(MATCHED_ITEM)))
|
$$(eval $$(call PARSE_KEYMAP,$$(MATCHED_ITEM)))
|
||||||
endif
|
endif
|
||||||
endif
|
|
||||||
endef
|
endef
|
||||||
|
|
||||||
# $1 = Keyboard
|
# $1 = Keyboard
|
||||||
@ -127,15 +126,11 @@ define PARSE_KEYBOARD
|
|||||||
CURRENT_KB := $1
|
CURRENT_KB := $1
|
||||||
# A subproject is any keyboard subfolder with a makefile
|
# A subproject is any keyboard subfolder with a makefile
|
||||||
SUBPROJECTS := $$(notdir $$(patsubst %/Makefile,%,$$(wildcard $(ROOT_DIR)/keyboards/$$(CURRENT_KB)/*/Makefile)))
|
SUBPROJECTS := $$(notdir $$(patsubst %/Makefile,%,$$(wildcard $(ROOT_DIR)/keyboards/$$(CURRENT_KB)/*/Makefile)))
|
||||||
$$(eval $$(call COMPARE_AND_REMOVE_FROM_RULE,allsp))
|
ifeq ($$(call COMPARE_AND_REMOVE_FROM_RULE,allsp),true)
|
||||||
ifeq ($$(RULE_FOUND),true)
|
|
||||||
$$(eval $$(call PARSE_ALL_SUBPROJECTS))
|
$$(eval $$(call PARSE_ALL_SUBPROJECTS))
|
||||||
else
|
else ifeq ($$(call TRY_TO_MATCH_RULE_FROM_LIST,$$(SUBPROJECTS)),true)
|
||||||
$$(eval $$(call TRY_TO_MATCH_RULE_FROM_LIST,$$(SUBPROJECTS)))
|
|
||||||
ifeq ($$(RULE_FOUND),true)
|
|
||||||
$$(eval $$(call PARSE_SUBPROJECT,$$(MATCHED_ITEM)))
|
$$(eval $$(call PARSE_SUBPROJECT,$$(MATCHED_ITEM)))
|
||||||
endif
|
endif
|
||||||
endif
|
|
||||||
endef
|
endef
|
||||||
|
|
||||||
# $1 Keymap
|
# $1 Keymap
|
||||||
@ -148,15 +143,11 @@ endef
|
|||||||
define PARSE_RULE
|
define PARSE_RULE
|
||||||
RULE := $1
|
RULE := $1
|
||||||
COMMANDS :=
|
COMMANDS :=
|
||||||
$$(eval $$(call COMPARE_AND_REMOVE_FROM_RULE,allkb))
|
ifeq ($$(call COMPARE_AND_REMOVE_FROM_RULE,allkb),true)
|
||||||
ifeq ($$(RULE_FOUND),true)
|
|
||||||
$$(eval $$(call PARSE_ALL_KEYBOARDS))
|
$$(eval $$(call PARSE_ALL_KEYBOARDS))
|
||||||
else
|
else ifeq ($$(call TRY_TO_MATCH_RULE_FROM_LIST,$$(KEYBOARDS)),true)
|
||||||
$$(eval $$(call TRY_TO_MATCH_RULE_FROM_LIST,$$(KEYBOARDS)))
|
|
||||||
ifeq ($$(RULE_FOUND),true)
|
|
||||||
$$(eval $$(call PARSE_KEYBOARD,$$(MATCHED_ITEM)))
|
$$(eval $$(call PARSE_KEYBOARD,$$(MATCHED_ITEM)))
|
||||||
endif
|
endif
|
||||||
endif
|
|
||||||
endef
|
endef
|
||||||
|
|
||||||
RUN_COMMAND = echo "Running": $(COMMAND_$(COMMAND));
|
RUN_COMMAND = echo "Running": $(COMMAND_$(COMMAND));
|
||||||
|
Loading…
Reference in New Issue
Block a user