diff --git a/Makefile b/Makefile index 418a02bb..fe9b2cdf 100644 --- a/Makefile +++ b/Makefile @@ -21,13 +21,13 @@ endif KALEIDOSCOPE_ETC_DIR ?= $(ARDUINO_DIRECTORIES_USER)/hardware/keyboardio/avr/libraries/Kaleidoscope/etc/ -ifeq ("$(KALEIDOSCOPE_ETC_DIR)/sketch-arduino-cli.mk","") +ifeq ("$(KALEIDOSCOPE_ETC_DIR)/makefiles/sketch.mk","") # Determine the path of this Makefile KALEIDOSCOPE_ETC_DIR:=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))/etc endif -include $(KALEIDOSCOPE_ETC_DIR)/sketch-arduino-cli.mk +include $(KALEIDOSCOPE_ETC_DIR)/makefiles/arduino-cli.mk # Set up an argument for passing to the simulator tests in docker # but if the var isn't set, don't even pass the definition @@ -37,10 +37,6 @@ ifneq ($(TEST_PATH),) TEST_PATH_ARG="TEST_PATH='$(TEST_PATH)'" endif -clean: - $(MAKE) -C tests clean - rm -rf testing/googletest/build/* - PLUGIN_TEST_SUPPORT_DIR ?= $(ARDUINO_DIRECTORIES_USER)/hardware/keyboardio/build-tools/ PLUGIN_TEST_BIN_DIR ?= $(PLUGIN_TEST_SUPPORT_DIR)/../toolchain/$(shell gcc --print-multiarch)/bin @@ -111,9 +107,10 @@ smoke-sketches: $(SMOKE_SKETCHES) .PHONY: force clean: - rm -rf -- "testing/googletest/build" - rm -rf -- "_build" - @$(KALEIDOSCOPE_BUILDER_DIR)/kaleidoscope-builder clean + $(MAKE) -C tests clean + rm -rf -- "testing/googletest/build/*" + rm -rf -- "_build/*" + $(SMOKE_SKETCHES): force - $(MAKE) -C $@ -f $(KALEIDOSCOPE_ETC_DIR)/sketch-arduino-cli.mk compile + $(MAKE) -C $@ -f $(KALEIDOSCOPE_ETC_DIR)/makefiles/sketch.mk compile diff --git a/etc/Makefile.sketch b/etc/Makefile.sketch index 5bc75ecf..132fa34a 100644 --- a/etc/Makefile.sketch +++ b/etc/Makefile.sketch @@ -16,4 +16,4 @@ endif KALEIDOSCOPE_ETC_DIR ?= $(ARDUINO_DIRECTORIES_USER)/hardware/keyboardio/avr/libraries/Kaleidoscope/etc/ -include $(KALEIDOSCOPE_ETC_DIR)/sketch-arduino-cli.mk +include $(KALEIDOSCOPE_ETC_DIR)/makefiles/sketch.mk diff --git a/etc/makefiles/arduino-cli.mk b/etc/makefiles/arduino-cli.mk new file mode 100644 index 00000000..562d26c9 --- /dev/null +++ b/etc/makefiles/arduino-cli.mk @@ -0,0 +1,73 @@ +mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST))) +mkfile_dir := $(dir $(mkfile_path)) + +# Make a variable lazily evaluated at first call +# From https://blog.jgc.org/2016/07/lazy-gnu-make-variables.html +make-lazy = $(eval $1 = $$(eval $1 := $(value $(1)))$$($1)) + +export KALEIDOSCOPE_DIR ?= $(abspath $(mkfile_dir)/../..) +export KALEIDOSCOPE_BIN_DIR ?= $(KALEIDOSCOPE_DIR)/bin + +# Arduino CLI config + +export ARDUINO_CONTENT ?= $(KALEIDOSCOPE_DIR)/.arduino +export ARDUINO_DIRECTORIES_DATA ?= $(ARDUINO_CONTENT)/data +export ARDUINO_DIRECTORIES_DOWNLOADS ?= $(ARDUINO_CONTENT)/downloads +export ARDUINO_DIRECTORIES_USER ?= $(ARDUINO_CONTENT)/user +export ARDUINO_CLI_CONFIG ?= $(ARDUINO_DIRECTORIES_DATA)/arduino-cli.yaml +export ARDUINO_BOARD_MANAGER_ADDITIONAL_URLS ?= https://raw.githubusercontent.com/keyboardio/boardsmanager/master/package_keyboardio_index.json + +system_arduino_cli=$(shell command -v arduino-cli || true) + +ifeq ($(system_arduino_cli),) +export ARDUINO_CLI ?= $(KALEIDOSCOPE_BIN_DIR)/arduino-cli +else +export ARDUINO_CLI ?= $(system_arduino_cli) +endif + +ifneq ($(VERBOSE),) +export ARDUINO_VERBOSE ?= --verbose +else +export ARDUINO_VERBOSE ?= +endif + +# This is horrible. But because make doesn't really support +# multi-line variables and we want to cache the full +# _arduino_props in a variable, which means letting make +# split the properties on space, which is what it converts +# newlines into. To make this go, we we need to replace interior +# spaces in the variables with something. We chose the fire +# emoji, since it accurately represents our feelings on this +# state of affairs. Later, when finding props, we need to reverse +# this process, turning fire into space. +_arduino_props = $(shell ${ARDUINO_CLI} compile --show-properties "$${SKETCH_FILE_PATH}"|perl -p -e"s/ /🔥/g") +$(call make-lazy,_arduino_props) + +_arduino_prop = $(subst $1=,,$(subst 🔥, ,$(filter $1=%,$(_arduino_props)))) + +# How to use_arduino_prop +# $(call _arduino_prop,recipe.hooks.sketch.prebuild.2.pattern) + + +# +.PHONY: configure-arduino-cli install-arduino-core-kaleidoscope install-arduino-core-avr + +.DEFAULT_GOAL := all + +all: + @echo "Make all target doesn't do anything" + @: ## Do not remove this line, otherwise `make all` will trigger the `%` rule too. + + +install-arduino-cli: + curl -fsSL https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | BINDIR="$(KALEIDOSCOPE_BIN_DIR)" sh + +configure-arduino-cli: + $(ARDUINO_CLI) config init + +install-arduino-core-kaleidoscope: + $(ARDUINO_CLI) core install "keyboardio:avr" + +install-arduino-core-avr: + $(ARDUINO_CLI) core install "arduino:avr" + diff --git a/etc/sketch-arduino-cli.mk b/etc/makefiles/sketch.mk similarity index 66% rename from etc/sketch-arduino-cli.mk rename to etc/makefiles/sketch.mk index ed8b3e80..691d2839 100644 --- a/etc/sketch-arduino-cli.mk +++ b/etc/makefiles/sketch.mk @@ -1,55 +1,7 @@ mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST))) mkfile_dir := $(dir $(mkfile_path)) +include $(mkfile_dir)/arduino-cli.mk -# Make a variable lazily evaluated at first call -# From https://blog.jgc.org/2016/07/lazy-gnu-make-variables.html -make-lazy = $(eval $1 = $$(eval $1 := $(value $(1)))$$($1)) - -export KALEIDOSCOPE_DIR ?= $(abspath $(mkfile_dir)/..) -export KALEIDOSCOPE_BIN_DIR ?= $(KALEIDOSCOPE_DIR)/bin - -# Arduino CLI config - -export ARDUINO_CONTENT ?= $(KALEIDOSCOPE_DIR)/.arduino -export ARDUINO_DIRECTORIES_DATA ?= $(ARDUINO_CONTENT)/data -export ARDUINO_DIRECTORIES_DOWNLOADS ?= $(ARDUINO_CONTENT)/downloads -export ARDUINO_DIRECTORIES_USER ?= $(ARDUINO_CONTENT)/user -export ARDUINO_CLI_CONFIG ?= $(ARDUINO_DIRECTORIES_DATA)/arduino-cli.yaml -export ARDUINO_BOARD_MANAGER_ADDITIONAL_URLS ?= https://raw.githubusercontent.com/keyboardio/boardsmanager/master/package_keyboardio_index.json - -system_arduino_cli=$(shell command -v arduino-cli || true) - -ifeq ($(system_arduino_cli),) -export ARDUINO_CLI ?= $(KALEIDOSCOPE_BIN_DIR)/arduino-cli -else -export ARDUINO_CLI ?= $(system_arduino_cli) -endif - -ifneq ($(VERBOSE),) -export ARDUINO_VERBOSE ?= --verbose -else -export ARDUINO_VERBOSE ?= -endif - -# This is horrible. But because make doesn't really support -# multi-line variables and we want to cache the full -# _arduino_props in a variable, which means letting make -# split the properties on space, which is what it converts -# newlines into. To make this go, we we need to replace interior -# spaces in the variables with something. We chose the fire -# emoji, since it accurately represents our feelings on this -# state of affairs. Later, when finding props, we need to reverse -# this process, turning fire into space. -_arduino_props = $(shell ${ARDUINO_CLI} compile --show-properties "$${SKETCH_FILE_PATH}"|perl -p -e"s/ /🔥/g") -$(call make-lazy,_arduino_props) - -_arduino_prop = $(subst $1=,,$(subst 🔥, ,$(filter $1=%,$(_arduino_props)))) - -# How to use_arduino_prop -# $(call _arduino_prop,recipe.hooks.sketch.prebuild.2.pattern) - - -# # Build path config TMPDIR ?= /tmp @@ -83,12 +35,6 @@ sketch_exists_p = $(realpath $(wildcard $(dir)/$(SKETCH_FILE_NAME))) export FQBN := $(call _arduino_prop,build.fqbn) -# Flashing related config -port = $(shell $(ARDUINO_CLI) board list --format=text | grep $(FQBN) |cut -d' ' -f 1) -flashing_instructions = $(call _arduino_prop,build.flashing_instructions) -ifeq ($(flashing_instructions),) -flashing_instructions = "If your keyboard needs you to do something to put it in flashing mode, do that now." -endif export BOOTLOADER_PATH := $(call _arduino_prop,runtime.platform.path)/bootloaders/$(call _arduino_prop,bootloader.file) @@ -124,7 +70,7 @@ export LIB_PROPERTIES_PATH := "../.." # We should use compiler.path instead of appending bin, but we # don't have substitution for arduino props yet -export COMPILER_PATH := $(call _arduino_prop,runtime.tools.avr-gcc.path)/bin +#export COMPILER_PATH := $(call _arduino_prop,runtime.tools.avr-gcc.path)/bin # Allow the compiler prefix to be empty for virtual builds COMPILER_PREFIX ?= avr- @@ -147,18 +93,6 @@ all: @: ## Do not remove this line, otherwise `make all` will trigger the `%` rule too. -install-arduino-cli: - curl -fsSL https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | BINDIR="$(KALEIDOSCOPE_BIN_DIR)" sh - -configure-arduino-cli: - $(ARDUINO_CLI) config init - -install-arduino-core-kaleidoscope: - $(ARDUINO_CLI) core install "keyboardio:avr" - -install-arduino-core-avr: - $(ARDUINO_CLI) core install "arduino:avr" - disassemble: ${ELF_FILE_PATH} ${AVR_OBJDUMP} -C -d "${ELF_FILE_PATH}" @@ -216,6 +150,11 @@ endif #but it's short some of the data we kind of need flash: + flashing_instructions := $(call _arduino_prop,build.flashing_instructions) +ifeq ($(flashing_instructions),) + flashing_instructions := "If your keyboard needs you to do something to put it in flashing mode, do that now." +endif + port = $(shell $(ARDUINO_CLI) board list --format=text | grep $(FQBN) |cut -d' ' -f 1) ifeq ($(port),) $(info Unable to detect keyboard serial port.) #@exit 1 diff --git a/examples/Devices/EZ/ErgoDox/Makefile b/examples/Devices/EZ/ErgoDox/Makefile index 5bc75ecf..132fa34a 100644 --- a/examples/Devices/EZ/ErgoDox/Makefile +++ b/examples/Devices/EZ/ErgoDox/Makefile @@ -16,4 +16,4 @@ endif KALEIDOSCOPE_ETC_DIR ?= $(ARDUINO_DIRECTORIES_USER)/hardware/keyboardio/avr/libraries/Kaleidoscope/etc/ -include $(KALEIDOSCOPE_ETC_DIR)/sketch-arduino-cli.mk +include $(KALEIDOSCOPE_ETC_DIR)/makefiles/sketch.mk diff --git a/examples/Devices/KBDFans/KBD4x/Makefile b/examples/Devices/KBDFans/KBD4x/Makefile index 5bc75ecf..132fa34a 100644 --- a/examples/Devices/KBDFans/KBD4x/Makefile +++ b/examples/Devices/KBDFans/KBD4x/Makefile @@ -16,4 +16,4 @@ endif KALEIDOSCOPE_ETC_DIR ?= $(ARDUINO_DIRECTORIES_USER)/hardware/keyboardio/avr/libraries/Kaleidoscope/etc/ -include $(KALEIDOSCOPE_ETC_DIR)/sketch-arduino-cli.mk +include $(KALEIDOSCOPE_ETC_DIR)/makefiles/sketch.mk diff --git a/examples/Devices/Keyboardio/Atreus/Makefile b/examples/Devices/Keyboardio/Atreus/Makefile index 5bc75ecf..132fa34a 100644 --- a/examples/Devices/Keyboardio/Atreus/Makefile +++ b/examples/Devices/Keyboardio/Atreus/Makefile @@ -16,4 +16,4 @@ endif KALEIDOSCOPE_ETC_DIR ?= $(ARDUINO_DIRECTORIES_USER)/hardware/keyboardio/avr/libraries/Kaleidoscope/etc/ -include $(KALEIDOSCOPE_ETC_DIR)/sketch-arduino-cli.mk +include $(KALEIDOSCOPE_ETC_DIR)/makefiles/sketch.mk diff --git a/examples/Devices/Keyboardio/Imago/Makefile b/examples/Devices/Keyboardio/Imago/Makefile index 5bc75ecf..132fa34a 100644 --- a/examples/Devices/Keyboardio/Imago/Makefile +++ b/examples/Devices/Keyboardio/Imago/Makefile @@ -16,4 +16,4 @@ endif KALEIDOSCOPE_ETC_DIR ?= $(ARDUINO_DIRECTORIES_USER)/hardware/keyboardio/avr/libraries/Kaleidoscope/etc/ -include $(KALEIDOSCOPE_ETC_DIR)/sketch-arduino-cli.mk +include $(KALEIDOSCOPE_ETC_DIR)/makefiles/sketch.mk diff --git a/examples/Devices/Keyboardio/Model01/Makefile b/examples/Devices/Keyboardio/Model01/Makefile index 5bc75ecf..132fa34a 100644 --- a/examples/Devices/Keyboardio/Model01/Makefile +++ b/examples/Devices/Keyboardio/Model01/Makefile @@ -16,4 +16,4 @@ endif KALEIDOSCOPE_ETC_DIR ?= $(ARDUINO_DIRECTORIES_USER)/hardware/keyboardio/avr/libraries/Kaleidoscope/etc/ -include $(KALEIDOSCOPE_ETC_DIR)/sketch-arduino-cli.mk +include $(KALEIDOSCOPE_ETC_DIR)/makefiles/sketch.mk diff --git a/examples/Devices/OLKB/Planck/Makefile b/examples/Devices/OLKB/Planck/Makefile index 5bc75ecf..132fa34a 100644 --- a/examples/Devices/OLKB/Planck/Makefile +++ b/examples/Devices/OLKB/Planck/Makefile @@ -16,4 +16,4 @@ endif KALEIDOSCOPE_ETC_DIR ?= $(ARDUINO_DIRECTORIES_USER)/hardware/keyboardio/avr/libraries/Kaleidoscope/etc/ -include $(KALEIDOSCOPE_ETC_DIR)/sketch-arduino-cli.mk +include $(KALEIDOSCOPE_ETC_DIR)/makefiles/sketch.mk diff --git a/examples/Devices/SOFTHRUF/Splitography/Makefile b/examples/Devices/SOFTHRUF/Splitography/Makefile index 5bc75ecf..132fa34a 100644 --- a/examples/Devices/SOFTHRUF/Splitography/Makefile +++ b/examples/Devices/SOFTHRUF/Splitography/Makefile @@ -16,4 +16,4 @@ endif KALEIDOSCOPE_ETC_DIR ?= $(ARDUINO_DIRECTORIES_USER)/hardware/keyboardio/avr/libraries/Kaleidoscope/etc/ -include $(KALEIDOSCOPE_ETC_DIR)/sketch-arduino-cli.mk +include $(KALEIDOSCOPE_ETC_DIR)/makefiles/sketch.mk diff --git a/examples/Devices/Technomancy/Atreus/Makefile b/examples/Devices/Technomancy/Atreus/Makefile index 5bc75ecf..132fa34a 100644 --- a/examples/Devices/Technomancy/Atreus/Makefile +++ b/examples/Devices/Technomancy/Atreus/Makefile @@ -16,4 +16,4 @@ endif KALEIDOSCOPE_ETC_DIR ?= $(ARDUINO_DIRECTORIES_USER)/hardware/keyboardio/avr/libraries/Kaleidoscope/etc/ -include $(KALEIDOSCOPE_ETC_DIR)/sketch-arduino-cli.mk +include $(KALEIDOSCOPE_ETC_DIR)/makefiles/sketch.mk diff --git a/examples/Devices/gHeavy/ButterStick/Makefile b/examples/Devices/gHeavy/ButterStick/Makefile index 5bc75ecf..132fa34a 100644 --- a/examples/Devices/gHeavy/ButterStick/Makefile +++ b/examples/Devices/gHeavy/ButterStick/Makefile @@ -16,4 +16,4 @@ endif KALEIDOSCOPE_ETC_DIR ?= $(ARDUINO_DIRECTORIES_USER)/hardware/keyboardio/avr/libraries/Kaleidoscope/etc/ -include $(KALEIDOSCOPE_ETC_DIR)/sketch-arduino-cli.mk +include $(KALEIDOSCOPE_ETC_DIR)/makefiles/sketch.mk diff --git a/examples/Devices/gHeavy/FaunchPad/Makefile b/examples/Devices/gHeavy/FaunchPad/Makefile index 5bc75ecf..132fa34a 100644 --- a/examples/Devices/gHeavy/FaunchPad/Makefile +++ b/examples/Devices/gHeavy/FaunchPad/Makefile @@ -16,4 +16,4 @@ endif KALEIDOSCOPE_ETC_DIR ?= $(ARDUINO_DIRECTORIES_USER)/hardware/keyboardio/avr/libraries/Kaleidoscope/etc/ -include $(KALEIDOSCOPE_ETC_DIR)/sketch-arduino-cli.mk +include $(KALEIDOSCOPE_ETC_DIR)/makefiles/sketch.mk diff --git a/examples/Internal/Sketch_Exploration/Makefile b/examples/Internal/Sketch_Exploration/Makefile index 5bc75ecf..132fa34a 100644 --- a/examples/Internal/Sketch_Exploration/Makefile +++ b/examples/Internal/Sketch_Exploration/Makefile @@ -16,4 +16,4 @@ endif KALEIDOSCOPE_ETC_DIR ?= $(ARDUINO_DIRECTORIES_USER)/hardware/keyboardio/avr/libraries/Kaleidoscope/etc/ -include $(KALEIDOSCOPE_ETC_DIR)/sketch-arduino-cli.mk +include $(KALEIDOSCOPE_ETC_DIR)/makefiles/sketch.mk diff --git a/testing/makefiles/delegate.mk b/testing/makefiles/delegate.mk index 5bc75ecf..132fa34a 100644 --- a/testing/makefiles/delegate.mk +++ b/testing/makefiles/delegate.mk @@ -16,4 +16,4 @@ endif KALEIDOSCOPE_ETC_DIR ?= $(ARDUINO_DIRECTORIES_USER)/hardware/keyboardio/avr/libraries/Kaleidoscope/etc/ -include $(KALEIDOSCOPE_ETC_DIR)/sketch-arduino-cli.mk +include $(KALEIDOSCOPE_ETC_DIR)/makefiles/sketch.mk