diff options
author | Nick Brassel <[email protected]> | 2023-11-28 07:53:43 +1100 |
---|---|---|
committer | GitHub <[email protected]> | 2023-11-28 07:53:43 +1100 |
commit | 5501e804ff8d41ce656061b91896c4ac8c681d78 (patch) | |
tree | 6a655fbceaeab67cf727dbe4318721407dd31824 /builddefs | |
parent | 094357c40347e8a5db36578851f1af34a92e9f68 (diff) | |
download | qmk_firmware-5501e804ff8d41ce656061b91896c4ac8c681d78.tar.gz qmk_firmware-5501e804ff8d41ce656061b91896c4ac8c681d78.zip |
QMK Userspace (#22222)
Co-authored-by: Duncan Sutherland <[email protected]>
Diffstat (limited to 'builddefs')
-rw-r--r-- | builddefs/build_json.mk | 19 | ||||
-rw-r--r-- | builddefs/build_keyboard.mk | 96 | ||||
-rw-r--r-- | builddefs/build_layout.mk | 4 | ||||
-rw-r--r-- | builddefs/common_rules.mk | 11 |
4 files changed, 101 insertions, 29 deletions
diff --git a/builddefs/build_json.mk b/builddefs/build_json.mk index e29d678e48..e9d1420f36 100644 --- a/builddefs/build_json.mk +++ b/builddefs/build_json.mk @@ -15,3 +15,22 @@ else ifneq ("$(wildcard $(MAIN_KEYMAP_PATH_1)/keymap.json)","") KEYMAP_JSON := $(MAIN_KEYMAP_PATH_1)/keymap.json KEYMAP_JSON_PATH := $(MAIN_KEYMAP_PATH_1) endif + +ifneq ($(QMK_USERSPACE),) + ifneq ("$(wildcard $(QMK_USERSPACE)/$(MAIN_KEYMAP_PATH_5)/keymap.json)","") + KEYMAP_JSON := $(QMK_USERSPACE)/$(MAIN_KEYMAP_PATH_5)/keymap.json + KEYMAP_PATH := $(QMK_USERSPACE)/$(MAIN_KEYMAP_PATH_5) + else ifneq ("$(wildcard $(QMK_USERSPACE)/$(MAIN_KEYMAP_PATH_4)/keymap.json)","") + KEYMAP_JSON := $(QMK_USERSPACE)/$(MAIN_KEYMAP_PATH_4)/keymap.json + KEYMAP_PATH := $(QMK_USERSPACE)/$(MAIN_KEYMAP_PATH_4) + else ifneq ("$(wildcard $(QMK_USERSPACE)/$(MAIN_KEYMAP_PATH_3)/keymap.json)","") + KEYMAP_JSON := $(QMK_USERSPACE)/$(MAIN_KEYMAP_PATH_3)/keymap.json + KEYMAP_PATH := $(QMK_USERSPACE)/$(MAIN_KEYMAP_PATH_3) + else ifneq ("$(wildcard $(QMK_USERSPACE)/$(MAIN_KEYMAP_PATH_2)/keymap.json)","") + KEYMAP_JSON := $(QMK_USERSPACE)/$(MAIN_KEYMAP_PATH_2)/keymap.json + KEYMAP_PATH := $(QMK_USERSPACE)/$(MAIN_KEYMAP_PATH_2) + else ifneq ("$(wildcard $(QMK_USERSPACE)/$(MAIN_KEYMAP_PATH_1)/keymap.json)","") + KEYMAP_JSON := $(QMK_USERSPACE)/$(MAIN_KEYMAP_PATH_1)/keymap.json + KEYMAP_PATH := $(QMK_USERSPACE)/$(MAIN_KEYMAP_PATH_1) + endif +endif diff --git a/builddefs/build_keyboard.mk b/builddefs/build_keyboard.mk index 12a8c5b67b..f17171fe20 100644 --- a/builddefs/build_keyboard.mk +++ b/builddefs/build_keyboard.mk @@ -127,34 +127,60 @@ include $(INFO_RULES_MK) include $(BUILDDEFS_PATH)/build_json.mk # Pull in keymap level rules.mk -# Look through the possible keymap folders until we find a matching keymap.c -ifneq ("$(wildcard $(MAIN_KEYMAP_PATH_1)/keymap.c)","") - -include $(MAIN_KEYMAP_PATH_1)/rules.mk - KEYMAP_C := $(MAIN_KEYMAP_PATH_1)/keymap.c - KEYMAP_PATH := $(MAIN_KEYMAP_PATH_1) -else ifneq ("$(wildcard $(MAIN_KEYMAP_PATH_2)/keymap.c)","") - -include $(MAIN_KEYMAP_PATH_2)/rules.mk - KEYMAP_C := $(MAIN_KEYMAP_PATH_2)/keymap.c - KEYMAP_PATH := $(MAIN_KEYMAP_PATH_2) -else ifneq ("$(wildcard $(MAIN_KEYMAP_PATH_3)/keymap.c)","") - -include $(MAIN_KEYMAP_PATH_3)/rules.mk - KEYMAP_C := $(MAIN_KEYMAP_PATH_3)/keymap.c - KEYMAP_PATH := $(MAIN_KEYMAP_PATH_3) -else ifneq ("$(wildcard $(MAIN_KEYMAP_PATH_4)/keymap.c)","") - -include $(MAIN_KEYMAP_PATH_4)/rules.mk - KEYMAP_C := $(MAIN_KEYMAP_PATH_4)/keymap.c - KEYMAP_PATH := $(MAIN_KEYMAP_PATH_4) -else ifneq ("$(wildcard $(MAIN_KEYMAP_PATH_5)/keymap.c)","") - -include $(MAIN_KEYMAP_PATH_5)/rules.mk - KEYMAP_C := $(MAIN_KEYMAP_PATH_5)/keymap.c - KEYMAP_PATH := $(MAIN_KEYMAP_PATH_5) -else ifneq ($(LAYOUTS),) - # If we haven't found a keymap yet fall back to community layouts - include $(BUILDDEFS_PATH)/build_layout.mk -# Not finding keymap.c is fine if we found a keymap.json -else ifeq ("$(wildcard $(KEYMAP_JSON_PATH))", "") - $(call CATASTROPHIC_ERROR,Invalid keymap,Could not find keymap) - # this state should never be reached +ifeq ("$(wildcard $(KEYMAP_PATH))", "") + # Look through the possible keymap folders until we find a matching keymap.c + ifneq ($(QMK_USERSPACE),) + ifneq ("$(wildcard $(QMK_USERSPACE)/$(MAIN_KEYMAP_PATH_1)/keymap.c)","") + -include $(QMK_USERSPACE)/$(MAIN_KEYMAP_PATH_1)/rules.mk + KEYMAP_C := $(QMK_USERSPACE)/$(MAIN_KEYMAP_PATH_1)/keymap.c + KEYMAP_PATH := $(QMK_USERSPACE)/$(MAIN_KEYMAP_PATH_1) + else ifneq ("$(wildcard $(QMK_USERSPACE)/$(MAIN_KEYMAP_PATH_2)/keymap.c)","") + -include $(QMK_USERSPACE)/$(MAIN_KEYMAP_PATH_2)/rules.mk + KEYMAP_C := $(QMK_USERSPACE)/$(MAIN_KEYMAP_PATH_2)/keymap.c + KEYMAP_PATH := $(QMK_USERSPACE)/$(MAIN_KEYMAP_PATH_2) + else ifneq ("$(wildcard $(QMK_USERSPACE)/$(MAIN_KEYMAP_PATH_3)/keymap.c)","") + -include $(QMK_USERSPACE)/$(MAIN_KEYMAP_PATH_3)/rules.mk + KEYMAP_C := $(QMK_USERSPACE)/$(MAIN_KEYMAP_PATH_3)/keymap.c + KEYMAP_PATH := $(QMK_USERSPACE)/$(MAIN_KEYMAP_PATH_3) + else ifneq ("$(wildcard $(QMK_USERSPACE)/$(MAIN_KEYMAP_PATH_4)/keymap.c)","") + -include $(QMK_USERSPACE)/$(MAIN_KEYMAP_PATH_4)/rules.mk + KEYMAP_C := $(QMK_USERSPACE)/$(MAIN_KEYMAP_PATH_4)/keymap.c + KEYMAP_PATH := $(QMK_USERSPACE)/$(MAIN_KEYMAP_PATH_4) + else ifneq ("$(wildcard $(QMK_USERSPACE)/$(MAIN_KEYMAP_PATH_5)/keymap.c)","") + -include $(QMK_USERSPACE)/$(MAIN_KEYMAP_PATH_5)/rules.mk + KEYMAP_C := $(QMK_USERSPACE)/$(MAIN_KEYMAP_PATH_5)/keymap.c + KEYMAP_PATH := $(QMK_USERSPACE)/$(MAIN_KEYMAP_PATH_5) + endif + endif + ifeq ($(KEYMAP_PATH),) + ifneq ("$(wildcard $(MAIN_KEYMAP_PATH_1)/keymap.c)","") + -include $(MAIN_KEYMAP_PATH_1)/rules.mk + KEYMAP_C := $(MAIN_KEYMAP_PATH_1)/keymap.c + KEYMAP_PATH := $(MAIN_KEYMAP_PATH_1) + else ifneq ("$(wildcard $(MAIN_KEYMAP_PATH_2)/keymap.c)","") + -include $(MAIN_KEYMAP_PATH_2)/rules.mk + KEYMAP_C := $(MAIN_KEYMAP_PATH_2)/keymap.c + KEYMAP_PATH := $(MAIN_KEYMAP_PATH_2) + else ifneq ("$(wildcard $(MAIN_KEYMAP_PATH_3)/keymap.c)","") + -include $(MAIN_KEYMAP_PATH_3)/rules.mk + KEYMAP_C := $(MAIN_KEYMAP_PATH_3)/keymap.c + KEYMAP_PATH := $(MAIN_KEYMAP_PATH_3) + else ifneq ("$(wildcard $(MAIN_KEYMAP_PATH_4)/keymap.c)","") + -include $(MAIN_KEYMAP_PATH_4)/rules.mk + KEYMAP_C := $(MAIN_KEYMAP_PATH_4)/keymap.c + KEYMAP_PATH := $(MAIN_KEYMAP_PATH_4) + else ifneq ("$(wildcard $(MAIN_KEYMAP_PATH_5)/keymap.c)","") + -include $(MAIN_KEYMAP_PATH_5)/rules.mk + KEYMAP_C := $(MAIN_KEYMAP_PATH_5)/keymap.c + KEYMAP_PATH := $(MAIN_KEYMAP_PATH_5) + else ifneq ($(LAYOUTS),) + # If we haven't found a keymap yet fall back to community layouts + include $(BUILDDEFS_PATH)/build_layout.mk + else ifeq ("$(wildcard $(KEYMAP_JSON_PATH))", "") # Not finding keymap.c is fine if we found a keymap.json + $(call CATASTROPHIC_ERROR,Invalid keymap,Could not find keymap) + # this state should never be reached + endif + endif endif # Have we found a keymap.json? @@ -364,6 +390,16 @@ ifeq ("$(USER_NAME)","") endif USER_PATH := users/$(USER_NAME) +# If we have userspace, then add it to the lookup VPATH +ifneq ($(wildcard $(QMK_USERSPACE)),) + VPATH += $(QMK_USERSPACE) +endif + +# If the equivalent users directory exists in userspace, use that in preference to anything currently in the main repo +ifneq ($(wildcard $(QMK_USERSPACE)/$(USER_PATH)),) + USER_PATH := $(QMK_USERSPACE)/$(USER_PATH) +endif + # Pull in user level rules.mk -include $(USER_PATH)/rules.mk ifneq ("$(wildcard $(USER_PATH)/config.h)","") @@ -404,6 +440,10 @@ ifneq ("$(KEYMAP_H)","") CONFIG_H += $(KEYMAP_H) endif +ifeq ($(KEYMAP_C),) + $(call CATASTROPHIC_ERROR,Invalid keymap,Could not find keymap) +endif + OPT_DEFS += -DKEYMAP_C=\"$(KEYMAP_C)\" # If a keymap or userspace places their keymap array in another file instead, allow for it to be included diff --git a/builddefs/build_layout.mk b/builddefs/build_layout.mk index 6166bd847c..9ff99cc221 100644 --- a/builddefs/build_layout.mk +++ b/builddefs/build_layout.mk @@ -1,6 +1,10 @@ LAYOUTS_PATH := layouts LAYOUTS_REPOS := $(patsubst %/,%,$(sort $(dir $(wildcard $(LAYOUTS_PATH)/*/)))) +ifneq ($(QMK_USERSPACE),) + LAYOUTS_REPOS += $(patsubst %/,%,$(QMK_USERSPACE)/$(LAYOUTS_PATH)) +endif + define SEARCH_LAYOUTS_REPO LAYOUT_KEYMAP_PATH := $$(LAYOUTS_REPO)/$$(LAYOUT)/$$(KEYMAP) LAYOUT_KEYMAP_JSON := $$(LAYOUT_KEYMAP_PATH)/keymap.json diff --git a/builddefs/common_rules.mk b/builddefs/common_rules.mk index 52dccbe475..cfd261737c 100644 --- a/builddefs/common_rules.mk +++ b/builddefs/common_rules.mk @@ -191,7 +191,7 @@ DFU_SUFFIX_ARGS ?= elf: $(BUILD_DIR)/$(TARGET).elf hex: $(BUILD_DIR)/$(TARGET).hex uf2: $(BUILD_DIR)/$(TARGET).uf2 -cpfirmware: $(FIRMWARE_FORMAT) +cpfirmware_qmk: $(FIRMWARE_FORMAT) $(SILENT) || printf "Copying $(TARGET).$(FIRMWARE_FORMAT) to qmk_firmware folder" | $(AWK_CMD) $(COPY) $(BUILD_DIR)/$(TARGET).$(FIRMWARE_FORMAT) $(TARGET).$(FIRMWARE_FORMAT) && $(PRINT_OK) eep: $(BUILD_DIR)/$(TARGET).eep @@ -200,6 +200,15 @@ sym: $(BUILD_DIR)/$(TARGET).sym LIBNAME=lib$(TARGET).a lib: $(LIBNAME) +cpfirmware: cpfirmware_qmk + +ifneq ($(QMK_USERSPACE),) +cpfirmware: cpfirmware_userspace +cpfirmware_userspace: cpfirmware_qmk + $(SILENT) || printf "Copying $(TARGET).$(FIRMWARE_FORMAT) to userspace folder" | $(AWK_CMD) + $(COPY) $(BUILD_DIR)/$(TARGET).$(FIRMWARE_FORMAT) $(QMK_USERSPACE)/$(TARGET).$(FIRMWARE_FORMAT) && $(PRINT_OK) +endif + # Display size of file, modifying the output so people don't mistakenly grab the hex output BINARY_SIZE = $(SIZE) --target=$(FORMAT) $(BUILD_DIR)/$(TARGET).hex | $(SED) -e 's/\.build\/.*$$/$(TARGET).$(FIRMWARE_FORMAT)/g' |