diff --git a/Makefile b/Makefile index 6a29f9a6..c1996bc0 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ -# This stub makefile for a Kaleidoscope plugin pulls in -# all targets from the Kaleidoscope-Plugin library +mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST))) +mkfile_dir := $(dir $(mkfile_path)) UNAME_S := $(shell uname -s) @@ -19,15 +19,8 @@ endif # the hardware directory can be determined in relation to the position of # this Makefile. -KALEIDOSCOPE_ETC_DIR ?= $(ARDUINO_DIRECTORIES_USER)/hardware/keyboardio/avr/libraries/Kaleidoscope/etc/ - -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)/makefiles/arduino-cli.mk +KALEIDOSCOPE_ETC_DIR := $(mkfile_dir)/etc +include $(mkfile_dir)/etc/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 @@ -113,4 +106,4 @@ clean: $(SMOKE_SKETCHES): force - $(MAKE) -C $@ -f $(KALEIDOSCOPE_ETC_DIR)/makefiles/sketch.mk compile + $(MAKE) -C $@ -f $(KALEIDOSCOPE_ETC_DIR)/makefiles/sketch.mk compile diff --git a/etc/makefiles/arduino-cli-prop.mk b/etc/makefiles/arduino-cli-prop.mk deleted file mode 100644 index 9347c3ed..00000000 --- a/etc/makefiles/arduino-cli-prop.mk +++ /dev/null @@ -1,46 +0,0 @@ -mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST))) -mkfile_dir := $(dir $(mkfile_path)) - -include $(mkfile_dir)/kaleidoscope-env.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)) - -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 - -# 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. -ifneq ($(FQBN),) -fqbn_arg = --fqbn $(FQBN) -endif - -# if we don't have a sketch, make a pretend one so we can run --show properties -# This is because aruduino-cli doesn't currently allow us to get props with -# just an FQBN. We've filed a bug with them -ifeq ($(SKETCH_FILE_PATH),) -_arudino_props_sketch_arg = $(KALEIDOSCOPE_ETC_DIR)/dummy-sketch/ -else -_arudino_props_sketch_arg = $(SKETCH_FILE_PATH) -endif - -_arduino_props = $(shell ${ARDUINO_CLI} compile $(fqbn_arg) --show-properties "$(_arduino_props_sketch_arg)"|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) diff --git a/etc/makefiles/arduino-cli.mk b/etc/makefiles/arduino-cli.mk index 507ee1c4..bfd050d5 100644 --- a/etc/makefiles/arduino-cli.mk +++ b/etc/makefiles/arduino-cli.mk @@ -1,8 +1,66 @@ mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST))) mkfile_dir := $(dir $(mkfile_path)) -include $(mkfile_dir)/arduino-cli-prop.mk +KALEIDOSCOPE_DIR ?= $(abspath $(mkfile_dir)/../..) +KALEIDOSCOPE_BIN_DIR ?= $(KALEIDOSCOPE_DIR)/bin +KALEIDOSCOPE_ETC_DIR ?= $(KALEIDOSCOPE_DIR)/etc +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 + +ifneq ($(VERBOSE),) +export ARDUINO_VERBOSE ?= --verbose +else +export ARDUINO_VERBOSE ?= +endif + + + +# 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)) + +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 + +# 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. +ifneq ($(FQBN),) +fqbn_arg = --fqbn $(FQBN) +endif + +# if we don't have a sketch, make a pretend one so we can run --show properties +# This is because aruduino-cli doesn't currently allow us to get props with +# just an FQBN. We've filed a bug with them +ifeq ($(SKETCH_FILE_PATH),) +_arudino_props_sketch_arg = $(KALEIDOSCOPE_ETC_DIR)/dummy-sketch/ +else +_arudino_props_sketch_arg = $(SKETCH_FILE_PATH) +endif + +_arduino_props = $(shell ${ARDUINO_CLI} compile $(fqbn_arg) --show-properties "$(_arduino_props_sketch_arg)"|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 .PHONY: all diff --git a/etc/makefiles/kaleidoscope-env.mk b/etc/makefiles/kaleidoscope-env.mk deleted file mode 100644 index be002715..00000000 --- a/etc/makefiles/kaleidoscope-env.mk +++ /dev/null @@ -1,20 +0,0 @@ -mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST))) -mkfile_dir := $(dir $(mkfile_path)) - -export KALEIDOSCOPE_DIR ?= $(abspath $(mkfile_dir)/../..) -export KALEIDOSCOPE_BIN_DIR ?= $(KALEIDOSCOPE_DIR)/bin -export KALEIDOSCOPE_ETC_DIR ?= $(KALEIDOSCOPE_DIR)/etc - -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 - -ifneq ($(VERBOSE),) -export ARDUINO_VERBOSE ?= --verbose -else -export ARDUINO_VERBOSE ?= -endif - diff --git a/testing/makefiles/libcommon.mk b/testing/makefiles/libcommon.mk index 2a74ff01..cd6ff52e 100644 --- a/testing/makefiles/libcommon.mk +++ b/testing/makefiles/libcommon.mk @@ -1,7 +1,7 @@ top_dir := $(dir $(lastword ${MAKEFILE_LIST}))../.. build_dir := ${top_dir}/_build -include $(top_dir)/etc/makefiles/arduino-cli-prop.mk +include $(top_dir)/etc/makefiles/arduino-cli.mk bundle_path = ${ARDUINO_DIRECTORIES_USER}/hardware/keyboardio/avr/libraries diff --git a/testing/makefiles/testcase.mk b/testing/makefiles/testcase.mk index c5882ca9..e2889ebc 100644 --- a/testing/makefiles/testcase.mk +++ b/testing/makefiles/testcase.mk @@ -1,6 +1,6 @@ top_dir := $(dir $(lastword ${MAKEFILE_LIST}))../.. -include $(top_dir)/etc/makefiles/arduino-cli-prop.mk +include $(top_dir)/etc/makefiles/arduino-cli.mk build_dir := ${top_dir}/_build/${testcase}