Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically include build.mk after rules.mk. #2046

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,13 @@ define PARSE_RULE
endif
endef

# different from the common.mk version because this needs extra $ because
# it's used in PARSE_KEYBOARD which is already really magic
define USE_RULES
$$(if $$(filter $(1),$$(RULES_MK_LIST)),,$$(eval RULES_MK_LIST += $(1)))\
$$(eval include $(1))
endef

# $1 = Keyboard
# Parses a rule in the format <keymap>:<target>
# the keyboard is already known when entering this function
Expand All @@ -301,9 +308,9 @@ define PARSE_KEYBOARD
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)
$(call USE_RULES,$(ROOT_DIR)/keyboards/$$(CURRENT_KB)/rules.mk)
ifneq ($$(DEFAULT_FOLDER),$$(CURRENT_KB))
$$(eval include $(ROOT_DIR)/keyboards/$$(DEFAULT_FOLDER)/rules.mk)
$(call USE_RULES,$(ROOT_DIR)/keyboards/$$(DEFAULT_FOLDER)/rules.mk)
endif
CURRENT_KB := $$(DEFAULT_FOLDER)

Expand All @@ -328,27 +335,27 @@ define PARSE_KEYBOARD
KEYBOARD_LAYOUTS :=
ifneq ("$$(wildcard $(ROOT_DIR)/keyboards/$$(KEYBOARD_FOLDER_PATH_5)/rules.mk)","")
LAYOUTS :=
$$(eval include $(ROOT_DIR)/keyboards/$$(KEYBOARD_FOLDER_PATH_5)/rules.mk)
$(call USE_RULES,$(ROOT_DIR)/keyboards/$$(KEYBOARD_FOLDER_PATH_5)/rules.mk)
KEYBOARD_LAYOUTS := $$(sort $$(LAYOUTS) $$(KEYBOARD_LAYOUTS))
endif
ifneq ("$$(wildcard $(ROOT_DIR)/keyboards/$$(KEYBOARD_FOLDER_PATH_4)/rules.mk)","")
LAYOUTS :=
$$(eval include $(ROOT_DIR)/keyboards/$$(KEYBOARD_FOLDER_PATH_4)/rules.mk)
$(call USE_RULES,$(ROOT_DIR)/keyboards/$$(KEYBOARD_FOLDER_PATH_4)/rules.mk)
KEYBOARD_LAYOUTS := $$(sort $$(LAYOUTS) $$(KEYBOARD_LAYOUTS))
endif
ifneq ("$$(wildcard $(ROOT_DIR)/keyboards/$$(KEYBOARD_FOLDER_PATH_3)/rules.mk)","")
LAYOUTS :=
$$(eval include $(ROOT_DIR)/keyboards/$$(KEYBOARD_FOLDER_PATH_3)/rules.mk)
$(call USE_RULES,$(ROOT_DIR)/keyboards/$$(KEYBOARD_FOLDER_PATH_3)/rules.mk)
KEYBOARD_LAYOUTS := $$(sort $$(LAYOUTS) $$(KEYBOARD_LAYOUTS))
endif
ifneq ("$$(wildcard $(ROOT_DIR)/keyboards/$$(KEYBOARD_FOLDER_PATH_2)/rules.mk)","")
LAYOUTS :=
$$(eval include $(ROOT_DIR)/keyboards/$$(KEYBOARD_FOLDER_PATH_2)/rules.mk)
$(call USE_RULES,$(ROOT_DIR)/keyboards/$$(KEYBOARD_FOLDER_PATH_2)/rules.mk)
KEYBOARD_LAYOUTS := $$(sort $$(LAYOUTS) $$(KEYBOARD_LAYOUTS))
endif
ifneq ("$$(wildcard $(ROOT_DIR)/keyboards/$$(KEYBOARD_FOLDER_PATH_1)/rules.mk)","")
LAYOUTS :=
$$(eval include $(ROOT_DIR)/keyboards/$$(KEYBOARD_FOLDER_PATH_1)/rules.mk)
$(call USE_RULES,$(ROOT_DIR)/keyboards/$$(KEYBOARD_FOLDER_PATH_1)/rules.mk)
KEYBOARD_LAYOUTS := $$(sort $$(LAYOUTS) $$(KEYBOARD_LAYOUTS))
endif

Expand All @@ -357,6 +364,8 @@ define PARSE_KEYBOARD

KEYMAPS := $$(sort $$(KEYMAPS) $$(LAYOUT_KEYMAPS))

$$(eval include $$(foreach RULES_MK,$$(RULES_MK_LIST),$$(wildcard $$(subst rules.mk,build.mk,$$(RULES_MK)))))

# 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),)
Expand Down
13 changes: 7 additions & 6 deletions build_keyboard.mk
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,19 @@ endif

# Pull in rules.mk files from all our subfolders
ifneq ("$(wildcard $(KEYBOARD_PATH_5)/rules.mk)","")
include $(KEYBOARD_PATH_5)/rules.mk
$(call USE_RULES,$(KEYBOARD_PATH_5)/rules.mk)
endif
ifneq ("$(wildcard $(KEYBOARD_PATH_4)/rules.mk)","")
include $(KEYBOARD_PATH_4)/rules.mk
$(call USE_RULES,$(KEYBOARD_PATH_4)/rules.mk)
endif
ifneq ("$(wildcard $(KEYBOARD_PATH_3)/rules.mk)","")
include $(KEYBOARD_PATH_3)/rules.mk
$(call USE_RULES,$(KEYBOARD_PATH_3)/rules.mk)
endif
ifneq ("$(wildcard $(KEYBOARD_PATH_2)/rules.mk)","")
include $(KEYBOARD_PATH_2)/rules.mk
$(call USE_RULES,$(KEYBOARD_PATH_2)/rules.mk)
endif
ifneq ("$(wildcard $(KEYBOARD_PATH_1)/rules.mk)","")
include $(KEYBOARD_PATH_1)/rules.mk
$(call USE_RULES,$(KEYBOARD_PATH_1)/rules.mk)
endif


Expand Down Expand Up @@ -315,7 +315,8 @@ ifeq ("$(USER_NAME)","")
endif
USER_PATH := users/$(USER_NAME)

-include $(USER_PATH)/rules.mk
$(call USE_RULES,$(USER_PATH)/rules.mk,-)
$(eval include $(foreach RULES_MK,$(RULES_MK_LIST),$(wildcard $(subst rules.mk,build.mk,$(RULES_MK)))))
ifneq ("$(wildcard $(USER_PATH)/config.h)","")
CONFIG_H += $(USER_PATH)/config.h
endif
Expand Down
5 changes: 5 additions & 0 deletions common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,8 @@ COMMON_VPATH += $(QUANTUM_PATH)/audio
COMMON_VPATH += $(QUANTUM_PATH)/process_keycode
COMMON_VPATH += $(QUANTUM_PATH)/api
COMMON_VPATH += $(DRIVER_PATH)

define USE_RULES
$(if $(filter $(1),$(RULES_MK_LIST)),,$(eval RULES_MK_LIST += $(1)))\
$(eval $(2)include $(1))
endef
3 changes: 3 additions & 0 deletions keyboards/ergodox_ez/build.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ifeq ($(strip $(RGB_MATRIX_ENABLE)), no)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change isn't actually necessary anymore.

i2c is added via QUANTUM_LIB_SRC which has some special handling that prevents conflicts with it being added multiple times (also, prevents LTO from being applied to it, as it can cause weird timing related issues)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, neat. that would indeed resolve this part. i'm not sure it also resolves the corresponding issue with the other optional modules, added in the later patch, though?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. There are still a number of use cases that would make this very useful still. Such as per-keyboard features/options, that can be adjusted by the keymaps. As well as by userspace, in general.

SRC += i2c_master.c
endif
1 change: 1 addition & 0 deletions keyboards/ergodox_ez/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ SLEEP_LED_ENABLE = no
API_SYSEX_ENABLE = no
RGBLIGHT_ENABLE = yes
RGB_MATRIX_ENABLE = no # enable later

DEBOUNCE_TYPE = eager_pr

LAYOUTS = ergodox