From 66b225d1d05389a3d62556484bc68eaf4723f599 Mon Sep 17 00:00:00 2001 From: Jesse Vincent Date: Mon, 16 Nov 2020 12:44:05 -0800 Subject: [PATCH] break out prop fetching to its own file --- etc/makefiles/arduino-cli-prop.mk | 31 +++++++++++++++++++++++++++++++ etc/makefiles/arduino-cli.mk | 23 +---------------------- 2 files changed, 32 insertions(+), 22 deletions(-) create mode 100644 etc/makefiles/arduino-cli-prop.mk diff --git a/etc/makefiles/arduino-cli-prop.mk b/etc/makefiles/arduino-cli-prop.mk new file mode 100644 index 00000000..51f07966 --- /dev/null +++ b/etc/makefiles/arduino-cli-prop.mk @@ -0,0 +1,31 @@ +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)) + +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. +_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) diff --git a/etc/makefiles/arduino-cli.mk b/etc/makefiles/arduino-cli.mk index 7674c447..8b86f7ea 100644 --- a/etc/makefiles/arduino-cli.mk +++ b/etc/makefiles/arduino-cli.mk @@ -1,9 +1,6 @@ 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)) +include $(mkfile_dir)/arduino-cli-prop.mk export KALEIDOSCOPE_DIR ?= $(abspath $(mkfile_dir)/../..) export KALEIDOSCOPE_BIN_DIR ?= $(KALEIDOSCOPE_DIR)/bin @@ -31,25 +28,7 @@ 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 .PHONY: all