From fa06a163607e8c6c4bd0968c2de96a9a298b777c Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Sat, 13 Aug 2016 10:46:38 +0200 Subject: process_unicode: Add a way to enter unicode symbols by name The purpose of this change is to allow keymaps to specify a dictionary of unicode symbol name to code mappings, and let the person at the keyboard enter unicode symbols by name. This is done by having a way to trigger unicode symbol input mode, when all keys are cached until Esc, Enter or Space are pressed. Once that happens, we try to look up the symbol from our lookup table. If found, we erase back, and type the unicode magic in to get that symbol. If not found, we still erase back, start unicode input mode, and replay what the user typed in. Signed-off-by: Gergely Nagy --- Makefile | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 053c8532af..693edc9f06 100644 --- a/Makefile +++ b/Makefile @@ -198,6 +198,11 @@ ifeq ($(strip $(AUDIO_ENABLE)), yes) SRC += $(QUANTUM_DIR)/audio/luts.c endif +ifeq ($(strip $(UCIS_ENABLE)), yes) + OPT_DEFS += -DUCIS_ENABLE + UNICODE_ENABLE = yes +endif + ifeq ($(strip $(UNICODE_ENABLE)), yes) OPT_DEFS += -DUNICODE_ENABLE SRC += $(QUANTUM_DIR)/process_keycode/process_unicode.c @@ -273,4 +278,4 @@ BUILD_DATE := $(shell date +"%Y-%m-%d-%H:%M:%S") OPT_DEFS += -DQMK_KEYBOARD=\"$(KEYBOARD)\" -DQMK_KEYMAP=\"$(KEYMAP)\" $(shell echo '#define QMK_VERSION "$(GIT_VERSION)"' > $(QUANTUM_PATH)/version.h) -$(shell echo '#define QMK_BUILDDATE "$(BUILD_DATE)"' >> $(QUANTUM_PATH)/version.h) \ No newline at end of file +$(shell echo '#define QMK_BUILDDATE "$(BUILD_DATE)"' >> $(QUANTUM_PATH)/version.h) -- cgit v1.2.3 From 86706de036cf7ad52b679b259ca8f980057d0da5 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Mon, 1 Aug 2016 09:23:37 +0300 Subject: Parsing of makefile variables from starting dir --- Makefile | 322 ++++++++------------------------------------------------------- 1 file changed, 41 insertions(+), 281 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 693edc9f06..fcd57754b5 100644 --- a/Makefile +++ b/Makefile @@ -1,281 +1,41 @@ -ifndef VERBOSE -.SILENT: -endif - -.DEFAULT_GOAL := all - -space := $(subst ,, ) -ESCAPED_ABS_PATH = $(subst $(space),_SPACE_,$(abspath $1)) -starting_makefile := $(call ESCAPED_ABS_PATH,$(firstword $(MAKEFILE_LIST))) -mkfile_path := $(call ESCAPED_ABS_PATH,$(lastword $(MAKEFILE_LIST)))) -abs_tmk_root := $(patsubst %/,%,$(dir $(mkfile_path))) - -ifneq (,$(findstring /keyboards/,$(starting_makefile))) - possible_keyboard:=$(patsubst %/,%,$(dir $(patsubst $(abs_tmk_root)/keyboards/%,%,$(starting_makefile)))) - ifneq (,$(findstring /keymaps/,$(possible_keyboard))) - KEYMAP_DIR:=$(lastword $(subst /keymaps/, ,$(possible_keyboard))) - KEYBOARD_DIR:=$(firstword $(subst /keymaps/, ,$(possible_keyboard))) - ifneq (,$(findstring /,$(KEYBOARD_DIR))) - # SUBPROJECT_DIR:=$(lastword $(subst /, ,$(KEYBOARD_DIR))) - # KEYBOARD_DIR:=$(firstword $(subst /, ,$(KEYBOARD_DIR))) - tmk_root = ../../.. - else - tmk_root = ../../../.. - endif - else - KEYMAP_DIR:=default - KEYBOARD_DIR:=$(possible_keyboard) - ifneq (,$(findstring /,$(KEYBOARD_DIR))) - # SUBPROJECT_DIR:=$(lastword $(subst /, ,$(KEYBOARD_DIR))) - # KEYBOARD_DIR:=$(firstword $(subst /, ,$(KEYBOARD_DIR))) - tmk_root = ../../.. - else - tmk_root = ../.. - endif - endif -else - tmk_root = . -endif -# $(info $(KEYBOARD_DIR)) -# $(info $(KEYMAP_DIR)) -# $(info $(SUBPROJECT_DIR)) - -# Directory common source filess exist -TOP_DIR = $(tmk_root) -TMK_DIR = tmk_core -TMK_PATH = $(TOP_DIR)/$(TMK_DIR) -LIB_PATH = $(TOP_DIR)/lib - -QUANTUM_DIR = quantum -QUANTUM_PATH = $(TOP_DIR)/$(QUANTUM_DIR) - - -ifdef keyboard - KEYBOARD ?= $(keyboard) -endif -ifdef KEYBOARD_DIR - KEYBOARD ?= $(KEYBOARD_DIR) -endif -ifndef KEYBOARD - KEYBOARD=planck -endif - -MASTER ?= left -ifdef master - MASTER = $(master) -endif - - -# converts things to keyboards/subproject -ifneq (,$(findstring /,$(KEYBOARD))) - TEMP:=$(KEYBOARD) - KEYBOARD:=$(firstword $(subst /, ,$(TEMP))) - SUBPROJECT:=$(lastword $(subst /, ,$(TEMP))) -endif - -KEYBOARD_PATH = $(TOP_DIR)/keyboards/$(KEYBOARD) - -ifdef sub - SUBPROJECT=$(sub) -endif -ifdef subproject - SUBPROJECT=$(subproject) -endif - -ifneq ("$(wildcard $(KEYBOARD_PATH)/$(KEYBOARD).c)","") - KEYBOARD_FILE = keyboards/$(KEYBOARD)/$(KEYBOARD).c - ifneq ($(call ESCAPED_ABS_PATH,$(KEYBOARD_PATH)/Makefile),$(starting_makefile)) - -include $(KEYBOARD_PATH)/Makefile - endif -else -$(error "$(KEYBOARD_PATH)/$(KEYBOARD).c" does not exist) -endif - -ifdef SUBPROJECT_DEFAULT - SUBPROJECT?=$(SUBPROJECT_DEFAULT) -endif - -ifdef SUBPROJECT - SUBPROJECT_PATH = $(TOP_DIR)/keyboards/$(KEYBOARD)/$(SUBPROJECT) - ifneq ("$(wildcard $(SUBPROJECT_PATH)/$(SUBPROJECT).c)","") - OPT_DEFS += -DSUBPROJECT_$(SUBPROJECT) - SUBPROJECT_FILE = keyboards/$(KEYBOARD)/$(SUBPROJECT)/$(SUBPROJECT).c - ifneq ($(call ESCAPED_ABS_PATH,$(SUBPROJECT_PATH)/Makefile),$(starting_makefile)) - -include $(SUBPROJECT_PATH)/Makefile - endif - else -$(error "$(SUBPROJECT_PATH)/$(SUBPROJECT).c" does not exist) - endif -endif - -ifdef keymap - KEYMAP ?= $(keymap) -endif -ifdef KEYMAP_DIR - KEYMAP ?= $(KEYMAP_DIR) -endif -ifndef KEYMAP - KEYMAP = default -endif -KEYMAP_PATH = $(KEYBOARD_PATH)/keymaps/$(KEYMAP) -ifneq ("$(wildcard $(KEYMAP_PATH)/keymap.c)","") - KEYMAP_FILE = keyboards/$(KEYBOARD)/keymaps/$(KEYMAP)/keymap.c - ifneq ($(call ESCAPED_ABS_PATH,$(KEYMAP_PATH)/Makefile),$(starting_makefile)) - -include $(KEYMAP_PATH)/Makefile - endif -else - ifeq ("$(wildcard $(SUBPROJECT_PATH)/keymaps/$(KEYMAP)/keymap.c)","") -$(error "$(KEYMAP_PATH)/keymap.c" does not exist) - else - KEYMAP_PATH = $(SUBPROJECT_PATH)/keymaps/$(KEYMAP) - KEYMAP_FILE = keyboards/$(KEYBOARD)/$(SUBPROJECT)/keymaps/$(KEYMAP)/keymap.c - ifneq ($(call ESCAPED_ABS_PATH,$(KEYMAP_PATH)/Makefile),$(starting_makefile)) - -include $(KEYMAP_PATH)/Makefile - endif - endif -endif - -ifdef SUBPROJECT - TARGET ?= $(KEYBOARD)_$(SUBPROJECT)_$(KEYMAP) -else - TARGET ?= $(KEYBOARD)_$(KEYMAP) -endif - -BUILD_DIR = $(TOP_DIR)/.build - -# Object files directory -# To put object files in current directory, use a dot (.), do NOT make -# this an empty or blank macro! -OBJDIR = $(BUILD_DIR)/obj_$(TARGET) - - - -ifneq ("$(wildcard $(KEYMAP_PATH)/config.h)","") - CONFIG_H = $(KEYMAP_PATH)/config.h -else - CONFIG_H = $(KEYBOARD_PATH)/config.h - ifdef SUBPROJECT - ifneq ("$(wildcard $(SUBPROJECT_PATH)/$(SUBPROJECT).c)","") - CONFIG_H = $(SUBPROJECT_PATH)/config.h - endif - endif -endif - -# # project specific files -SRC += $(KEYBOARD_FILE) \ - $(KEYMAP_FILE) \ - $(QUANTUM_DIR)/quantum.c \ - $(QUANTUM_DIR)/keymap_common.c \ - $(QUANTUM_DIR)/keycode_config.c \ - $(QUANTUM_DIR)/process_keycode/process_leader.c - -ifdef SUBPROJECT - SRC += $(SUBPROJECT_FILE) -endif - -ifdef SUBPROJECT - SRC += $(SUBPROJECT_FILE) -endif - -ifdef SUBPROJECT - SRC += $(SUBPROJECT_FILE) -endif - -ifndef CUSTOM_MATRIX - SRC += $(QUANTUM_DIR)/matrix.c -endif - -ifeq ($(strip $(MIDI_ENABLE)), yes) - OPT_DEFS += -DMIDI_ENABLE - SRC += $(QUANTUM_DIR)/process_keycode/process_midi.c -endif - -ifeq ($(strip $(AUDIO_ENABLE)), yes) - OPT_DEFS += -DAUDIO_ENABLE - SRC += $(QUANTUM_DIR)/process_keycode/process_music.c - SRC += $(QUANTUM_DIR)/audio/audio.c - SRC += $(QUANTUM_DIR)/audio/voices.c - SRC += $(QUANTUM_DIR)/audio/luts.c -endif - -ifeq ($(strip $(UCIS_ENABLE)), yes) - OPT_DEFS += -DUCIS_ENABLE - UNICODE_ENABLE = yes -endif - -ifeq ($(strip $(UNICODE_ENABLE)), yes) - OPT_DEFS += -DUNICODE_ENABLE - SRC += $(QUANTUM_DIR)/process_keycode/process_unicode.c -endif - -ifeq ($(strip $(RGBLIGHT_ENABLE)), yes) - OPT_DEFS += -DRGBLIGHT_ENABLE - SRC += $(QUANTUM_DIR)/light_ws2812.c - SRC += $(QUANTUM_DIR)/rgblight.c -endif - -ifeq ($(strip $(TAP_DANCE_ENABLE)), yes) - OPT_DEFS += -DTAP_DANCE_ENABLE - SRC += $(QUANTUM_DIR)/process_keycode/process_tap_dance.c -endif - -ifeq ($(strip $(SERIAL_LINK_ENABLE)), yes) - SERIAL_DIR = $(QUANTUM_DIR)/serial_link - SERIAL_PATH = $(QUANTUM_PATH)/serial_link - SERIAL_SRC = $(wildcard $(SERIAL_PATH)/protocol/*.c) - SERIAL_SRC += $(wildcard $(SERIAL_PATH)/system/*.c) - SRC += $(patsubst $(QUANTUM_PATH)/%,%,$(SERIAL_SRC)) - OPT_DEFS += -DSERIAL_LINK_ENABLE - VAPTH += $(SERIAL_PATH) -endif - -# Optimize size but this may cause error "relocation truncated to fit" -#EXTRALDFLAGS = -Wl,--relax - -# Search Path -VPATH += $(KEYMAP_PATH) -ifdef SUBPROJECT - VPATH += $(SUBPROJECT_PATH) -endif -VPATH += $(KEYBOARD_PATH) -VPATH += $(TOP_DIR) -VPATH += $(TMK_PATH) -VPATH += $(QUANTUM_PATH) -VPATH += $(QUANTUM_PATH)/keymap_extras -VPATH += $(QUANTUM_PATH)/audio -VPATH += $(QUANTUM_PATH)/process_keycode - - -# We can assume a ChibiOS target When MCU_FAMILY is defined, since it's not used for LUFA -ifdef MCU_FAMILY - PLATFORM=CHIBIOS -else - PLATFORM=AVR -endif - -include $(TMK_PATH)/common.mk -ifeq ($(PLATFORM),AVR) - include $(TMK_PATH)/protocol/lufa.mk - include $(TMK_PATH)/avr.mk -else ifeq ($(PLATFORM),CHIBIOS) - include $(TMK_PATH)/protocol/chibios.mk - include $(TMK_PATH)/chibios.mk - OPT_OS = chibios -else - $(error Unknown platform) -endif - -ifeq ($(strip $(VISUALIZER_ENABLE)), yes) - VISUALIZER_DIR = $(QUANTUM_DIR)/visualizer - VISUALIZER_PATH = $(QUANTUM_PATH)/visualizer - include $(VISUALIZER_PATH)/visualizer.mk -endif - -include $(TMK_PATH)/rules.mk - -GIT_VERSION := $(shell git describe --abbrev=6 --dirty --always --tags 2>/dev/null || date +"%Y-%m-%d-%H:%M:%S") -BUILD_DATE := $(shell date +"%Y-%m-%d-%H:%M:%S") -OPT_DEFS += -DQMK_KEYBOARD=\"$(KEYBOARD)\" -DQMK_KEYMAP=\"$(KEYMAP)\" - -$(shell echo '#define QMK_VERSION "$(GIT_VERSION)"' > $(QUANTUM_PATH)/version.h) -$(shell echo '#define QMK_BUILDDATE "$(BUILD_DATE)"' >> $(QUANTUM_PATH)/version.h) +STARTING_MAKEFILE := $(firstword $(MAKEFILE_LIST)) +ROOT_MAKEFILE := $(lastword $(MAKEFILE_LIST)) +ABS_STARTING_MAKEFILE := $(abspath $(STARTING_MAKEFILE)) +ABS_ROOT_MAKEFILE := $(abspath $(ROOT_MAKEFILE)) +ABS_STARTING_DIR := $(dir $(ABS_STARTING_MAKEFILE)) +ABS_ROOT_DIR := $(dir $(ABS_ROOT_MAKEFILE)) +STARTING_DIR := $(subst $(ABS_ROOT_DIR),,$(ABS_STARTING_DIR)) + +PATH_ELEMENTS := $(subst /, ,$(STARTING_DIR)) + +define NEXT_PATH_ELEMENT + $$(eval CURRENT_PATH_ELEMENT := $$(firstword $$(PATH_ELEMENTS))) + $$(eval PATH_ELEMENTS := $$(wordlist 2,9999,$$(PATH_ELEMENTS))) +endef + +$(eval $(call NEXT_PATH_ELEMENT)) + +ifeq ($(CURRENT_PATH_ELEMENT),keyboards) + $(eval $(call NEXT_PATH_ELEMENT)) + KEYBOARD := $(CURRENT_PATH_ELEMENT) + $(eval $(call NEXT_PATH_ELEMENT)) + ifeq ($(CURRENT_PATH_ELEMENT),keymaps) + $(eval $(call NEXT_PATH_ELEMENT)) + KEYMAP := $(CURRENT_PATH_ELEMENT) + else ifneq ($(CURRENT_PATH_ELEMENT),) + SUBPROJECT := $(CURRENT_PATH_ELEMENT) + $(eval $(call NEXT_PATH_ELEMENT)) + ifeq ($(CURRENT_PATH_ELEMENT),keymaps) + $(eval $(call NEXT_PATH_ELEMENT)) + KEYMAP := $(CURRENT_PATH_ELEMENT) + endif + endif +endif + +$(info Keyboard: $(KEYBOARD)) +$(info Keymap: $(KEYMAP)) +$(info Subproject: $(SUBPROJECT)) + + +all: + echo "Compiling" \ No newline at end of file -- cgit v1.2.3 From e6e675335dbaa6bd175be7aaee829c717e572488 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Wed, 3 Aug 2016 08:44:11 +0300 Subject: First version of rule parsing Only handles allkb at the moment. --- Makefile | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'Makefile') diff --git a/Makefile b/Makefile index fcd57754b5..f0d5c05ccc 100644 --- a/Makefile +++ b/Makefile @@ -36,6 +36,54 @@ $(info Keyboard: $(KEYBOARD)) $(info Keymap: $(KEYMAP)) $(info Subproject: $(SUBPROJECT)) +# Compare the start of the RULE_VARIABLE with the first argument($1) +# If the rules equals $1 or starts with $1-, RULE_FOUND is set to true +# and $1 is removed from the RULE variable +# 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 + ifeq ($1,$$(RULE)) + RULE:= + RULE_FOUND := true + else + STARTDASH_REMOVED=$$(subst START$1-,,START$$(RULE)) + ifneq ($$(STARTDASH_REMOVED),START$$(RULE)) + RULE_FOUND := true + RULE := $$(STARTDASH_REMOVED) + else + RULE_FOUND := false + endif + endif +endef + +define PARSE_ALL_KEYBOARDS + COMMANDS += allkb + #$$(info $$(RULE)) + COMMAND_allkb := "All keyboards with $$(RULE)" +endef + +define PARSE_RULE + RULE := $1 + COMMANDS := + $$(eval $$(call COMPARE_AND_REMOVE_FROM_RULE,allkb)) + ifeq ($$(RULE_FOUND),true) + $$(eval $$(call PARSE_ALL_KEYBOARDS)) + endif +endef + +RUN_COMMAND = echo "Running": $(COMMAND_$(COMMAND)); + +.PHONY: % +%: + $(eval $(call PARSE_RULE,$@)) + $(foreach COMMAND,$(COMMANDS),$(RUN_COMMAND)) + +.PHONY: all-keyboards +all-keyboards: allkb + +.PHONY: all-keyboards-defaults +all-keyboards-defaults: allkb-default-default +.PHONY: all all: echo "Compiling" \ No newline at end of file -- cgit v1.2.3 From f97ae2b199df087f4b48c7019c2d887089d81614 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Wed, 3 Aug 2016 09:28:47 +0300 Subject: Rule parsing to match kebyoards --- Makefile | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'Makefile') diff --git a/Makefile b/Makefile index f0d5c05ccc..b24270ad1b 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,9 @@ STARTING_MAKEFILE := $(firstword $(MAKEFILE_LIST)) ROOT_MAKEFILE := $(lastword $(MAKEFILE_LIST)) +ROOT_DIR := $(dir, $(ROOT_MAKEFILE)) +ifeq ($(ROOT_DIR),) + ROOT_DIR := . +endif ABS_STARTING_MAKEFILE := $(abspath $(STARTING_MAKEFILE)) ABS_ROOT_MAKEFILE := $(abspath $(ROOT_MAKEFILE)) ABS_STARTING_DIR := $(dir $(ABS_STARTING_MAKEFILE)) @@ -32,9 +36,14 @@ ifeq ($(CURRENT_PATH_ELEMENT),keyboards) endif endif +$(info $(ROOT_DIR)/keyboards) +KEYBOARDS := $(notdir $(patsubst %/.,%,$(wildcard $(ROOT_DIR)/keyboards/*/.))) + $(info Keyboard: $(KEYBOARD)) $(info Keymap: $(KEYMAP)) $(info Subproject: $(SUBPROJECT)) +$(info Keyboards: $(KEYBOARDS)) + # Compare the start of the RULE_VARIABLE with the first argument($1) # If the rules equals $1 or starts with $1-, RULE_FOUND is set to true @@ -62,12 +71,34 @@ define PARSE_ALL_KEYBOARDS COMMAND_allkb := "All keyboards with $$(RULE)" endef +define PARSE_KEYBOARD + COMMANDS += $1 + #$$(info $$(RULE)) + COMMAND_$1 := "Keyboard $1 with $$(RULE)" +endef + + +# Recursively try to find a matching keyboard +# During the first call $1 contains a list of all keyboards +# One keyboard is checked and removed at a time +define TRY_PARSE_KEYBOARD + CURRENT_KB := $$(firstword $1) + $$(eval $$(call COMPARE_AND_REMOVE_FROM_RULE,$$(CURRENT_KB))) + ifeq ($$(RULE_FOUND),true) + $$(eval $$(call PARSE_KEYBOARD,$$(CURRENT_KB))) + else ifneq ($1,) + $$(eval $$(call TRY_PARSE_KEYBOARD,$$(wordlist 2,9999,$1))) + endif +endef + define PARSE_RULE RULE := $1 COMMANDS := $$(eval $$(call COMPARE_AND_REMOVE_FROM_RULE,allkb)) ifeq ($$(RULE_FOUND),true) $$(eval $$(call PARSE_ALL_KEYBOARDS)) + else + $$(eval $$(call TRY_PARSE_KEYBOARD,$(KEYBOARDS))) endif endef -- cgit v1.2.3 From 9b02e66ce0f703480e42038a5084174a45b54b1d Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Thu, 4 Aug 2016 08:49:44 +0300 Subject: Add keymap parsing --- Makefile | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index b24270ad1b..b4204478e1 100644 --- a/Makefile +++ b/Makefile @@ -71,12 +71,28 @@ define PARSE_ALL_KEYBOARDS COMMAND_allkb := "All keyboards with $$(RULE)" endef +# $1 = Keyboard define PARSE_KEYBOARD - COMMANDS += $1 - #$$(info $$(RULE)) - COMMAND_$1 := "Keyboard $1 with $$(RULE)" + $$(eval $$(call COMPARE_AND_REMOVE_FROM_RULE,allkm)) + ifeq ($$(RULE_FOUND),true) + $$(eval $$(call PARSE_ALL_KEYMAPS, $1)) + else + KEYMAPS := $(notdir $(patsubst %/.,%,$(wildcard $(ROOT_DIR)/keyboards/$1/keymaps/*/.))) + $$(eval $$(call TRY_PARSE_KEYMAP,$$(KEYMAPS),$1)) + endif +endef + +define PARSE_ALL_KEYMAPS + COMMANDS += ALL_KEYMAPS + COMMAND_ALL_KEYMAPS := All keymaps in $1 endef +# $1 Keyboard +# $2 Keymap +define PARSE_KEYMAP + COMMANDS += KEYBOARD_$1_KEYMAP_$2 + COMMAND_KEYBOARD_$1_KEYMAP_$2 := Keyboard $1, Keymap $2 +endef # Recursively try to find a matching keyboard # During the first call $1 contains a list of all keyboards @@ -91,6 +107,18 @@ define TRY_PARSE_KEYBOARD endif endef +# $1 list of keymaps +# $2 keyboard +define TRY_PARSE_KEYMAP + CURRENT_KM := $$(firstword $1) + $$(eval $$(call COMPARE_AND_REMOVE_FROM_RULE,$$(CURRENT_KM))) + ifeq ($$(RULE_FOUND),true) + $$(eval $$(call PARSE_KEYMAP,$2,$$(CURRENT_KM))) + else ifneq ($1,) + $$(eval $$(call TRY_PARSE_KEYMAP,$$(wordlist 2,9999,$1),$2)) + endif +endef + define PARSE_RULE RULE := $1 COMMANDS := -- cgit v1.2.3 From dfe510d5b8f83c9977b507ed204632c2f22c5d24 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Thu, 4 Aug 2016 09:17:02 +0300 Subject: Refactor common rule list parsing into own function --- Makefile | 61 +++++++++++++++++++++++++++++-------------------------------- 1 file changed, 29 insertions(+), 32 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index b4204478e1..e88eeefee4 100644 --- a/Makefile +++ b/Makefile @@ -65,6 +65,20 @@ define COMPARE_AND_REMOVE_FROM_RULE endif endef +# Recursively try to find a match +# $1 The list to be checked +# 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))) + endif +endef + + define PARSE_ALL_KEYBOARDS COMMANDS += allkb #$$(info $$(RULE)) @@ -73,51 +87,31 @@ endef # $1 = Keyboard define PARSE_KEYBOARD + CURRENT_KB := $1 $$(eval $$(call COMPARE_AND_REMOVE_FROM_RULE,allkm)) ifeq ($$(RULE_FOUND),true) - $$(eval $$(call PARSE_ALL_KEYMAPS, $1)) + $$(eval $$(call PARSE_ALL_KEYMAPS)) else KEYMAPS := $(notdir $(patsubst %/.,%,$(wildcard $(ROOT_DIR)/keyboards/$1/keymaps/*/.))) - $$(eval $$(call TRY_PARSE_KEYMAP,$$(KEYMAPS),$1)) + $$(eval $$(call TRY_TO_MATCH_RULE_FROM_LIST,$$(KEYMAPS))) + ifeq ($$(RULE_FOUND),true) + $$(eval $$(call PARSE_KEYMAP,$$(MATCHED_ITEM))) + endif endif endef define PARSE_ALL_KEYMAPS COMMANDS += ALL_KEYMAPS - COMMAND_ALL_KEYMAPS := All keymaps in $1 + COMMAND_ALL_KEYMAPS := All keymaps in $(CURRENT_KB) endef -# $1 Keyboard -# $2 Keymap +# $1 Keymap define PARSE_KEYMAP - COMMANDS += KEYBOARD_$1_KEYMAP_$2 - COMMAND_KEYBOARD_$1_KEYMAP_$2 := Keyboard $1, Keymap $2 + CURRENT_KM = $1 + COMMANDS += KEYBOARD_$$(CURRENT_KB)_KEYMAP_$$(CURRENT_KM) + COMMAND_KEYBOARD_$$(CURRENT_KB)_KEYMAP_$$(CURRENT_KM) := Keyboard $$(CURRENT_KB), Keymap $$(CURRENT_KM) endef -# Recursively try to find a matching keyboard -# During the first call $1 contains a list of all keyboards -# One keyboard is checked and removed at a time -define TRY_PARSE_KEYBOARD - CURRENT_KB := $$(firstword $1) - $$(eval $$(call COMPARE_AND_REMOVE_FROM_RULE,$$(CURRENT_KB))) - ifeq ($$(RULE_FOUND),true) - $$(eval $$(call PARSE_KEYBOARD,$$(CURRENT_KB))) - else ifneq ($1,) - $$(eval $$(call TRY_PARSE_KEYBOARD,$$(wordlist 2,9999,$1))) - endif -endef - -# $1 list of keymaps -# $2 keyboard -define TRY_PARSE_KEYMAP - CURRENT_KM := $$(firstword $1) - $$(eval $$(call COMPARE_AND_REMOVE_FROM_RULE,$$(CURRENT_KM))) - ifeq ($$(RULE_FOUND),true) - $$(eval $$(call PARSE_KEYMAP,$2,$$(CURRENT_KM))) - else ifneq ($1,) - $$(eval $$(call TRY_PARSE_KEYMAP,$$(wordlist 2,9999,$1),$2)) - endif -endef define PARSE_RULE RULE := $1 @@ -126,7 +120,10 @@ define PARSE_RULE ifeq ($$(RULE_FOUND),true) $$(eval $$(call PARSE_ALL_KEYBOARDS)) else - $$(eval $$(call TRY_PARSE_KEYBOARD,$(KEYBOARDS))) + $$(eval $$(call TRY_TO_MATCH_RULE_FROM_LIST,$$(KEYBOARDS))) + ifeq ($$(RULE_FOUND),true) + $$(eval $$(call PARSE_KEYBOARD,$$(MATCHED_ITEM))) + endif endif endef -- cgit v1.2.3 From 9ee6d4a23d9a1bdc019fc9968a909866ffeda905 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Thu, 4 Aug 2016 09:56:03 +0300 Subject: Proper looping for allkb and allkm --- Makefile | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index e88eeefee4..57cf3f523a 100644 --- a/Makefile +++ b/Makefile @@ -78,21 +78,32 @@ define TRY_TO_MATCH_RULE_FROM_LIST endif endef +define ALL_IN_LIST_LOOP + OLD_RULE$1 := $$(RULE) + $$(eval $$(call $1,$$(ITEM$1))) + RULE := $$(OLD_RULE$1) +endef + +define PARSE_ALL_IN_LIST + $$(foreach ITEM$1,$2,$$(eval $$(call ALL_IN_LIST_LOOP,$1))) +endef define PARSE_ALL_KEYBOARDS - COMMANDS += allkb - #$$(info $$(RULE)) - COMMAND_allkb := "All keyboards with $$(RULE)" + $$(eval $$(call PARSE_ALL_IN_LIST,PARSE_KEYBOARD,$(KEYBOARDS))) +endef + +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/*/.))) $$(eval $$(call COMPARE_AND_REMOVE_FROM_RULE,allkm)) ifeq ($$(RULE_FOUND),true) $$(eval $$(call PARSE_ALL_KEYMAPS)) else - KEYMAPS := $(notdir $(patsubst %/.,%,$(wildcard $(ROOT_DIR)/keyboards/$1/keymaps/*/.))) $$(eval $$(call TRY_TO_MATCH_RULE_FROM_LIST,$$(KEYMAPS))) ifeq ($$(RULE_FOUND),true) $$(eval $$(call PARSE_KEYMAP,$$(MATCHED_ITEM))) @@ -100,11 +111,6 @@ define PARSE_KEYBOARD endif endef -define PARSE_ALL_KEYMAPS - COMMANDS += ALL_KEYMAPS - COMMAND_ALL_KEYMAPS := All keymaps in $(CURRENT_KB) -endef - # $1 Keymap define PARSE_KEYMAP CURRENT_KM = $1 @@ -112,7 +118,6 @@ define PARSE_KEYMAP COMMAND_KEYBOARD_$$(CURRENT_KB)_KEYMAP_$$(CURRENT_KM) := Keyboard $$(CURRENT_KB), Keymap $$(CURRENT_KM) endef - define PARSE_RULE RULE := $1 COMMANDS := -- cgit v1.2.3 From 1df6498721e989f1b3b10ba4b1b03d0ba54e9204 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Sun, 7 Aug 2016 14:33:49 +0300 Subject: Subproject parsing Does not handle keyboards without subprojects correctly yet. --- Makefile | 49 ++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 38 insertions(+), 11 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 57cf3f523a..e9e95569c4 100644 --- a/Makefile +++ b/Makefile @@ -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 -- cgit v1.2.3 From 286b3b8057630bf9ce78d3a0aaa24f4841b37b3e Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Sun, 7 Aug 2016 15:56:41 +0300 Subject: Slight refactoring to remove some verbosity --- Makefile | 45 ++++++++++++++++++--------------------------- 1 file changed, 18 insertions(+), 27 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index e9e95569c4..8f7dbb9e6c 100644 --- a/Makefile +++ b/Makefile @@ -50,8 +50,7 @@ $(info Keyboards: $(KEYBOARDS)) # and $1 is removed from the RULE variable # 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 +define COMPARE_AND_REMOVE_FROM_RULE_HELPER ifeq ($1,$$(RULE)) RULE:= RULE_FOUND := true @@ -66,21 +65,25 @@ define COMPARE_AND_REMOVE_FROM_RULE endif endef +COMPARE_AND_REMOVE_FROM_RULE = $(eval $(call COMPARE_AND_REMOVE_FROM_RULE_HELPER,$1))$(RULE_FOUND) + + # Recursively try to find a match # $1 The list to be checked # 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 +define TRY_TO_MATCH_RULE_FROM_LIST_HELPER ifneq ($1,) - $$(eval $$(call COMPARE_AND_REMOVE_FROM_RULE,$$(firstword $1))) - ifeq ($$(RULE_FOUND),true) + ifeq ($$(call COMPARE_AND_REMOVE_FROM_RULE,$$(firstword $1)),true) MATCHED_ITEM := $$(firstword $1) 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 endef +TRY_TO_MATCH_RULE_FROM_LIST = $(eval $(call TRY_TO_MATCH_RULE_FROM_LIST_HELPER,$1))$(RULE_FOUND) + define ALL_IN_LIST_LOOP OLD_RULE$1 := $$(RULE) $$(eval $$(call $1,$$(ITEM$1))) @@ -111,14 +114,10 @@ endef 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) + ifeq ($$(call COMPARE_AND_REMOVE_FROM_RULE,allkm),true) $$(eval $$(call PARSE_ALL_KEYMAPS)) - else - $$(eval $$(call TRY_TO_MATCH_RULE_FROM_LIST,$$(KEYMAPS))) - ifeq ($$(RULE_FOUND),true) - $$(eval $$(call PARSE_KEYMAP,$$(MATCHED_ITEM))) - endif + else ifeq ($$(call TRY_TO_MATCH_RULE_FROM_LIST,$$(KEYMAPS)),true) + $$(eval $$(call PARSE_KEYMAP,$$(MATCHED_ITEM))) endif endef @@ -127,14 +126,10 @@ 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) + ifeq ($$(call COMPARE_AND_REMOVE_FROM_RULE,allsp),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 + else ifeq ($$(call TRY_TO_MATCH_RULE_FROM_LIST,$$(SUBPROJECTS)),true) + $$(eval $$(call PARSE_SUBPROJECT,$$(MATCHED_ITEM))) endif endef @@ -148,14 +143,10 @@ endef define PARSE_RULE RULE := $1 COMMANDS := - $$(eval $$(call COMPARE_AND_REMOVE_FROM_RULE,allkb)) - ifeq ($$(RULE_FOUND),true) + ifeq ($$(call COMPARE_AND_REMOVE_FROM_RULE,allkb),true) $$(eval $$(call PARSE_ALL_KEYBOARDS)) - else - $$(eval $$(call TRY_TO_MATCH_RULE_FROM_LIST,$$(KEYBOARDS))) - ifeq ($$(RULE_FOUND),true) - $$(eval $$(call PARSE_KEYBOARD,$$(MATCHED_ITEM))) - endif + else ifeq ($$(call TRY_TO_MATCH_RULE_FROM_LIST,$$(KEYBOARDS)),true) + $$(eval $$(call PARSE_KEYBOARD,$$(MATCHED_ITEM))) endif endef -- cgit v1.2.3 From 091fab5103bd896f1b36094a7337dbe2f9d2ad59 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Sun, 7 Aug 2016 16:02:14 +0300 Subject: Slight rearrange of the Makefile for easier readability --- Makefile | 54 +++++++++++++++++++++++++++--------------------------- 1 file changed, 27 insertions(+), 27 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 8f7dbb9e6c..a034213653 100644 --- a/Makefile +++ b/Makefile @@ -94,20 +94,30 @@ define PARSE_ALL_IN_LIST $$(foreach ITEM$1,$2,$$(eval $$(call ALL_IN_LIST_LOOP,$1))) endef -define PARSE_ALL_KEYBOARDS - $$(eval $$(call PARSE_ALL_IN_LIST,PARSE_KEYBOARD,$(KEYBOARDS))) +define PARSE_RULE + RULE := $1 + COMMANDS := + ifeq ($$(call COMPARE_AND_REMOVE_FROM_RULE,allkb),true) + $$(eval $$(call PARSE_ALL_KEYBOARDS)) + else ifeq ($$(call TRY_TO_MATCH_RULE_FROM_LIST,$$(KEYBOARDS)),true) + $$(eval $$(call PARSE_KEYBOARD,$$(MATCHED_ITEM))) + endif endef -define PARSE_ALL_KEYMAPS - $$(eval $$(call PARSE_ALL_IN_LIST,PARSE_KEYMAP,$$(KEYMAPS))) +# $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))) + ifeq ($$(call COMPARE_AND_REMOVE_FROM_RULE,allsp),true) + $$(eval $$(call PARSE_ALL_SUBPROJECTS)) + else ifeq ($$(call TRY_TO_MATCH_RULE_FROM_LIST,$$(SUBPROJECTS)),true) + $$(eval $$(call PARSE_SUBPROJECT,$$(MATCHED_ITEM))) + endif endef -define PARSE_ALL_SUBPROJECTS - ifeq ($$(SUBPROJECTS),) - $$(eval $$(call PARSE_SUBPROJECT,)) - else - $$(eval $$(call PARSE_ALL_IN_LIST,PARSE_SUBPROJECT,$$(SUBPROJECTS))) - endif +define PARSE_ALL_KEYBOARDS + $$(eval $$(call PARSE_ALL_IN_LIST,PARSE_KEYBOARD,$(KEYBOARDS))) endef # $1 Subproject @@ -121,15 +131,11 @@ define PARSE_SUBPROJECT 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))) - ifeq ($$(call COMPARE_AND_REMOVE_FROM_RULE,allsp),true) - $$(eval $$(call PARSE_ALL_SUBPROJECTS)) - else ifeq ($$(call TRY_TO_MATCH_RULE_FROM_LIST,$$(SUBPROJECTS)),true) - $$(eval $$(call PARSE_SUBPROJECT,$$(MATCHED_ITEM))) +define PARSE_ALL_SUBPROJECTS + ifeq ($$(SUBPROJECTS),) + $$(eval $$(call PARSE_SUBPROJECT,)) + else + $$(eval $$(call PARSE_ALL_IN_LIST,PARSE_SUBPROJECT,$$(SUBPROJECTS))) endif endef @@ -140,14 +146,8 @@ define PARSE_KEYMAP COMMAND_KEYBOARD_$$(CURRENT_KB)_SUBPROJECT_$(CURRENT_SP)_KEYMAP_$$(CURRENT_KM) := Keyboard $$(CURRENT_KB), Subproject $$(CURRENT_SP), Keymap $$(CURRENT_KM) endef -define PARSE_RULE - RULE := $1 - COMMANDS := - ifeq ($$(call COMPARE_AND_REMOVE_FROM_RULE,allkb),true) - $$(eval $$(call PARSE_ALL_KEYBOARDS)) - else ifeq ($$(call TRY_TO_MATCH_RULE_FROM_LIST,$$(KEYBOARDS)),true) - $$(eval $$(call PARSE_KEYBOARD,$$(MATCHED_ITEM))) - endif +define PARSE_ALL_KEYMAPS + $$(eval $$(call PARSE_ALL_IN_LIST,PARSE_KEYMAP,$$(KEYMAPS))) endef RUN_COMMAND = echo "Running": $(COMMAND_$(COMMAND)); -- cgit v1.2.3 From 0d5caead5ad0edc06aedda06814da05815fc177e Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Sun, 7 Aug 2016 16:45:33 +0300 Subject: Add default subproject parsing --- Makefile | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index a034213653..1e11dd5ff8 100644 --- a/Makefile +++ b/Makefile @@ -12,6 +12,8 @@ STARTING_DIR := $(subst $(ABS_ROOT_DIR),,$(ABS_STARTING_DIR)) PATH_ELEMENTS := $(subst /, ,$(STARTING_DIR)) +QUANTUM_DIR:=$(ROOT_DIR)/quantum + define NEXT_PATH_ELEMENT $$(eval CURRENT_PATH_ELEMENT := $$(firstword $$(PATH_ELEMENTS))) $$(eval PATH_ELEMENTS := $$(wordlist 2,9999,$$(PATH_ELEMENTS))) @@ -111,8 +113,14 @@ define PARSE_KEYBOARD SUBPROJECTS := $$(notdir $$(patsubst %/Makefile,%,$$(wildcard $(ROOT_DIR)/keyboards/$$(CURRENT_KB)/*/Makefile))) ifeq ($$(call COMPARE_AND_REMOVE_FROM_RULE,allsp),true) $$(eval $$(call PARSE_ALL_SUBPROJECTS)) + else ifeq ($$(call COMPARE_AND_REMOVE_FROM_RULE,defaultsp),true) + $$(eval $$(call PARSE_SUBPROJECT,defaultsp)) else ifeq ($$(call TRY_TO_MATCH_RULE_FROM_LIST,$$(SUBPROJECTS)),true) $$(eval $$(call PARSE_SUBPROJECT,$$(MATCHED_ITEM))) + else + # 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 + $$(eval $$(call PARSE_SUBPROJECT,defaultsp)) endif endef @@ -122,7 +130,12 @@ endef # $1 Subproject define PARSE_SUBPROJECT - CURRENT_SP := $1 + ifeq ($1,defaultsp) + $$(eval include $(ROOT_DIR)/keyboards/$$(CURRENT_KB)/Makefile) + CURRENT_SP := $$(SUBPROJECT_DEFAULT) + else + CURRENT_SP := $1 + endif KEYMAPS := $$(notdir $$(patsubst %/.,%,$$(wildcard $(ROOT_DIR)/keyboards/$$(CURRENT_KB)/keymaps/*/.))) ifeq ($$(call COMPARE_AND_REMOVE_FROM_RULE,allkm),true) $$(eval $$(call PARSE_ALL_KEYMAPS)) @@ -133,7 +146,7 @@ endef define PARSE_ALL_SUBPROJECTS ifeq ($$(SUBPROJECTS),) - $$(eval $$(call PARSE_SUBPROJECT,)) + $$(eval $$(call PARSE_SUBPROJECT,defaultsp)) else $$(eval $$(call PARSE_ALL_IN_LIST,PARSE_SUBPROJECT,$$(SUBPROJECTS))) endif -- cgit v1.2.3 From 44441de8cad7255fd0637459ed39b89e34751b78 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Sun, 7 Aug 2016 17:04:39 +0300 Subject: Split keyboard makefiles into rules and Makefile --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 1e11dd5ff8..b2a8735320 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,7 @@ STARTING_DIR := $(subst $(ABS_ROOT_DIR),,$(ABS_STARTING_DIR)) PATH_ELEMENTS := $(subst /, ,$(STARTING_DIR)) -QUANTUM_DIR:=$(ROOT_DIR)/quantum +MAKEFILE_INCLUDED=yes define NEXT_PATH_ELEMENT $$(eval CURRENT_PATH_ELEMENT := $$(firstword $$(PATH_ELEMENTS))) -- cgit v1.2.3 From 2dd9c1edcdcc3fc579e6109daf9012f9a82b7435 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Sun, 7 Aug 2016 17:48:59 +0300 Subject: Proper parsing of keymaps inside subprojects --- Makefile | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index b2a8735320..028d143930 100644 --- a/Makefile +++ b/Makefile @@ -131,16 +131,32 @@ endef # $1 Subproject define PARSE_SUBPROJECT ifeq ($1,defaultsp) + SUBPROJECT_DEFAULT= $$(eval include $(ROOT_DIR)/keyboards/$$(CURRENT_KB)/Makefile) CURRENT_SP := $$(SUBPROJECT_DEFAULT) else CURRENT_SP := $1 endif - KEYMAPS := $$(notdir $$(patsubst %/.,%,$$(wildcard $(ROOT_DIR)/keyboards/$$(CURRENT_KB)/keymaps/*/.))) - ifeq ($$(call COMPARE_AND_REMOVE_FROM_RULE,allkm),true) - $$(eval $$(call PARSE_ALL_KEYMAPS)) - else ifeq ($$(call TRY_TO_MATCH_RULE_FROM_LIST,$$(KEYMAPS)),true) - $$(eval $$(call PARSE_KEYMAP,$$(MATCHED_ITEM))) + # If current subproject is empty (the default was not defined), and we have a list of subproject + # then make all + ifeq ($$(CURRENT_SP),) + ifneq ($$(SUBPROJECTS),) + CURRENT_SP := allsp + endif + endif + ifneq ($$(CURRENT_SP),allsp) + KEYMAPS := $$(notdir $$(patsubst %/.,%,$$(wildcard $(ROOT_DIR)/keyboards/$$(CURRENT_KB)/keymaps/*/.))) + ifneq ($$(CURRENT_SP),) + SP_KEYMAPS := $$(notdir $$(patsubst %/.,%,$$(wildcard $(ROOT_DIR)/keyboards/$$(CURRENT_KB)/$$(CURRENT_SP)/keymaps/*/.))) + KEYMAPS := $$(sort $$(KEYMAPS) $$(SP_KEYMAPS)) + endif + ifeq ($$(call COMPARE_AND_REMOVE_FROM_RULE,allkm),true) + $$(eval $$(call PARSE_ALL_KEYMAPS)) + else ifeq ($$(call TRY_TO_MATCH_RULE_FROM_LIST,$$(KEYMAPS)),true) + $$(eval $$(call PARSE_KEYMAP,$$(MATCHED_ITEM))) + endif + else + $$(eval $$(call PARSE_ALL_IN_LIST,PARSE_SUBPROJECT,$(SUBPROJECTS))) endif endef -- cgit v1.2.3 From a6d35000241e20df32b34498a3a9622bde6f0062 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Sun, 7 Aug 2016 18:12:45 +0300 Subject: Print error message when trying to build non-existing keymap --- Makefile | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 028d143930..a9a2d98fcb 100644 --- a/Makefile +++ b/Makefile @@ -39,7 +39,8 @@ ifeq ($(CURRENT_PATH_ELEMENT),keyboards) endif $(info $(ROOT_DIR)/keyboards) -KEYBOARDS := $(notdir $(patsubst %/.,%,$(wildcard $(ROOT_DIR)/keyboards/*/.))) +# Only consider folders with makefiles, to prevent errors in case there are extra folders +KEYBOARDS := $(notdir $(patsubst %/Makefile,%,$(wildcard $(ROOT_DIR)/keyboards/*/Makefile))) $(info Keyboard: $(KEYBOARD)) $(info Keymap: $(KEYMAP)) @@ -154,6 +155,13 @@ define PARSE_SUBPROJECT $$(eval $$(call PARSE_ALL_KEYMAPS)) else ifeq ($$(call TRY_TO_MATCH_RULE_FROM_LIST,$$(KEYMAPS)),true) $$(eval $$(call PARSE_KEYMAP,$$(MATCHED_ITEM))) + else + ifeq ($$(CURRENT_SP),) + $$(info make: *** No rule to make target '$$(CURRENT_KB)-$$(RULE)'. Stop.) + else + $$(info make: *** No rule to make target '$$(CURRENT_KB)-$$(CURRENT_SP)-$$(RULE)'. Stop.) + endif + exit 1 endif else $$(eval $$(call PARSE_ALL_IN_LIST,PARSE_SUBPROJECT,$(SUBPROJECTS))) -- cgit v1.2.3 From 1ad5578d11b0b4a7288c3fd0748de3a57f4180f2 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Sun, 7 Aug 2016 18:15:45 +0300 Subject: Print error when building non-existing keyboard --- Makefile | 3 +++ 1 file changed, 3 insertions(+) (limited to 'Makefile') diff --git a/Makefile b/Makefile index a9a2d98fcb..623e4b064d 100644 --- a/Makefile +++ b/Makefile @@ -104,6 +104,9 @@ define PARSE_RULE $$(eval $$(call PARSE_ALL_KEYBOARDS)) else ifeq ($$(call TRY_TO_MATCH_RULE_FROM_LIST,$$(KEYBOARDS)),true) $$(eval $$(call PARSE_KEYBOARD,$$(MATCHED_ITEM))) + else + $$(info make: *** No rule to make target '$1'. Stop.) + exit 1 endif endef -- cgit v1.2.3 From c83af5451349e6160a2ee220e7b45bb974be5c64 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Sun, 7 Aug 2016 18:30:58 +0300 Subject: Support for running from keyboard directory --- Makefile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 623e4b064d..7180b41476 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ STARTING_MAKEFILE := $(firstword $(MAKEFILE_LIST)) ROOT_MAKEFILE := $(lastword $(MAKEFILE_LIST)) -ROOT_DIR := $(dir, $(ROOT_MAKEFILE)) +ROOT_DIR := $(dir $(ROOT_MAKEFILE)) ifeq ($(ROOT_DIR),) ROOT_DIR := . endif @@ -104,6 +104,8 @@ define PARSE_RULE $$(eval $$(call PARSE_ALL_KEYBOARDS)) else ifeq ($$(call TRY_TO_MATCH_RULE_FROM_LIST,$$(KEYBOARDS)),true) $$(eval $$(call PARSE_KEYBOARD,$$(MATCHED_ITEM))) + else ifneq ($$(KEYBOARD),) + $$(eval $$(call PARSE_KEYBOARD,$$(KEYBOARD))) else $$(info make: *** No rule to make target '$1'. Stop.) exit 1 -- cgit v1.2.3 From 4f20061f6619f632c28518979d17a51674a3f2c9 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Sun, 7 Aug 2016 18:44:57 +0300 Subject: Proper handling for running make from a subproject or keymap dir --- Makefile | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 7180b41476..a14642af6c 100644 --- a/Makefile +++ b/Makefile @@ -105,6 +105,15 @@ define PARSE_RULE else ifeq ($$(call TRY_TO_MATCH_RULE_FROM_LIST,$$(KEYBOARDS)),true) $$(eval $$(call PARSE_KEYBOARD,$$(MATCHED_ITEM))) else ifneq ($$(KEYBOARD),) + # If there's no match in the beginning, then use the working directory instead + # First add the keymap to the commandline if we are in a keymap subdirectory + ifneq ($$(KEYMAP),) + RULE := $$(KEYMAP)-$$(RULE) + endif + # If we are in a subproject subdirectory add the subproject + ifneq ($$(SUBPROJECT),) + RULE := $$(SUBPROJECT)-$$(RULE) + endif $$(eval $$(call PARSE_KEYBOARD,$$(KEYBOARD))) else $$(info make: *** No rule to make target '$1'. Stop.) -- cgit v1.2.3 From 459ddaceda252a7d8614c43f17cd4c8c14712d5f Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Sun, 7 Aug 2016 18:54:12 +0300 Subject: Add backwards compability with makefile variables --- Makefile | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'Makefile') diff --git a/Makefile b/Makefile index a14642af6c..cf0a12f695 100644 --- a/Makefile +++ b/Makefile @@ -42,6 +42,20 @@ $(info $(ROOT_DIR)/keyboards) # Only consider folders with makefiles, to prevent errors in case there are extra folders KEYBOARDS := $(notdir $(patsubst %/Makefile,%,$(wildcard $(ROOT_DIR)/keyboards/*/Makefile))) +#Compability with the old make variables +ifdef keyboard + KEYBOARD := $(keyboard) +endif +ifdef sub + SUBPROJECT := $(sub) +endif +ifdef subproject + SUBPROJECT := $(subproject) +endif +ifdef keymap + KEYMAP := $(keymap) +endif + $(info Keyboard: $(KEYBOARD)) $(info Keymap: $(KEYMAP)) $(info Subproject: $(SUBPROJECT)) -- cgit v1.2.3 From 3fa6625869b1bc1a2050a7e5edc6228a926536fc Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Sun, 7 Aug 2016 19:16:44 +0300 Subject: Proper default goals when inside keyboard fodlers --- Makefile | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index cf0a12f695..38bead90a5 100644 --- a/Makefile +++ b/Makefile @@ -61,6 +61,18 @@ $(info Keymap: $(KEYMAP)) $(info Subproject: $(SUBPROJECT)) $(info Keyboards: $(KEYBOARDS)) +ifneq ($(KEYMAP),) + ifeq ($(SUBPROJECT),) + .DEFAULT_GOAL := $(KEYBOARD)-$(KEYMAP) + else + .DEFAULT_GOAL := $(KEYBOARD)-$(SUBPROJECT)-$(KEYMAP) + endif +else ifneq ($(SUBPROJECT),) + .DEFAULT_GOAL := $(KEYBOARD)-$(SUBPROJECT)-allkm +else ifneq ($(KEYBOARD),) + .DEFAULT_GOAL := $(KEYBOARD)-allsp-allkm +endif + # Compare the start of the RULE_VARIABLE with the first argument($1) # If the rules equals $1 or starts with $1-, RULE_FOUND is set to true @@ -114,9 +126,11 @@ endef define PARSE_RULE RULE := $1 COMMANDS := + $$(info $$(RULE)) ifeq ($$(call COMPARE_AND_REMOVE_FROM_RULE,allkb),true) $$(eval $$(call PARSE_ALL_KEYBOARDS)) else ifeq ($$(call TRY_TO_MATCH_RULE_FROM_LIST,$$(KEYBOARDS)),true) + $$(info $$(MATCHED_ITEM)) $$(eval $$(call PARSE_KEYBOARD,$$(MATCHED_ITEM))) else ifneq ($$(KEYBOARD),) # If there's no match in the beginning, then use the working directory instead @@ -222,12 +236,13 @@ RUN_COMMAND = echo "Running": $(COMMAND_$(COMMAND)); $(eval $(call PARSE_RULE,$@)) $(foreach COMMAND,$(COMMANDS),$(RUN_COMMAND)) + +.PHONY: all +all: + echo "Compiling" + .PHONY: all-keyboards all-keyboards: allkb .PHONY: all-keyboards-defaults all-keyboards-defaults: allkb-default-default - -.PHONY: all -all: - echo "Compiling" \ No newline at end of file -- cgit v1.2.3 From a04bb3a3bae456a0744cf2f6dde326d9a24ebcee Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Sun, 7 Aug 2016 19:22:21 +0300 Subject: Fixed the shortcut targets --- Makefile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 38bead90a5..d59da0b635 100644 --- a/Makefile +++ b/Makefile @@ -61,6 +61,7 @@ $(info Keymap: $(KEYMAP)) $(info Subproject: $(SUBPROJECT)) $(info Keyboards: $(KEYBOARDS)) +.DEFAULT_GOAL := all ifneq ($(KEYMAP),) ifeq ($(SUBPROJECT),) .DEFAULT_GOAL := $(KEYBOARD)-$(KEYMAP) @@ -238,11 +239,10 @@ RUN_COMMAND = echo "Running": $(COMMAND_$(COMMAND)); .PHONY: all -all: - echo "Compiling" +all: all-keyboards .PHONY: all-keyboards -all-keyboards: allkb +all-keyboards: allkb-allsp-allkm .PHONY: all-keyboards-defaults -all-keyboards-defaults: allkb-default-default +all-keyboards-defaults: allkb-allsp-default -- cgit v1.2.3 From 0dd629a990e1546614dfa2b430489571c2550f7a Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Sun, 7 Aug 2016 21:28:14 +0300 Subject: Fix running make from various subfolders --- Makefile | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index d59da0b635..a02fa24a2b 100644 --- a/Makefile +++ b/Makefile @@ -38,7 +38,6 @@ ifeq ($(CURRENT_PATH_ELEMENT),keyboards) endif endif -$(info $(ROOT_DIR)/keyboards) # Only consider folders with makefiles, to prevent errors in case there are extra folders KEYBOARDS := $(notdir $(patsubst %/Makefile,%,$(wildcard $(ROOT_DIR)/keyboards/*/Makefile))) @@ -127,22 +126,11 @@ endef define PARSE_RULE RULE := $1 COMMANDS := - $$(info $$(RULE)) ifeq ($$(call COMPARE_AND_REMOVE_FROM_RULE,allkb),true) $$(eval $$(call PARSE_ALL_KEYBOARDS)) else ifeq ($$(call TRY_TO_MATCH_RULE_FROM_LIST,$$(KEYBOARDS)),true) - $$(info $$(MATCHED_ITEM)) $$(eval $$(call PARSE_KEYBOARD,$$(MATCHED_ITEM))) else ifneq ($$(KEYBOARD),) - # If there's no match in the beginning, then use the working directory instead - # First add the keymap to the commandline if we are in a keymap subdirectory - ifneq ($$(KEYMAP),) - RULE := $$(KEYMAP)-$$(RULE) - endif - # If we are in a subproject subdirectory add the subproject - ifneq ($$(SUBPROJECT),) - RULE := $$(SUBPROJECT)-$$(RULE) - endif $$(eval $$(call PARSE_KEYBOARD,$$(KEYBOARD))) else $$(info make: *** No rule to make target '$1'. Stop.) @@ -161,6 +149,8 @@ define PARSE_KEYBOARD $$(eval $$(call PARSE_SUBPROJECT,defaultsp)) else ifeq ($$(call TRY_TO_MATCH_RULE_FROM_LIST,$$(SUBPROJECTS)),true) $$(eval $$(call PARSE_SUBPROJECT,$$(MATCHED_ITEM))) + else ifneq ($$(SUBPROJECT),) + $$(eval $$(call PARSE_SUBPROJECT,$$(SUBPROJECT))) else # 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 @@ -194,10 +184,14 @@ define PARSE_SUBPROJECT SP_KEYMAPS := $$(notdir $$(patsubst %/.,%,$$(wildcard $(ROOT_DIR)/keyboards/$$(CURRENT_KB)/$$(CURRENT_SP)/keymaps/*/.))) KEYMAPS := $$(sort $$(KEYMAPS) $$(SP_KEYMAPS)) endif - ifeq ($$(call COMPARE_AND_REMOVE_FROM_RULE,allkm),true) + ifeq ($$(RULE),) + $$(eval $$(call PARSE_ALL_KEYMAPS)) + else ifeq ($$(call COMPARE_AND_REMOVE_FROM_RULE,allkm),true) $$(eval $$(call PARSE_ALL_KEYMAPS)) else ifeq ($$(call TRY_TO_MATCH_RULE_FROM_LIST,$$(KEYMAPS)),true) $$(eval $$(call PARSE_KEYMAP,$$(MATCHED_ITEM))) + else ifneq ($$(KEYMAP),) + $$(eval $$(call PARSE_KEYMAP,$$(KEYMAP))) else ifeq ($$(CURRENT_SP),) $$(info make: *** No rule to make target '$$(CURRENT_KB)-$$(RULE)'. Stop.) @@ -232,12 +226,16 @@ endef RUN_COMMAND = echo "Running": $(COMMAND_$(COMMAND)); +# Allow specifying just the subproject, in the keyboard directory, which will compile all keymaps +SUBPROJECTS := $(notdir $(patsubst %/Makefile,%,$(wildcard ./*/Makefile))) +.PHONY: $(SUBPROJECTS) +$(SUBPROJECTS): %: %-allkm + .PHONY: % %: $(eval $(call PARSE_RULE,$@)) $(foreach COMMAND,$(COMMANDS),$(RUN_COMMAND)) - .PHONY: all all: all-keyboards -- cgit v1.2.3 From db5c3b74fb6541879bfad9930d2a659b1d89cd83 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Mon, 8 Aug 2016 01:16:06 +0300 Subject: Add color output --- Makefile | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index a02fa24a2b..e5becd7ad7 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,7 @@ +ifndef VERBOSE +.SILENT: +endif + STARTING_MAKEFILE := $(firstword $(MAKEFILE_LIST)) ROOT_MAKEFILE := $(lastword $(MAKEFILE_LIST)) ROOT_DIR := $(dir $(ROOT_MAKEFILE)) @@ -216,15 +220,37 @@ endef # $1 Keymap define PARSE_KEYMAP CURRENT_KM = $1 - 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) + COMMAND := COMMAND_KEYBOARD_$$(CURRENT_KB)_SUBPROJECT_$(CURRENT_SP)_KEYMAP_$$(CURRENT_KM) + COMMANDS += $$(COMMAND) + ifeq ($$(CURRENT_SP),) + KB_SP := $(CURRENT_KB) + else + KB_SP := $(CURRENT_KB)/$$(CURRENT_SP) + endif + KB_SP := $(BOLD)$$(KB_SP)$(NO_COLOR) + COMMAND_$$(COMMAND) := \ + printf "Compiling $$(KB_SP) with $(BOLD)$$(CURRENT_KM)$(NO_COLOR)" | \ + $(AWK) '{ printf "%-118s", $$$$0;}'; \ + LOG=$$$$(echo "$$(MAKE) -c $(ROOT_DIR) -f build_keyboard.mk VERBOSE=$(VERBOSE) COLOR=$(COLOR) SILENT=true" 2>&1) ; \ + if [ $$$$? -gt 0 ]; \ + then $$(PRINT_ERROR_PLAIN); \ + elif [ "$$$$LOG" != "" ] ; \ + then $$(PRINT_WARNING_PLAIN); \ + else \ + $$(PRINT_OK); \ + fi; endef define PARSE_ALL_KEYMAPS $$(eval $$(call PARSE_ALL_IN_LIST,PARSE_KEYMAP,$$(KEYMAPS))) endef -RUN_COMMAND = echo "Running": $(COMMAND_$(COMMAND)); +include $(ROOT_DIR)/message.mk + +#RUN_COMMAND = echo "Running": $(COMMAND_$(COMMAND)); +RUN_COMMAND = \ +$(COMMAND_$(COMMAND)) +#LOG=$$(echo $(COMMAND) VERBOSE=$(VERBOSE) COLOR=$(COLOR) SILENT=true 2>&1) ; if [ $$? -gt 0 ]; then $(PRINT_ERROR_PLAIN); elif [ "$$LOG" != "" ] ; then $(PRINT_WARNING_PLAIN); else $(PRINT_OK); fi; \ # Allow specifying just the subproject, in the keyboard directory, which will compile all keymaps SUBPROJECTS := $(notdir $(patsubst %/Makefile,%,$(wildcard ./*/Makefile))) @@ -244,3 +270,4 @@ all-keyboards: allkb-allsp-allkm .PHONY: all-keyboards-defaults all-keyboards-defaults: allkb-allsp-default + -- cgit v1.2.3 From 67b294ca66fd9da341ab93019a380d91ac589c96 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Mon, 8 Aug 2016 10:26:23 +0300 Subject: Actual compilation --- Makefile | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index e5becd7ad7..fc61572094 100644 --- a/Makefile +++ b/Makefile @@ -228,17 +228,19 @@ define PARSE_KEYMAP KB_SP := $(CURRENT_KB)/$$(CURRENT_SP) endif KB_SP := $(BOLD)$$(KB_SP)$(NO_COLOR) + MAKE_VARS := KEYBOARD=$$(CURRENT_KB) SUBPROJECT=$$(CURRENT_SP) KEYMAP=$$(CURRENT_KM) + MAKE_VARS += VERBOSE=$(VERBOSE) COLOR=$(COLOR) SILENT=false COMMAND_$$(COMMAND) := \ - printf "Compiling $$(KB_SP) with $(BOLD)$$(CURRENT_KM)$(NO_COLOR)" | \ - $(AWK) '{ printf "%-118s", $$$$0;}'; \ - LOG=$$$$(echo "$$(MAKE) -c $(ROOT_DIR) -f build_keyboard.mk VERBOSE=$(VERBOSE) COLOR=$(COLOR) SILENT=true" 2>&1) ; \ - if [ $$$$? -gt 0 ]; \ - then $$(PRINT_ERROR_PLAIN); \ - elif [ "$$$$LOG" != "" ] ; \ - then $$(PRINT_WARNING_PLAIN); \ - else \ - $$(PRINT_OK); \ - fi; + printf "Compiling $$(KB_SP) with $(BOLD)$$(CURRENT_KM)$(NO_COLOR)" | \ + $(AWK) '{ printf "%-118s", $$$$0;}'; \ + LOG=$$$$($$(MAKE) -C $(ROOT_DIR) -f build_keyboard.mk $$(MAKE_VARS) 2>&1) ; \ + if [ $$$$? -gt 0 ]; \ + then $$(PRINT_ERROR_PLAIN); \ + elif [ "$$$$LOG" != "" ] ; \ + then $$(PRINT_WARNING_PLAIN); \ + else \ + $$(PRINT_OK); \ + fi; endef define PARSE_ALL_KEYMAPS @@ -258,9 +260,11 @@ SUBPROJECTS := $(notdir $(patsubst %/Makefile,%,$(wildcard ./*/Makefile))) $(SUBPROJECTS): %: %-allkm .PHONY: % -%: +%: + cmp --version >/dev/null 2>&1; if [ $$? -gt 0 ]; then printf "$(MSG_NO_CMP)"; exit 1; fi; $(eval $(call PARSE_RULE,$@)) $(foreach COMMAND,$(COMMANDS),$(RUN_COMMAND)) + .PHONY: all all: all-keyboards -- cgit v1.2.3 From 60c6e79ecb032e9726809a295ab3e0011e6b2fb4 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Mon, 8 Aug 2016 11:19:29 +0300 Subject: Move git submodule check and version generation to main Makefile --- Makefile | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'Makefile') diff --git a/Makefile b/Makefile index fc61572094..caa8f2de1c 100644 --- a/Makefile +++ b/Makefile @@ -262,6 +262,13 @@ $(SUBPROJECTS): %: %-allkm .PHONY: % %: cmp --version >/dev/null 2>&1; if [ $$? -gt 0 ]; then printf "$(MSG_NO_CMP)"; exit 1; fi; + git submodule status --recursive 2>/dev/null | \ + while IFS= read -r x; do \ + case "$$x" in \ + \ *) ;; \ + *) printf "$(MSG_SUBMODULE_DIRTY)";break;; \ + esac \ + done $(eval $(call PARSE_RULE,$@)) $(foreach COMMAND,$(COMMANDS),$(RUN_COMMAND)) @@ -275,3 +282,8 @@ all-keyboards: allkb-allsp-allkm .PHONY: all-keyboards-defaults all-keyboards-defaults: allkb-allsp-default + +GIT_VERSION := $(shell git describe --abbrev=6 --dirty --always --tags 2>/dev/null || date +"%Y-%m-%d-%H:%M:%S") +BUILD_DATE := $(shell date +"%Y-%m-%d-%H:%M:%S") +$(shell echo '#define QMK_VERSION "$(GIT_VERSION)"' > $(ROOT_DIR)/quantum/version.h) +$(shell echo '#define QMK_BUILDDATE "$(BUILD_DATE)"' >> $(ROOT_DIR)/quantum/version.h) \ No newline at end of file -- cgit v1.2.3 From 881bde8258e077500a99fd670633e79ecd074832 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Tue, 9 Aug 2016 08:30:21 +0300 Subject: Fix running make in parallel --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index caa8f2de1c..b39e9dded1 100644 --- a/Makefile +++ b/Makefile @@ -270,7 +270,7 @@ $(SUBPROJECTS): %: %-allkm esac \ done $(eval $(call PARSE_RULE,$@)) - $(foreach COMMAND,$(COMMANDS),$(RUN_COMMAND)) + +$(foreach COMMAND,$(COMMANDS),$(RUN_COMMAND)) .PHONY: all -- cgit v1.2.3 From e4c842de02d95e98f65c7bb4a8406ec6df4944fe Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Tue, 9 Aug 2016 08:31:04 +0300 Subject: Don't run builtin rules for submake To speed up the compilation --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index b39e9dded1..9b534e897b 100644 --- a/Makefile +++ b/Makefile @@ -233,7 +233,7 @@ define PARSE_KEYMAP COMMAND_$$(COMMAND) := \ printf "Compiling $$(KB_SP) with $(BOLD)$$(CURRENT_KM)$(NO_COLOR)" | \ $(AWK) '{ printf "%-118s", $$$$0;}'; \ - LOG=$$$$($$(MAKE) -C $(ROOT_DIR) -f build_keyboard.mk $$(MAKE_VARS) 2>&1) ; \ + LOG=$$$$($$(MAKE) -r -R -C $(ROOT_DIR) -f build_keyboard.mk $$(MAKE_VARS) 2>&1) ; \ if [ $$$$? -gt 0 ]; \ then $$(PRINT_ERROR_PLAIN); \ elif [ "$$$$LOG" != "" ] ; \ -- cgit v1.2.3 From 8732265928818dd0b8797fb271e7c7fa9346d025 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Tue, 9 Aug 2016 09:52:01 +0300 Subject: Options for silent compilation A single keyboard is always by default compiled in verbose mode. While multiple keyboards are compiled in silent mode. This can be overriden by the silent variable from the command line --- Makefile | 50 ++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 38 insertions(+), 12 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 9b534e897b..3d4bd589f3 100644 --- a/Makefile +++ b/Makefile @@ -2,6 +2,16 @@ ifndef VERBOSE .SILENT: endif +ifdef silent + SILENT = $(silent) +endif + +ifdef SILENT + SUB_IS_SILENT := $(silent) +endif + +override SILENT = false + STARTING_MAKEFILE := $(firstword $(MAKEFILE_LIST)) ROOT_MAKEFILE := $(lastword $(MAKEFILE_LIST)) ROOT_DIR := $(dir $(ROOT_MAKEFILE)) @@ -59,10 +69,10 @@ ifdef keymap KEYMAP := $(keymap) endif -$(info Keyboard: $(KEYBOARD)) -$(info Keymap: $(KEYMAP)) -$(info Subproject: $(SUBPROJECT)) -$(info Keyboards: $(KEYBOARDS)) +#$(info Keyboard: $(KEYBOARD)) +#$(info Keymap: $(KEYMAP)) +#$(info Subproject: $(SUBPROJECT)) +#$(info Keyboards: $(KEYBOARDS)) .DEFAULT_GOAL := all ifneq ($(KEYMAP),) @@ -229,11 +239,14 @@ define PARSE_KEYMAP endif KB_SP := $(BOLD)$$(KB_SP)$(NO_COLOR) MAKE_VARS := KEYBOARD=$$(CURRENT_KB) SUBPROJECT=$$(CURRENT_SP) KEYMAP=$$(CURRENT_KM) - MAKE_VARS += VERBOSE=$(VERBOSE) COLOR=$(COLOR) SILENT=false - COMMAND_$$(COMMAND) := \ - printf "Compiling $$(KB_SP) with $(BOLD)$$(CURRENT_KM)$(NO_COLOR)" | \ - $(AWK) '{ printf "%-118s", $$$$0;}'; \ - LOG=$$$$($$(MAKE) -r -R -C $(ROOT_DIR) -f build_keyboard.mk $$(MAKE_VARS) 2>&1) ; \ + MAKE_VARS += VERBOSE=$(VERBOSE) COLOR=$(COLOR) + MAKE_COMMAND := $$(MAKE) -r -R -C $(ROOT_DIR) -f build_keyboard.mk + MAKE_MSG := Compiling $$(KB_SP) with $(BOLD)$$(CURRENT_KM)$(NO_COLOR) + MAKE_MSG_FORMAT := $(AWK) '{ printf "%-118s", $$$$0;}' + COMMAND_true_$$(COMMAND) := \ + printf "$$(MAKE_MSG)" | \ + $$(MAKE_MSG_FORMAT); \ + LOG=$$$$($$(MAKE_COMMAND) $$(MAKE_VARS) SILENT=true 2>&1) ; \ if [ $$$$? -gt 0 ]; \ then $$(PRINT_ERROR_PLAIN); \ elif [ "$$$$LOG" != "" ] ; \ @@ -241,18 +254,30 @@ define PARSE_KEYMAP else \ $$(PRINT_OK); \ fi; + COMMAND_false_$$(COMMAND) := \ + printf "$$(MAKE_MSG)\n" | \ + $$(MAKE_MSG_FORMAT); \ + $$(MAKE_COMMAND) $$(MAKE_VARS) SILENT=false; endef define PARSE_ALL_KEYMAPS $$(eval $$(call PARSE_ALL_IN_LIST,PARSE_KEYMAP,$$(KEYMAPS))) endef +define SET_SILENT_MODE + ifdef SUB_IS_SILENT + SILENT_MODE := $(SUB_IS_SILENT) + else ifeq ($$(words $$(COMMANDS)),1) + SILENT_MODE := false + else + SILENT_MODE := true + endif +endef + include $(ROOT_DIR)/message.mk -#RUN_COMMAND = echo "Running": $(COMMAND_$(COMMAND)); RUN_COMMAND = \ -$(COMMAND_$(COMMAND)) -#LOG=$$(echo $(COMMAND) VERBOSE=$(VERBOSE) COLOR=$(COLOR) SILENT=true 2>&1) ; if [ $$? -gt 0 ]; then $(PRINT_ERROR_PLAIN); elif [ "$$LOG" != "" ] ; then $(PRINT_WARNING_PLAIN); else $(PRINT_OK); fi; \ +$(COMMAND_$(SILENT_MODE)_$(COMMAND)) # Allow specifying just the subproject, in the keyboard directory, which will compile all keymaps SUBPROJECTS := $(notdir $(patsubst %/Makefile,%,$(wildcard ./*/Makefile))) @@ -270,6 +295,7 @@ $(SUBPROJECTS): %: %-allkm esac \ done $(eval $(call PARSE_RULE,$@)) + $(eval $(call SET_SILENT_MODE)) +$(foreach COMMAND,$(COMMANDS),$(RUN_COMMAND)) -- cgit v1.2.3 From d924eb591ebcfb603f8941763de9616ce4b1554c Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Thu, 11 Aug 2016 09:34:23 +0300 Subject: Fix variable name clash with builtin This caused the submake to be called several times, messing up the build. --- Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 3d4bd589f3..319684c83e 100644 --- a/Makefile +++ b/Makefile @@ -240,13 +240,13 @@ define PARSE_KEYMAP KB_SP := $(BOLD)$$(KB_SP)$(NO_COLOR) MAKE_VARS := KEYBOARD=$$(CURRENT_KB) SUBPROJECT=$$(CURRENT_SP) KEYMAP=$$(CURRENT_KM) MAKE_VARS += VERBOSE=$(VERBOSE) COLOR=$(COLOR) - MAKE_COMMAND := $$(MAKE) -r -R -C $(ROOT_DIR) -f build_keyboard.mk + MAKE_CMD := $$(MAKE) -r -R -C $(ROOT_DIR) -f build_keyboard.mk MAKE_MSG := Compiling $$(KB_SP) with $(BOLD)$$(CURRENT_KM)$(NO_COLOR) MAKE_MSG_FORMAT := $(AWK) '{ printf "%-118s", $$$$0;}' COMMAND_true_$$(COMMAND) := \ printf "$$(MAKE_MSG)" | \ $$(MAKE_MSG_FORMAT); \ - LOG=$$$$($$(MAKE_COMMAND) $$(MAKE_VARS) SILENT=true 2>&1) ; \ + LOG=$$$$($$(MAKE_CMD) $$(MAKE_VARS) SILENT=true 2>&1) ; \ if [ $$$$? -gt 0 ]; \ then $$(PRINT_ERROR_PLAIN); \ elif [ "$$$$LOG" != "" ] ; \ @@ -257,7 +257,7 @@ define PARSE_KEYMAP COMMAND_false_$$(COMMAND) := \ printf "$$(MAKE_MSG)\n" | \ $$(MAKE_MSG_FORMAT); \ - $$(MAKE_COMMAND) $$(MAKE_VARS) SILENT=false; + $$(MAKE_CMD) $$(MAKE_VARS) SILENT=false; endef define PARSE_ALL_KEYMAPS -- cgit v1.2.3 From 87bf34a5d341c3a2381f57c19fcb94c21c8d0122 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Sun, 14 Aug 2016 12:25:23 +0300 Subject: Pass the target to submake --- Makefile | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 319684c83e..ed89b07337 100644 --- a/Makefile +++ b/Makefile @@ -230,6 +230,9 @@ endef # $1 Keymap define PARSE_KEYMAP CURRENT_KM = $1 + # The rest of the rule is the target + # Remove the leading "-" from the target, as it acts as a separator + MAKE_TARGET := $$(patsubst -%,%,$$(RULE)) COMMAND := COMMAND_KEYBOARD_$$(CURRENT_KB)_SUBPROJECT_$(CURRENT_SP)_KEYMAP_$$(CURRENT_KM) COMMANDS += $$(COMMAND) ifeq ($$(CURRENT_SP),) @@ -240,8 +243,11 @@ define PARSE_KEYMAP KB_SP := $(BOLD)$$(KB_SP)$(NO_COLOR) MAKE_VARS := KEYBOARD=$$(CURRENT_KB) SUBPROJECT=$$(CURRENT_SP) KEYMAP=$$(CURRENT_KM) MAKE_VARS += VERBOSE=$(VERBOSE) COLOR=$(COLOR) - MAKE_CMD := $$(MAKE) -r -R -C $(ROOT_DIR) -f build_keyboard.mk - MAKE_MSG := Compiling $$(KB_SP) with $(BOLD)$$(CURRENT_KM)$(NO_COLOR) + MAKE_CMD := $$(MAKE) -r -R -C $(ROOT_DIR) -f build_keyboard.mk $$(MAKE_TARGET) + MAKE_MSG := Making $$(KB_SP) with keymap $(BOLD)$$(CURRENT_KM)$(NO_COLOR) + ifneq ($$(MAKE_TARGET),) + MAKE_MSG += and target $(BOLD)$$(MAKE_TARGET)$(NO_COLOR) + endif MAKE_MSG_FORMAT := $(AWK) '{ printf "%-118s", $$$$0;}' COMMAND_true_$$(COMMAND) := \ printf "$$(MAKE_MSG)" | \ -- cgit v1.2.3 From 03e31ef8b9752220d092a1950030cf7942e002eb Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Tue, 16 Aug 2016 08:42:08 +0300 Subject: Continue on error --- Makefile | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index ed89b07337..f80d4e99c8 100644 --- a/Makefile +++ b/Makefile @@ -12,6 +12,8 @@ endif override SILENT = false +ON_ERROR := error_occured=1 + STARTING_MAKEFILE := $(firstword $(MAKEFILE_LIST)) ROOT_MAKEFILE := $(lastword $(MAKEFILE_LIST)) ROOT_DIR := $(dir $(ROOT_MAKEFILE)) @@ -302,7 +304,9 @@ $(SUBPROJECTS): %: %-allkm done $(eval $(call PARSE_RULE,$@)) $(eval $(call SET_SILENT_MODE)) - +$(foreach COMMAND,$(COMMANDS),$(RUN_COMMAND)) + +error_occured=0; \ + $(foreach COMMAND,$(COMMANDS),$(RUN_COMMAND)) \ + if [ $$error_occured -gt 0 ]; then printf "$(MSG_ERRORS)" & exit $$error_occured; fi .PHONY: all -- cgit v1.2.3 From f29730da36cb2e036c5878327f567532d2533ff1 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Tue, 16 Aug 2016 08:57:10 +0300 Subject: Better format for non-silent output --- Makefile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index f80d4e99c8..9ca73b4ad7 100644 --- a/Makefile +++ b/Makefile @@ -263,8 +263,7 @@ define PARSE_KEYMAP $$(PRINT_OK); \ fi; COMMAND_false_$$(COMMAND) := \ - printf "$$(MAKE_MSG)\n" | \ - $$(MAKE_MSG_FORMAT); \ + printf "$$(MAKE_MSG)\n\n"; \ $$(MAKE_CMD) $$(MAKE_VARS) SILENT=false; endef -- cgit v1.2.3 From b26ded3ab1c09e2a127feb5f4e22e97242ce77d7 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Sat, 20 Aug 2016 14:53:29 +0300 Subject: Comment the Makefile Also move some messages to message.mk --- Makefile | 129 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 113 insertions(+), 16 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 9ca73b4ad7..d70ac9a3b8 100644 --- a/Makefile +++ b/Makefile @@ -2,15 +2,18 @@ ifndef VERBOSE .SILENT: endif +# Allow the silent with lower caps to work the same way as upper caps ifdef silent SILENT = $(silent) endif ifdef SILENT - SUB_IS_SILENT := $(silent) + SUB_IS_SILENT := $(SILENT) endif -override SILENT = false +# We need to make sure that silent is always turned off at the top level +# Otherwise the [OK], [ERROR] and [WARN] messags won't be displayed correctly +override SILENT := false ON_ERROR := error_occured=1 @@ -26,27 +29,44 @@ ABS_STARTING_DIR := $(dir $(ABS_STARTING_MAKEFILE)) ABS_ROOT_DIR := $(dir $(ABS_ROOT_MAKEFILE)) STARTING_DIR := $(subst $(ABS_ROOT_DIR),,$(ABS_STARTING_DIR)) -PATH_ELEMENTS := $(subst /, ,$(STARTING_DIR)) - MAKEFILE_INCLUDED=yes +# Helper function to process the newt element of a space separated path +# It works a bit like the traditional functional head tail +# so the CURRENT_PATH_ELEMENT will beome the new head +# and the PATH_ELEMENTS are the rest that are still unprocessed define NEXT_PATH_ELEMENT $$(eval CURRENT_PATH_ELEMENT := $$(firstword $$(PATH_ELEMENTS))) $$(eval PATH_ELEMENTS := $$(wordlist 2,9999,$$(PATH_ELEMENTS))) endef +# We change the / to spaces so that we more easily can work with the elements +# separately +PATH_ELEMENTS := $(subst /, ,$(STARTING_DIR)) +# Initialize the path elements list for further processing $(eval $(call NEXT_PATH_ELEMENT)) +# This function sets the KEYBOARD; KEYMAP and SUBPROJECT to the correct +# variables depending on which directory you stand in. +# It's really a very simple if else chain, if you squint enough, +# but the makefile syntax makes it very verbose. +# If we are in a subfolder of keyboards ifeq ($(CURRENT_PATH_ELEMENT),keyboards) $(eval $(call NEXT_PATH_ELEMENT)) KEYBOARD := $(CURRENT_PATH_ELEMENT) $(eval $(call NEXT_PATH_ELEMENT)) + # If we are in a subfolder of keymaps, or in other words in a keymap + # folder ifeq ($(CURRENT_PATH_ELEMENT),keymaps) $(eval $(call NEXT_PATH_ELEMENT)) KEYMAP := $(CURRENT_PATH_ELEMENT) + # else if we are not in the keyboard folder itself else ifneq ($(CURRENT_PATH_ELEMENT),) + # the we can assume it's a subproject, as no other folders + # should have make files in them SUBPROJECT := $(CURRENT_PATH_ELEMENT) $(eval $(call NEXT_PATH_ELEMENT)) + # if we are inside a keymap folder of a subproject ifeq ($(CURRENT_PATH_ELEMENT),keymaps) $(eval $(call NEXT_PATH_ELEMENT)) KEYMAP := $(CURRENT_PATH_ELEMENT) @@ -57,7 +77,8 @@ endif # Only consider folders with makefiles, to prevent errors in case there are extra folders KEYBOARDS := $(notdir $(patsubst %/Makefile,%,$(wildcard $(ROOT_DIR)/keyboards/*/Makefile))) -#Compability with the old make variables +#Compability with the old make variables, anything you specify directly on the command line +# always overrides the detected folders ifdef keyboard KEYBOARD := $(keyboard) endif @@ -71,29 +92,41 @@ ifdef keymap KEYMAP := $(keymap) endif +# Uncomment these for debugging #$(info Keyboard: $(KEYBOARD)) #$(info Keymap: $(KEYMAP)) #$(info Subproject: $(SUBPROJECT)) #$(info Keyboards: $(KEYBOARDS)) + +# Set the default goal depening on where we are running make from +# this handles the case where you run make without any arguments .DEFAULT_GOAL := all ifneq ($(KEYMAP),) ifeq ($(SUBPROJECT),) + # Inside a keymap folder, just build the keymap, with the + # default subproject .DEFAULT_GOAL := $(KEYBOARD)-$(KEYMAP) else + # Inside a subproject keyamp folder, build the keymap + # for that subproject .DEFAULT_GOAL := $(KEYBOARD)-$(SUBPROJECT)-$(KEYMAP) endif else ifneq ($(SUBPROJECT),) + # Inside a subproject folder, build all keymaps for that subproject .DEFAULT_GOAL := $(KEYBOARD)-$(SUBPROJECT)-allkm else ifneq ($(KEYBOARD),) + # Inside a keyboard folder, build all keymaps for all subprojects + # Note that this is different from the old behaviour, which would + # build only the default keymap of the default keyboard .DEFAULT_GOAL := $(KEYBOARD)-allsp-allkm endif -# Compare the start of the RULE_VARIABLE with the first argument($1) +# Compare the start of the RULE variable with the first argument($1) # If the rules equals $1 or starts with $1-, RULE_FOUND is set to true # 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, and RULE left as it was # The function is a bit tricky, since there's no built in $(startswith) function define COMPARE_AND_REMOVE_FROM_RULE_HELPER ifeq ($1,$$(RULE)) @@ -110,10 +143,12 @@ define COMPARE_AND_REMOVE_FROM_RULE_HELPER endif endef +# This makes it easier to call COMPARE_AND_REMOVE_FROM_RULE, since it makes it behave like +# a function that returns the value 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 for the start of the rule to be checked # $1 The list to be checked # If a match is found, then RULE_FOUND is set to true # and MATCHED_ITEM to the item that was matched @@ -127,6 +162,7 @@ define TRY_TO_MATCH_RULE_FROM_LIST_HELPER endif endef +# Make it easier to call TRY_TO_MATCH_RULE_FROM_LIST TRY_TO_MATCH_RULE_FROM_LIST = $(eval $(call TRY_TO_MATCH_RULE_FROM_LIST_HELPER,$1))$(RULE_FOUND) define ALL_IN_LIST_LOOP @@ -139,47 +175,70 @@ define PARSE_ALL_IN_LIST $$(foreach ITEM$1,$2,$$(eval $$(call ALL_IN_LIST_LOOP,$1))) endef +# The entry point for rule parsing +# parses a rule in the format --- +# but this particular function only deals with the first part define PARSE_RULE RULE := $1 COMMANDS := + # If the rule starts with allkb, then continue the parsing from + # PARSE_ALL_KEYBOARDS ifeq ($$(call COMPARE_AND_REMOVE_FROM_RULE,allkb),true) $$(eval $$(call PARSE_ALL_KEYBOARDS)) + # If the rule starts with the name of a known keyboard, then continue + # the parsing from PARSE_KEYBOARD else ifeq ($$(call TRY_TO_MATCH_RULE_FROM_LIST,$$(KEYBOARDS)),true) $$(eval $$(call PARSE_KEYBOARD,$$(MATCHED_ITEM))) + # Otherwise use the KEYBOARD variable, which is determined either by + # the current directory you run make from, or passed in as an argument else ifneq ($$(KEYBOARD),) $$(eval $$(call PARSE_KEYBOARD,$$(KEYBOARD))) else $$(info make: *** No rule to make target '$1'. Stop.) + # Notice the tab instead of spaces below! exit 1 endif endef # $1 = Keyboard +# Parses a rule in the format -- +# the keyboard is already known when entering this function 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))) + # 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 else - # 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 $$(eval $$(call PARSE_SUBPROJECT,defaultsp)) endif endef +# if we are going to compile all keyboards, match the rest of the rule +# for each of them define PARSE_ALL_KEYBOARDS $$(eval $$(call PARSE_ALL_IN_LIST,PARSE_KEYBOARD,$(KEYBOARDS))) endef # $1 Subproject +# When entering this, the keyboard and subproject are known, so now we need +# to determine which keymaps are going to get compiled define PARSE_SUBPROJECT + # If we want to compile the default subproject, then we need to + # include the correct makefile to determine the actual name of it ifeq ($1,defaultsp) SUBPROJECT_DEFAULT= $$(eval include $(ROOT_DIR)/keyboards/$$(CURRENT_KB)/Makefile) @@ -188,39 +247,54 @@ define PARSE_SUBPROJECT CURRENT_SP := $1 endif # If current subproject is empty (the default was not defined), and we have a list of subproject - # then make all + # then make all of them ifeq ($$(CURRENT_SP),) ifneq ($$(SUBPROJECTS),) CURRENT_SP := allsp endif endif + # The special allsp is handled later ifneq ($$(CURRENT_SP),allsp) + # get a list of all keymaps KEYMAPS := $$(notdir $$(patsubst %/.,%,$$(wildcard $(ROOT_DIR)/keyboards/$$(CURRENT_KB)/keymaps/*/.))) ifneq ($$(CURRENT_SP),) + # if the subproject is defined, then also look for keymaps inside the subproject folder SP_KEYMAPS := $$(notdir $$(patsubst %/.,%,$$(wildcard $(ROOT_DIR)/keyboards/$$(CURRENT_KB)/$$(CURRENT_SP)/keymaps/*/.))) KEYMAPS := $$(sort $$(KEYMAPS) $$(SP_KEYMAPS)) endif + # 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 allkm was specified else ifeq ($$(call COMPARE_AND_REMOVE_FROM_RULE,allkm),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))) else + # Otherwise something is wrong with the target + # Try to give as much information as possible of what it it was trying to do ifeq ($$(CURRENT_SP),) $$(info make: *** No rule to make target '$$(CURRENT_KB)-$$(RULE)'. Stop.) else $$(info make: *** No rule to make target '$$(CURRENT_KB)-$$(CURRENT_SP)-$$(RULE)'. Stop.) endif + # Notice the tab instead of spaces below! exit 1 endif else + # As earlier mentione,d when allsb is specified, we call our self recursively + # for all of the subprojects $$(eval $$(call PARSE_ALL_IN_LIST,PARSE_SUBPROJECT,$(SUBPROJECTS))) endif endef +# If we want to parse all subprojects, but the keyboard doesn't have any, +# then use defaultsp instead define PARSE_ALL_SUBPROJECTS ifeq ($$(SUBPROJECTS),) $$(eval $$(call PARSE_SUBPROJECT,defaultsp)) @@ -230,27 +304,36 @@ define PARSE_ALL_SUBPROJECTS endef # $1 Keymap +# This is the meat of compiling a keyboard, when entering this, everything is known +# keyboard, subproject, and keymap +# Note that we are not directly calling the command here, but instead building a list, +# which will later be processed define PARSE_KEYMAP CURRENT_KM = $1 # The rest of the rule is the target # Remove the leading "-" from the target, as it acts as a separator MAKE_TARGET := $$(patsubst -%,%,$$(RULE)) + # We need to generate an unique indentifer to append to the COMMANDS list COMMAND := COMMAND_KEYBOARD_$$(CURRENT_KB)_SUBPROJECT_$(CURRENT_SP)_KEYMAP_$$(CURRENT_KM) COMMANDS += $$(COMMAND) + # If we are compiling a keyboard without a subproject, we want to display just the name + # of the keyboard, otherwise keyboard/subproject ifeq ($$(CURRENT_SP),) KB_SP := $(CURRENT_KB) else KB_SP := $(CURRENT_KB)/$$(CURRENT_SP) endif + # Format it in bold KB_SP := $(BOLD)$$(KB_SP)$(NO_COLOR) + # Specify the variables that we are passing forward to submake MAKE_VARS := KEYBOARD=$$(CURRENT_KB) SUBPROJECT=$$(CURRENT_SP) KEYMAP=$$(CURRENT_KM) MAKE_VARS += VERBOSE=$(VERBOSE) COLOR=$(COLOR) + # And the first part of the make command MAKE_CMD := $$(MAKE) -r -R -C $(ROOT_DIR) -f build_keyboard.mk $$(MAKE_TARGET) - MAKE_MSG := Making $$(KB_SP) with keymap $(BOLD)$$(CURRENT_KM)$(NO_COLOR) - ifneq ($$(MAKE_TARGET),) - MAKE_MSG += and target $(BOLD)$$(MAKE_TARGET)$(NO_COLOR) - endif - MAKE_MSG_FORMAT := $(AWK) '{ printf "%-118s", $$$$0;}' + # The message to display + MAKE_MSG := $$(MSG_MAKE_KB) + # We run the command differently, depending on if we want more output or not + # The true version for silent output and the false version otherwise COMMAND_true_$$(COMMAND) := \ printf "$$(MAKE_MSG)" | \ $$(MAKE_MSG_FORMAT); \ @@ -267,10 +350,14 @@ define PARSE_KEYMAP $$(MAKE_CMD) $$(MAKE_VARS) SILENT=false; endef +# Just parse all the keymaps for a specifc keyboard define PARSE_ALL_KEYMAPS $$(eval $$(call PARSE_ALL_IN_LIST,PARSE_KEYMAP,$$(KEYMAPS))) endef +# Set the silent mode depending on if we are trying to compile multiple keyboards or not +# By default it's on in that case, but it can be overriden by specifying silent=false +# from the command line define SET_SILENT_MODE ifdef SUB_IS_SILENT SILENT_MODE := $(SUB_IS_SILENT) @@ -291,9 +378,12 @@ SUBPROJECTS := $(notdir $(patsubst %/Makefile,%,$(wildcard ./*/Makefile))) .PHONY: $(SUBPROJECTS) $(SUBPROJECTS): %: %-allkm +# Let's match everything, we handle all the rule parsing ourselves .PHONY: % %: + # Check if we have the CMP tool installed cmp --version >/dev/null 2>&1; if [ $$? -gt 0 ]; then printf "$(MSG_NO_CMP)"; exit 1; fi; + # Check if the submodules are dirty, and display a warning if they are git submodule status --recursive 2>/dev/null | \ while IFS= read -r x; do \ case "$$x" in \ @@ -303,14 +393,20 @@ $(SUBPROJECTS): %: %-allkm done $(eval $(call PARSE_RULE,$@)) $(eval $(call SET_SILENT_MODE)) + # Run all the commands in the same shell, notice the + at the first line + # it has to be there to allow parallel execution of the submake + # This always tries to compile everything, even if error occurs in the middle + # But we return the error code at the end, to trigger travis failures +error_occured=0; \ $(foreach COMMAND,$(COMMANDS),$(RUN_COMMAND)) \ if [ $$error_occured -gt 0 ]; then printf "$(MSG_ERRORS)" & exit $$error_occured; fi +# All should compile everything .PHONY: all all: all-keyboards +# Define some shortcuts, mostly for compability with the old syntax .PHONY: all-keyboards all-keyboards: allkb-allsp-allkm @@ -318,6 +414,7 @@ all-keyboards: allkb-allsp-allkm all-keyboards-defaults: allkb-allsp-default +# Generate the version.h file GIT_VERSION := $(shell git describe --abbrev=6 --dirty --always --tags 2>/dev/null || date +"%Y-%m-%d-%H:%M:%S") BUILD_DATE := $(shell date +"%Y-%m-%d-%H:%M:%S") $(shell echo '#define QMK_VERSION "$(GIT_VERSION)"' > $(ROOT_DIR)/quantum/version.h) -- cgit v1.2.3 From 1c69acb7d518893ee77e326342d4603da87470e5 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Sun, 21 Aug 2016 13:10:34 +0300 Subject: Add longest match to the rule-checking This fixes cases where you have several keyboards with a common prefix, like algernon, and algernon-master --- Makefile | 43 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index d70ac9a3b8..c8122e5765 100644 --- a/Makefile +++ b/Makefile @@ -152,13 +152,52 @@ COMPARE_AND_REMOVE_FROM_RULE = $(eval $(call COMPARE_AND_REMOVE_FROM_RULE_HELPER # $1 The list to be checked # 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_HELPER +define TRY_TO_MATCH_RULE_FROM_LIST_HELPER3 ifneq ($1,) ifeq ($$(call COMPARE_AND_REMOVE_FROM_RULE,$$(firstword $1)),true) MATCHED_ITEM := $$(firstword $1) else - $$(eval $$(call TRY_TO_MATCH_RULE_FROM_LIST_HELPER,$$(wordlist 2,9999,$1))) + $$(eval $$(call TRY_TO_MATCH_RULE_FROM_LIST_HELPER3,$$(wordlist 2,9999,$1))) + endif + endif +endef + +# A recursive helper function for finding the longest match +# $1 The list to be checed +# It works by always removing the currently matched item from the list +# and call itself recursively, until a match is found +define TRY_TO_MATCH_RULE_FROM_LIST_HELPER2 + # Stop the recursion when the list is empty + ifneq ($1,) + RULE_BEFORE := $$(RULE) + $$(eval $$(call TRY_TO_MATCH_RULE_FROM_LIST_HELPER3,$1)) + # If a match is found in the current list, otherwise just return what we had before + ifeq ($$(RULE_FOUND),true) + # Save the best match so far and call itself recursivel + BEST_MATCH := $$(MATCHED_ITEM) + BEST_MATCH_RULE := $$(RULE) + RULE_FOUND := false + RULE := $$(RULE_BEFORE) + $$(eval $$(call TRY_TO_MATCH_RULE_FROM_LIST_HELPER2,$$(filter-out $$(MATCHED_ITEM),$1))) endif + endif +endef + + +# Recursively try to find the longest match for the start of the rule to be checked +# $1 The list to be checked +# 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_HELPER + BEST_MATCH := + $$(eval $$(call TRY_TO_MATCH_RULE_FROM_LIST_HELPER2,$1)) + ifneq ($$(BEST_MATCH),) + RULE_FOUND := true + RULE := $$(BEST_MATCH_RULE) + MATCHED_ITEM := $$(BEST_MATCH) + else + RULE_FOUND := false + MATCHED_ITEM := endif endef -- cgit v1.2.3 From 7c9fff59d0bfd36016a5cd79d40ec27ae591610b Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Wed, 24 Aug 2016 10:29:01 +0300 Subject: Fix slight inconsistency When running make from either a keyboard folder or a subproject it runs all keymaps for all subprojects and the selected subproject respectively. Without this fix, the same doesn't happen if your run make clean for example. As it would just provide you with an error message. Now this will work as expected. --- Makefile | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index c8122e5765..f78cca6c6f 100644 --- a/Makefile +++ b/Makefile @@ -262,7 +262,7 @@ define PARSE_KEYBOARD # 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 else - $$(eval $$(call PARSE_SUBPROJECT,defaultsp)) + $$(eval $$(call PARSE_SUBPROJECT,)) endif endef @@ -278,12 +278,14 @@ endef define PARSE_SUBPROJECT # If we want to compile the default subproject, then we need to # include the correct makefile to determine the actual name of it - ifeq ($1,defaultsp) + CURRENT_SP := $1 + ifeq ($$(CURRENT_SP),) + CURRENT_SP := defaultsp + endif + ifeq ($$(CURRENT_SP),defaultsp) SUBPROJECT_DEFAULT= $$(eval include $(ROOT_DIR)/keyboards/$$(CURRENT_KB)/Makefile) CURRENT_SP := $$(SUBPROJECT_DEFAULT) - else - CURRENT_SP := $1 endif # If current subproject is empty (the default was not defined), and we have a list of subproject # then make all of them @@ -314,16 +316,16 @@ define PARSE_SUBPROJECT # Otherwise try to match the keymap from the current folder, or arguments to the make command else ifneq ($$(KEYMAP),) $$(eval $$(call PARSE_KEYMAP,$$(KEYMAP))) + # No matching keymap found, so we assume that the rest of the rule is the target + # If we haven't been able to parse out a subproject, then make all of them + # This is consistent with running make without any arguments from the keyboard + # folder + else ifeq ($1,) + $$(eval $$(call PARSE_ALL_SUBPROJECTS)) + # Otherwise, make all keymaps, again this is consistent with how it works without + # any arguments else - # Otherwise something is wrong with the target - # Try to give as much information as possible of what it it was trying to do - ifeq ($$(CURRENT_SP),) - $$(info make: *** No rule to make target '$$(CURRENT_KB)-$$(RULE)'. Stop.) - else - $$(info make: *** No rule to make target '$$(CURRENT_KB)-$$(CURRENT_SP)-$$(RULE)'. Stop.) - endif - # Notice the tab instead of spaces below! - exit 1 + $$(eval $$(call PARSE_ALL_KEYMAPS)) endif else # As earlier mentione,d when allsb is specified, we call our self recursively -- cgit v1.2.3 From 6d7cd639a5e4503f00162c7cfa4bc7302b82c71c Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Sun, 21 Aug 2016 16:29:54 +0300 Subject: Basic framework for parsing test targets --- Makefile | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index f78cca6c6f..16e90f8e49 100644 --- a/Makefile +++ b/Makefile @@ -224,6 +224,8 @@ define PARSE_RULE # PARSE_ALL_KEYBOARDS ifeq ($$(call COMPARE_AND_REMOVE_FROM_RULE,allkb),true) $$(eval $$(call PARSE_ALL_KEYBOARDS)) + else ifeq ($$(call COMPARE_AND_REMOVE_FROM_RULE,test),true) + $$(eval $$(call PARSE_TEST)) # If the rule starts with the name of a known keyboard, then continue # the parsing from PARSE_KEYBOARD else ifeq ($$(call TRY_TO_MATCH_RULE_FROM_LIST,$$(KEYBOARDS)),true) @@ -396,6 +398,16 @@ define PARSE_ALL_KEYMAPS $$(eval $$(call PARSE_ALL_IN_LIST,PARSE_KEYMAP,$$(KEYMAPS))) endef +define PARSE_TEST + TEST_NAME := $$(firstword $$(subst -, ,$$(RULE))) + TEST_TARGET := $$(subst $$(TEST_NAME),,$$(subst $$(TEST_NAME)-,,$$(RULE))) + MATCHED_TESTS := $$(foreach TEST,$$(TEST_LIST),$$(if $$(findstring $$(TEST_NAME),$$(TEST)),$$(TEST),)) + $$(info Test name $$(TEST_NAME)) + $$(info Test target $$(TEST_TARGET)) + $$(info $$(MATCHED_TESTS)) +endef + + # Set the silent mode depending on if we are trying to compile multiple keyboards or not # By default it's on in that case, but it can be overriden by specifying silent=false # from the command line @@ -459,4 +471,6 @@ all-keyboards-defaults: allkb-allsp-default GIT_VERSION := $(shell git describe --abbrev=6 --dirty --always --tags 2>/dev/null || date +"%Y-%m-%d-%H:%M:%S") BUILD_DATE := $(shell date +"%Y-%m-%d-%H:%M:%S") $(shell echo '#define QMK_VERSION "$(GIT_VERSION)"' > $(ROOT_DIR)/quantum/version.h) -$(shell echo '#define QMK_BUILDDATE "$(BUILD_DATE)"' >> $(ROOT_DIR)/quantum/version.h) \ No newline at end of file +$(shell echo '#define QMK_BUILDDATE "$(BUILD_DATE)"' >> $(ROOT_DIR)/quantum/version.h) + +include $(ROOT_DIR)/testlist.mk \ No newline at end of file -- cgit v1.2.3 From 27a673f5cf75747fe73641059aae60e9b53a1c78 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Sun, 21 Aug 2016 17:14:38 +0300 Subject: The makefile actually calls build_test --- Makefile | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 16e90f8e49..67b981d51e 100644 --- a/Makefile +++ b/Makefile @@ -358,7 +358,6 @@ define PARSE_KEYMAP MAKE_TARGET := $$(patsubst -%,%,$$(RULE)) # We need to generate an unique indentifer to append to the COMMANDS list COMMAND := COMMAND_KEYBOARD_$$(CURRENT_KB)_SUBPROJECT_$(CURRENT_SP)_KEYMAP_$$(CURRENT_KM) - COMMANDS += $$(COMMAND) # If we are compiling a keyboard without a subproject, we want to display just the name # of the keyboard, otherwise keyboard/subproject ifeq ($$(CURRENT_SP),) @@ -370,13 +369,18 @@ define PARSE_KEYMAP KB_SP := $(BOLD)$$(KB_SP)$(NO_COLOR) # Specify the variables that we are passing forward to submake MAKE_VARS := KEYBOARD=$$(CURRENT_KB) SUBPROJECT=$$(CURRENT_SP) KEYMAP=$$(CURRENT_KM) - MAKE_VARS += VERBOSE=$(VERBOSE) COLOR=$(COLOR) # And the first part of the make command MAKE_CMD := $$(MAKE) -r -R -C $(ROOT_DIR) -f build_keyboard.mk $$(MAKE_TARGET) # The message to display MAKE_MSG := $$(MSG_MAKE_KB) # We run the command differently, depending on if we want more output or not # The true version for silent output and the false version otherwise + $$(eval $$(call BUILD)) +endef + +define BUILD + MAKE_VARS += VERBOSE=$(VERBOSE) COLOR=$(COLOR) + COMMANDS += $$(COMMAND) COMMAND_true_$$(COMMAND) := \ printf "$$(MAKE_MSG)" | \ $$(MAKE_MSG_FORMAT); \ @@ -398,13 +402,21 @@ define PARSE_ALL_KEYMAPS $$(eval $$(call PARSE_ALL_IN_LIST,PARSE_KEYMAP,$$(KEYMAPS))) endef +define BUILD_TEST + TEST_NAME := $1 + MAKE_TARGET := $2 + COMMAND := $1 + MAKE_CMD := $$(MAKE) -r -R -C $(ROOT_DIR) -f build_test.mk $$(MAKE_TARGET) + MAKE_VARS := TEST=$$(TEST_NAME) + MAKE_MSG := $$(MSG_MAKE_TEST) + $$(eval $$(call BUILD)) +endef + define PARSE_TEST TEST_NAME := $$(firstword $$(subst -, ,$$(RULE))) TEST_TARGET := $$(subst $$(TEST_NAME),,$$(subst $$(TEST_NAME)-,,$$(RULE))) MATCHED_TESTS := $$(foreach TEST,$$(TEST_LIST),$$(if $$(findstring $$(TEST_NAME),$$(TEST)),$$(TEST),)) - $$(info Test name $$(TEST_NAME)) - $$(info Test target $$(TEST_TARGET)) - $$(info $$(MATCHED_TESTS)) + $$(foreach TEST,$$(MATCHED_TESTS),$$(eval $$(call BUILD_TEST,$$(TEST),$$(TEST_TARGET)))) endef -- cgit v1.2.3 From f4429ba48ca8346a208b711cd63e7413ac3efeff Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Thu, 25 Aug 2016 11:25:27 +0300 Subject: Running of unit tests But only if the compilation has succeeded --- Makefile | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 67b981d51e..054aa31ec5 100644 --- a/Makefile +++ b/Makefile @@ -28,6 +28,7 @@ ABS_ROOT_MAKEFILE := $(abspath $(ROOT_MAKEFILE)) ABS_STARTING_DIR := $(dir $(ABS_STARTING_MAKEFILE)) ABS_ROOT_DIR := $(dir $(ABS_ROOT_MAKEFILE)) STARTING_DIR := $(subst $(ABS_ROOT_DIR),,$(ABS_STARTING_DIR)) +TEST_DIR := $(ROOT_DIR)/.build/test MAKEFILE_INCLUDED=yes @@ -394,7 +395,10 @@ define BUILD fi; COMMAND_false_$$(COMMAND) := \ printf "$$(MAKE_MSG)\n\n"; \ - $$(MAKE_CMD) $$(MAKE_VARS) SILENT=false; + $$(MAKE_CMD) $$(MAKE_VARS) SILENT=false; \ + if [ $$$$? -gt 0 ]; \ + then error_occured=1; \ + fi; endef # Just parse all the keymaps for a specifc keyboard @@ -410,6 +414,7 @@ define BUILD_TEST MAKE_VARS := TEST=$$(TEST_NAME) MAKE_MSG := $$(MSG_MAKE_TEST) $$(eval $$(call BUILD)) + TESTS += $$(TEST_DIR)/$$(TEST_NAME).elf endef define PARSE_TEST @@ -464,8 +469,8 @@ $(SUBPROJECTS): %: %-allkm # But we return the error code at the end, to trigger travis failures +error_occured=0; \ $(foreach COMMAND,$(COMMANDS),$(RUN_COMMAND)) \ - if [ $$error_occured -gt 0 ]; then printf "$(MSG_ERRORS)" & exit $$error_occured; fi - + if [ $$error_occured -gt 0 ]; then printf "$(MSG_ERRORS)" & exit $$error_occured; fi;\ + $(foreach TEST,$(TESTS),$(TEST)) # All should compile everything .PHONY: all -- cgit v1.2.3 From fc855cb30e86aadee7b1d9ee62f83d85cc0447ea Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Sat, 27 Aug 2016 13:29:54 +0300 Subject: Fix running multiple tests --- Makefile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 054aa31ec5..5f5c46860c 100644 --- a/Makefile +++ b/Makefile @@ -414,10 +414,12 @@ define BUILD_TEST MAKE_VARS := TEST=$$(TEST_NAME) MAKE_MSG := $$(MSG_MAKE_TEST) $$(eval $$(call BUILD)) - TESTS += $$(TEST_DIR)/$$(TEST_NAME).elf + TEST_EXECUTABLE := $$(TEST_DIR)/$$(TEST_NAME).elf + TESTS += $$(TEST_EXECUTABLE) endef define PARSE_TEST + TESTS := TEST_NAME := $$(firstword $$(subst -, ,$$(RULE))) TEST_TARGET := $$(subst $$(TEST_NAME),,$$(subst $$(TEST_NAME)-,,$$(RULE))) MATCHED_TESTS := $$(foreach TEST,$$(TEST_LIST),$$(if $$(findstring $$(TEST_NAME),$$(TEST)),$$(TEST),)) @@ -470,7 +472,7 @@ $(SUBPROJECTS): %: %-allkm +error_occured=0; \ $(foreach COMMAND,$(COMMANDS),$(RUN_COMMAND)) \ if [ $$error_occured -gt 0 ]; then printf "$(MSG_ERRORS)" & exit $$error_occured; fi;\ - $(foreach TEST,$(TESTS),$(TEST)) + $(foreach TEST,$(TESTS),$(TEST);) # All should compile everything .PHONY: all -- cgit v1.2.3 From 7eefb34e7c4f162b9568ff880d0e4e5214e1b9c9 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Sat, 27 Aug 2016 14:53:57 +0300 Subject: Detect failures when running multiple tests Also add better output. --- Makefile | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 5f5c46860c..b7ef5f92a3 100644 --- a/Makefile +++ b/Makefile @@ -415,7 +415,15 @@ define BUILD_TEST MAKE_MSG := $$(MSG_MAKE_TEST) $$(eval $$(call BUILD)) TEST_EXECUTABLE := $$(TEST_DIR)/$$(TEST_NAME).elf - TESTS += $$(TEST_EXECUTABLE) + TESTS += $$(TEST_NAME) + TEST_MSG := $$(MSG_TEST) + $$(TEST_NAME)_COMMAND := \ + printf "$$(TEST_MSG)\n"; \ + $$(TEST_EXECUTABLE); \ + if [ $$$$? -gt 0 ]; \ + then error_occured=1; \ + fi; \ + printf "\n"; endef define PARSE_TEST @@ -472,7 +480,8 @@ $(SUBPROJECTS): %: %-allkm +error_occured=0; \ $(foreach COMMAND,$(COMMANDS),$(RUN_COMMAND)) \ if [ $$error_occured -gt 0 ]; then printf "$(MSG_ERRORS)" & exit $$error_occured; fi;\ - $(foreach TEST,$(TESTS),$(TEST);) + $(foreach TEST,$(TESTS),$($(TEST)_COMMAND)) \ + if [ $$error_occured -gt 0 ]; then printf "$(MSG_ERRORS)" & exit $$error_occured; fi;\ # All should compile everything .PHONY: all -- cgit v1.2.3 From 1b963117fedf91e4bef97d75eb4e3e0b3b1e1dfd Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Sat, 27 Aug 2016 18:01:59 +0300 Subject: Support for running and cleaning all tests --- Makefile | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index b7ef5f92a3..78bf50ed41 100644 --- a/Makefile +++ b/Makefile @@ -414,23 +414,29 @@ define BUILD_TEST MAKE_VARS := TEST=$$(TEST_NAME) MAKE_MSG := $$(MSG_MAKE_TEST) $$(eval $$(call BUILD)) - TEST_EXECUTABLE := $$(TEST_DIR)/$$(TEST_NAME).elf - TESTS += $$(TEST_NAME) - TEST_MSG := $$(MSG_TEST) - $$(TEST_NAME)_COMMAND := \ - printf "$$(TEST_MSG)\n"; \ - $$(TEST_EXECUTABLE); \ - if [ $$$$? -gt 0 ]; \ - then error_occured=1; \ - fi; \ - printf "\n"; + ifneq ($$(MAKE_TARGET),clean) + TEST_EXECUTABLE := $$(TEST_DIR)/$$(TEST_NAME).elf + TESTS += $$(TEST_NAME) + TEST_MSG := $$(MSG_TEST) + $$(TEST_NAME)_COMMAND := \ + printf "$$(TEST_MSG)\n"; \ + $$(TEST_EXECUTABLE); \ + if [ $$$$? -gt 0 ]; \ + then error_occured=1; \ + fi; \ + printf "\n"; + endif endef define PARSE_TEST TESTS := TEST_NAME := $$(firstword $$(subst -, ,$$(RULE))) TEST_TARGET := $$(subst $$(TEST_NAME),,$$(subst $$(TEST_NAME)-,,$$(RULE))) - MATCHED_TESTS := $$(foreach TEST,$$(TEST_LIST),$$(if $$(findstring $$(TEST_NAME),$$(TEST)),$$(TEST),)) + ifeq ($$(TEST_NAME),all) + MATCHED_TESTS := $$(TEST_LIST) + else + MATCHED_TESTS := $$(foreach TEST,$$(TEST_LIST),$$(if $$(findstring $$(TEST_NAME),$$(TEST)),$$(TEST),)) + endif $$(foreach TEST,$$(MATCHED_TESTS),$$(eval $$(call BUILD_TEST,$$(TEST),$$(TEST_TARGET)))) endef @@ -494,6 +500,11 @@ all-keyboards: allkb-allsp-allkm .PHONY: all-keyboards-defaults all-keyboards-defaults: allkb-allsp-default +.PHONY: test +test: test-all + +.PHONY: test-clean +test-clean: test-all-clean # Generate the version.h file GIT_VERSION := $(shell git describe --abbrev=6 --dirty --always --tags 2>/dev/null || date +"%Y-%m-%d-%H:%M:%S") -- cgit v1.2.3 From 6410f0c021792ebbbd279fc6150f197274e914c8 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Sat, 27 Aug 2016 18:13:01 +0300 Subject: The all target makes all keyboards and all tests --- Makefile | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 78bf50ed41..0aaf585786 100644 --- a/Makefile +++ b/Makefile @@ -2,6 +2,10 @@ ifndef VERBOSE .SILENT: endif +# Never run this makefile in parallel, as it could screw things up +# It won't affect the submakes, so you still get the speedup from specifying -jx +.NOTPARALLEL: + # Allow the silent with lower caps to work the same way as upper caps ifdef silent SILENT = $(silent) @@ -491,7 +495,7 @@ $(SUBPROJECTS): %: %-allkm # All should compile everything .PHONY: all -all: all-keyboards +all: all-keyboards test-all # Define some shortcuts, mostly for compability with the old syntax .PHONY: all-keyboards -- cgit v1.2.3