From f0983e80119a5c0ec4ff78526d1a1fef4ca63c77 Mon Sep 17 00:00:00 2001 From: Jesse Vincent Date: Sat, 19 Dec 2020 00:12:23 -0800 Subject: [PATCH 1/3] A handful of changes to make the makefiles lazier to shave off a few % of execution time --- etc/makefiles/arduino-cli.mk | 7 +++++-- etc/makefiles/sketch.mk | 31 ++++++++++++++++++------------- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/etc/makefiles/arduino-cli.mk b/etc/makefiles/arduino-cli.mk index f3c771ed..71577647 100644 --- a/etc/makefiles/arduino-cli.mk +++ b/etc/makefiles/arduino-cli.mk @@ -17,7 +17,10 @@ endif # Build path config TMPDIR ?= /tmp -export KALEIDOSCOPE_DIR ?= $(abspath $(mkfile_dir)/../..) +ifeq ($(KALEIDOSCOPE_DIR),) +export KALEIDOSCOPE_DIR := $(abspath $(mkfile_dir)/../..) +endif + KALEIDOSCOPE_BIN_DIR ?= $(KALEIDOSCOPE_DIR)/bin KALEIDOSCOPE_ETC_DIR ?= $(KALEIDOSCOPE_DIR)/etc @@ -74,7 +77,7 @@ endif -system_arduino_cli=$(shell command -v arduino-cli || true) +system_arduino_cli := $(shell command -v arduino-cli || true) arduino_env = ARDUINO_DIRECTORIES_USER=$(ARDUINO_DIRECTORIES_USER) \ ARDUINO_DIRECTORIES_DATA=$(ARDUINO_DIRECTORIES_DATA) diff --git a/etc/makefiles/sketch.mk b/etc/makefiles/sketch.mk index 2de435f0..35afbd38 100644 --- a/etc/makefiles/sketch.mk +++ b/etc/makefiles/sketch.mk @@ -33,8 +33,9 @@ endif # but since we'd just return an empty value in that case, why bother? GIT_VERSION := $(shell git -C "$(SKETCH_DIR)" describe --abbrev=6 --dirty --alway 2>/dev/null || echo 'unknown') -SKETCH_IDENTIFIER ?= $(shell echo "${SKETCH_FILE_PATH}" | cksum | cut -d ' ' -f 1)-$(SKETCH_FILE_NAME) - +ifeq ($(SKETCH_IDENTIFIER),) +SKETCH_IDENTIFIER := $(shell echo "${SKETCH_FILE_PATH}" | cksum | cut -d ' ' -f 1)-$(SKETCH_FILE_NAME) +endif BUILD_PATH ?= $(KALEIDOSCOPE_BUILD_PATH)/$(SKETCH_IDENTIFIER) OUTPUT_PATH ?= $(KALEIDOSCOPE_OUTPUT_PATH)/$(SKETCH_IDENTIFIER) @@ -53,7 +54,7 @@ KALEIDOSCOPE_PLATFORM_LIB_DIR := $(abspath $(KALEIDOSCOPE_DIR)/..) ifeq ($(FQBN),) -possible_fqbns = $(shell $(ARDUINO_CLI) board list --format=json |grep FQBN| grep -v "keyboardio:virtual"|cut -d: -f 2-) +possible_fqbns = $(shell $(ARDUINO_CLI) board list --format=json |grep FQBN| grep -v "keyboardio:virtual"|cut -d: -f 2-) possible_fqbn = $(firstword $(possible_fqbns)) @@ -106,7 +107,9 @@ endif # Flashing related config ifneq ($(FQBN),) -KALEIDOSCOPE_DEVICE_PORT ?= $(shell $(ARDUINO_CLI) board list --format=text | grep $(FQBN) |cut -d' ' -f 1) +ifeq ($(KALEIDOSCOPE_DEVICE_PORT),) +KALEIDOSCOPE_DEVICE_PORT = $(shell $(ARDUINO_CLI) board list --format=text | grep $(FQBN) |cut -d' ' -f 1) +endif endif flashing_instructions := $(call _arduino_prop,build.flashing_instructions) @@ -194,16 +197,18 @@ endif #TODO (arduino team) I'd love to do this with their json output #but it's short some of the data we kind of need -flash: -ifeq ($(KALEIDOSCOPE_DEVICE_PORT),) - $(info ERROR: Unable to detect keyboard serial port.) - $(info ) - $(info Arduino should autodetect it, but you could also set ) - $(info KALEIDOSCOPE_DEVICE_PORT to your keyboard's serial port.) - $(info ) - $(error ) +.PHONY: ensure-device-port-defined -endif +ensure-device-port-defined: + @if [ -z $(KALEIDOSCOPE_DEVICE_PORT) ]; then \ + echo "ERROR: Unable to detect keyboard serial port.";\ + echo ;\ + echo "Arduino should autodetect it, but you could also set";\ + echo "KALEIDOSCOPE_DEVICE_PORT to your keyboard's serial port.";\ + echo ;\ + exit -1;fi + +flash: ensure-device-port-defined $(info $(unescaped_flashing_instructions)) $(info ) $(info When you're ready to proceed, press 'Enter'.) From f17786a9c34730b24ed16524761ee25a8f6f83c6 Mon Sep 17 00:00:00 2001 From: Jesse Vincent Date: Sat, 19 Dec 2020 00:17:48 -0800 Subject: [PATCH 2/3] Another makefile laziness optimization --- etc/makefiles/sketch.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/etc/makefiles/sketch.mk b/etc/makefiles/sketch.mk index 35afbd38..ecd4ef99 100644 --- a/etc/makefiles/sketch.mk +++ b/etc/makefiles/sketch.mk @@ -117,7 +117,7 @@ ifeq ($(flashing_instructions),) flashing_instructions := "If your keyboard needs you to do something to put it in flashing mode, do that now." endif -unescaped_flashing_instructions := $(shell printf $(flashing_instructions) ) +unescaped_flashing_instructions = $(shell printf $(flashing_instructions) ) DEFAULT_GOAL: compile From 82515e46d96d754479e61fdfb84a6b534d61c593 Mon Sep 17 00:00:00 2001 From: Jesse Vincent Date: Sat, 19 Dec 2020 14:42:14 -0800 Subject: [PATCH 3/3] A small optimization for recursive makefile calls to stop shelling out to look for arduino-cli when we already know the answer --- etc/makefiles/arduino-cli.mk | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/etc/makefiles/arduino-cli.mk b/etc/makefiles/arduino-cli.mk index 71577647..8560a76b 100644 --- a/etc/makefiles/arduino-cli.mk +++ b/etc/makefiles/arduino-cli.mk @@ -75,19 +75,20 @@ endif endif - - -system_arduino_cli := $(shell command -v arduino-cli || true) - arduino_env = ARDUINO_DIRECTORIES_USER=$(ARDUINO_DIRECTORIES_USER) \ ARDUINO_DIRECTORIES_DATA=$(ARDUINO_DIRECTORIES_DATA) +ifeq ($(ARDUINO_CLI_PATH),) + +system_arduino_cli ?= $(shell command -v arduino-cli || true) + ifeq ($(system_arduino_cli),) export ARDUINO_CLI_PATH ?= $(KALEIDOSCOPE_BIN_DIR)/arduino-cli else export ARDUINO_CLI_PATH ?= $(system_arduino_cli) endif +endif export ARDUINO_CLI ?= $(arduino_env) $(ARDUINO_CLI_PATH)