- # A subproject is any keyboard subfolder with a makefile
- SUBPROJECTS := $$(notdir $$(patsubst %/Makefile,%,$$(wildcard $(ROOT_DIR)/keyboards/$$(CURRENT_KB)/*/Makefile)))
- # if the rule starts with allsp, then continue with looping over all subprojects
- ifeq ($$(call COMPARE_AND_REMOVE_FROM_RULE,allsp),true)
- $$(eval $$(call PARSE_ALL_SUBPROJECTS))
- # A special case for matching the defaultsp (default subproject)
- else ifeq ($$(call COMPARE_AND_REMOVE_FROM_RULE,defaultsp),true)
- $$(eval $$(call PARSE_SUBPROJECT,defaultsp))
- # If the rule starts with the name of a known subproject
- else ifeq ($$(call TRY_TO_MATCH_RULE_FROM_LIST,$$(SUBPROJECTS)),true)
- $$(eval $$(call PARSE_SUBPROJECT,$$(MATCHED_ITEM)))
- # Try to use the SUBPROJECT variable, which is either determined by the
- # directory which invoked make, or passed as an argument to make
- else ifneq ($$(SUBPROJECT),)
- $$(eval $$(call PARSE_SUBPROJECT,$$(SUBPROJECT)))
- # If there's no matching subproject, we assume it's the default
- # This will allow you to leave the subproject part of the target out
+
+ # KEYBOARD_FOLDERS := $$(subst /, , $(CURRENT_KB))
+
+ DEFAULT_FOLDER := $$(CURRENT_KB)
+
+ # We assume that every rules.mk will contain the full default value
+ $$(eval include $(ROOT_DIR)/keyboards/$$(CURRENT_KB)/rules.mk)
+ ifneq ($$(DEFAULT_FOLDER),$$(CURRENT_KB))
+ $$(eval include $(ROOT_DIR)/keyboards/$$(DEFAULT_FOLDER)/rules.mk)
+ endif
+ CURRENT_KB := $$(DEFAULT_FOLDER)
+
+ # 5/4/3/2/1
+ KEYBOARD_FOLDER_PATH_1 := $$(CURRENT_KB)
+ KEYBOARD_FOLDER_PATH_2 := $$(patsubst %/,%,$$(dir $$(KEYBOARD_FOLDER_PATH_1)))
+ KEYBOARD_FOLDER_PATH_3 := $$(patsubst %/,%,$$(dir $$(KEYBOARD_FOLDER_PATH_2)))
+ KEYBOARD_FOLDER_PATH_4 := $$(patsubst %/,%,$$(dir $$(KEYBOARD_FOLDER_PATH_3)))
+ KEYBOARD_FOLDER_PATH_5 := $$(patsubst %/,%,$$(dir $$(KEYBOARD_FOLDER_PATH_4)))
+ KEYBOARD_FOLDER_1 := $$(notdir $$(KEYBOARD_FOLDER_PATH_1))
+ KEYBOARD_FOLDER_2 := $$(notdir $$(KEYBOARD_FOLDER_PATH_2))
+ KEYBOARD_FOLDER_3 := $$(notdir $$(KEYBOARD_FOLDER_PATH_3))
+ KEYBOARD_FOLDER_4 := $$(notdir $$(KEYBOARD_FOLDER_PATH_4))
+ KEYBOARD_FOLDER_5 := $$(notdir $$(KEYBOARD_FOLDER_PATH_5))
+
+ KEYMAPS :=
+ # get a list of all keymaps
+ KEYMAPS += $$(notdir $$(patsubst %/.,%,$$(wildcard $(ROOT_DIR)/keyboards/$$(KEYBOARD_FOLDER_PATH_1)/keymaps/*/.)))
+ KEYMAPS += $$(notdir $$(patsubst %/.,%,$$(wildcard $(ROOT_DIR)/keyboards/$$(KEYBOARD_FOLDER_PATH_2)/keymaps/*/.)))
+ KEYMAPS += $$(notdir $$(patsubst %/.,%,$$(wildcard $(ROOT_DIR)/keyboards/$$(KEYBOARD_FOLDER_PATH_3)/keymaps/*/.)))
+ KEYMAPS += $$(notdir $$(patsubst %/.,%,$$(wildcard $(ROOT_DIR)/keyboards/$$(KEYBOARD_FOLDER_PATH_4)/keymaps/*/.)))
+ KEYMAPS += $$(notdir $$(patsubst %/.,%,$$(wildcard $(ROOT_DIR)/keyboards/$$(KEYBOARD_FOLDER_PATH_5)/keymaps/*/.)))
+ # this might be needed, but in a different form
+ #KEYMAPS := $$(sort $$(filter-out $$(KEYBOARD_FOLDER_1) $$(KEYBOARD_FOLDER_2) \
+ $$(KEYBOARD_FOLDER_3) $$(KEYBOARD_FOLDER_4) $$(KEYBOARD_FOLDER_5), $$(KEYMAPS)))
+
+ KEYBOARD_LAYOUTS :=
+ ifneq ("$$(wildcard $(ROOT_DIR)/keyboards/$$(KEYBOARD_FOLDER_5)/rules.mk)","")
+ LAYOUTS :=
+ $$(eval include $(ROOT_DIR)/keyboards/$$(KEYBOARD_FOLDER_5)/rules.mk)
+ KEYBOARD_LAYOUTS := $$(sort $$(LAYOUTS) $$(KEYBOARD_LAYOUTS))
+ endif
+ ifneq ("$$(wildcard $(ROOT_DIR)/keyboards/$$(KEYBOARD_FOLDER_4)/rules.mk)","")
+ LAYOUTS :=
+ $$(eval include $(ROOT_DIR)/keyboards/$$(KEYBOARD_FOLDER_4)/rules.mk)
+ KEYBOARD_LAYOUTS := $$(sort $$(LAYOUTS) $$(KEYBOARD_LAYOUTS))
+ endif
+ ifneq ("$$(wildcard $(ROOT_DIR)/keyboards/$$(KEYBOARD_FOLDER_3)/rules.mk)","")
+ LAYOUTS :=
+ $$(eval include $(ROOT_DIR)/keyboards/$$(KEYBOARD_FOLDER_3)/rules.mk)
+ KEYBOARD_LAYOUTS := $$(sort $$(LAYOUTS) $$(KEYBOARD_LAYOUTS))
+ endif
+ ifneq ("$$(wildcard $(ROOT_DIR)/keyboards/$$(KEYBOARD_FOLDER_2)/rules.mk)","")
+ LAYOUTS :=
+ $$(eval include $(ROOT_DIR)/keyboards/$$(KEYBOARD_FOLDER_2)/rules.mk)
+ KEYBOARD_LAYOUTS := $$(sort $$(LAYOUTS) $$(KEYBOARD_LAYOUTS))
+ endif
+ ifneq ("$$(wildcard $(ROOT_DIR)/keyboards/$$(KEYBOARD_FOLDER_1)/rules.mk)","")
+ LAYOUTS :=
+ $$(eval include $(ROOT_DIR)/keyboards/$$(KEYBOARD_FOLDER_1)/rules.mk)
+ KEYBOARD_LAYOUTS := $$(sort $$(LAYOUTS) $$(KEYBOARD_LAYOUTS))
+ endif
+
+ LAYOUT_KEYMAPS :=
+ $$(foreach LAYOUT,$$(KEYBOARD_LAYOUTS),$$(eval LAYOUT_KEYMAPS += $$(notdir $$(patsubst %/.,%,$$(wildcard $(ROOT_DIR)/layouts/*/$$(LAYOUT)/*/.)))))
+
+ KEYMAPS := $$(sort $$(KEYMAPS) $$(LAYOUT_KEYMAPS))
+
+ # if the rule after removing the start of it is empty (we haven't specified a kemap or target)
+ # compile all the keymaps
+ ifeq ($$(RULE),)
+ $$(eval $$(call PARSE_ALL_KEYMAPS))
+ # The same if all was specified
+ else ifeq ($$(call COMPARE_AND_REMOVE_FROM_RULE,all),true)
+ $$(eval $$(call PARSE_ALL_KEYMAPS))
+ # Try to match the specified keyamp with the list of known keymaps
+ else ifeq ($$(call TRY_TO_MATCH_RULE_FROM_LIST,$$(KEYMAPS)),true)
+ $$(eval $$(call PARSE_KEYMAP,$$(MATCHED_ITEM)))
+ # Otherwise try to match the keymap from the current folder, or arguments to the make command
+ else ifneq ($$(KEYMAP),)
+ $$(eval $$(call PARSE_KEYMAP,$$(KEYMAP)))
+ # Otherwise, make all keymaps, again this is consistent with how it works without
+ # any arguments