This is a complete rework of how Kaleidoscope is built, but should be largely transparent to most developers and completely invisible to folks using the Arduino IDE. Some advanced features of kaleidoscope-builder config files have gone away, but it’s likely that @algernon was the only person using them. The tradeoff is that we’re now using a much better maintained build tool under the hood and that we’re no longer as tied to a single specific directory structure.pull/936/head
parent
aaa9603d72
commit
d94c3d5234
@ -0,0 +1,7 @@
|
||||
#!/bin/sh
|
||||
if ! git diff --exit-code; then
|
||||
>&2 echo "'make astyle' found code style differences. Please make astyle and commit your changes"
|
||||
exit 1;
|
||||
fi
|
||||
exit 0;
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,4 @@
|
||||
#!/bin/sh
|
||||
|
||||
ASTYLE_IGNORE_PATTERN='testing/googletest/'
|
||||
find ./* -type f \( -name '*.h' -o -name '*.cpp' -o -name '*.ino' \) | grep -v "$ASTYLE_IGNORE_PATTERN" | xargs -n 1 astyle -q --style=google --unpad-paren --pad-header --pad-oper --indent-classes --indent=spaces=2 --max-continuation-indent=80
|
@ -0,0 +1,4 @@
|
||||
// this is a dummy sketch that's just here so that we can get
|
||||
// arduino-cli to give us properties for our platform if we
|
||||
// don't have a sketch, like happens when building parts of the
|
||||
// simulator test infrastructure
|
@ -0,0 +1,6 @@
|
||||
{
|
||||
"cpu": {
|
||||
"fqbn": "keyboardio:avr:keyboardio_atreus",
|
||||
"port": ""
|
||||
}
|
||||
}
|
@ -0,0 +1,148 @@
|
||||
mkfile_dir := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
|
||||
|
||||
ifeq ($(VERBOSE),)
|
||||
|
||||
ifeq ($(QUIET),)
|
||||
$(info Building in quiet mode. For a lot more informatiion, add 'VERBOSE=1' to the beginning of your call to $(MAKE))
|
||||
export QUIET = @
|
||||
endif
|
||||
|
||||
export ARDUINO_VERBOSE ?=
|
||||
else
|
||||
export ARDUINO_VERBOSE ?= --verbose
|
||||
endif
|
||||
|
||||
|
||||
|
||||
# Build path config
|
||||
TMPDIR ?= /tmp
|
||||
|
||||
export KALEIDOSCOPE_DIR ?= $(abspath $(mkfile_dir)/../..)
|
||||
KALEIDOSCOPE_BIN_DIR ?= $(KALEIDOSCOPE_DIR)/bin
|
||||
KALEIDOSCOPE_ETC_DIR ?= $(KALEIDOSCOPE_DIR)/etc
|
||||
|
||||
KALEIDOSCOPE_TEMP_PATH ?= $(TMPDIR)/kaleidoscope-$(USER)
|
||||
KALEIDOSCOPE_BUILD_PATH ?= $(KALEIDOSCOPE_TEMP_PATH)/build
|
||||
KALEIDOSCOPE_OUTPUT_PATH ?= $(KALEIDOSCOPE_TEMP_PATH)/output
|
||||
|
||||
CORE_CACHE_PATH ?= $(KALEIDOSCOPE_TEMP_PATH)/arduino-cores
|
||||
|
||||
|
||||
ARDUINO_CONTENT ?= $(KALEIDOSCOPE_DIR)/.arduino
|
||||
export ARDUINO_DIRECTORIES_DATA ?= $(ARDUINO_CONTENT)/data
|
||||
export ARDUINO_DIRECTORIES_DOWNLOADS ?= $(ARDUINO_CONTENT)/downloads
|
||||
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
|
||||
|
||||
# If it looks like Kaleidoscope is inside a "traditional" Arduino hardware directory
|
||||
# in the user's homedir, let's use that.
|
||||
|
||||
ifeq ($(shell uname -s),Darwin)
|
||||
traditional_path = $(HOME)/Documents/Arduino/
|
||||
else
|
||||
traditional_path = $(HOME)/Arduino/
|
||||
endif
|
||||
|
||||
# use realpath to compare the real absolute path of the kaleidoscope dir
|
||||
# and the arduino bundle, even if they're symlinked into the Arudino/hardware dir
|
||||
ifeq ($(realpath $(traditional_path)/hardware/keyboardio/avr/libraries/Kaleidoscope), $(realpath $(KALEIDOSCOPE_DIR)))
|
||||
export ARDUINO_DIRECTORIES_USER ?= $(traditional_path)
|
||||
endif
|
||||
# Otherwise, use the arduino-cli bundle
|
||||
export ARDUINO_DIRECTORIES_USER ?= $(ARDUINO_CONTENT)/user
|
||||
|
||||
# If we're not calling setup, we should freak out if the hardware
|
||||
# definitions don't exist
|
||||
|
||||
ifneq ($(MAKECMDGOALS),setup)
|
||||
|
||||
ifeq ($(wildcard $(ARDUINO_DIRECTORIES_USER)/hardware/keyboardio/avr/boards.txt),)
|
||||
|
||||
$(info Kaleidoscope hardware definitions not found in)
|
||||
$(info $(ARDUINO_DIRECTORIES_USER))
|
||||
$(info )
|
||||
$(info You may be able to resolve this issue by running the following command)
|
||||
$(info to initialize Kaleidoscope )
|
||||
$(info )
|
||||
$(info $(MAKE) -C $(KALEIDOSCOPE_DIR) setup )
|
||||
$(info )
|
||||
$(error )
|
||||
|
||||
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 ($(system_arduino_cli),)
|
||||
export ARDUINO_CLI_PATH ?= $(KALEIDOSCOPE_BIN_DIR)/arduino-cli
|
||||
else
|
||||
export ARDUINO_CLI_PATH ?= $(system_arduino_cli)
|
||||
endif
|
||||
|
||||
|
||||
export ARDUINO_CLI ?= $(arduino_env) $(ARDUINO_CLI_PATH)
|
||||
|
||||
ifneq ($(VERBOSE),)
|
||||
$(info Using ardino-cli from $(ARDUINO_CLI_PATH))
|
||||
endif
|
||||
|
||||
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 arduino-cli doesn't currently allow us to get props with
|
||||
# just an FQBN. We've filed a bug with them
|
||||
ifeq ($(SKETCH_FILE_PATH),)
|
||||
_arduino_props_sketch_arg = $(KALEIDOSCOPE_ETC_DIR)/dummy-sketch/
|
||||
else
|
||||
_arduino_props_sketch_arg = $(SKETCH_FILE_PATH)
|
||||
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 $(fqbn_arg) --show-properties "$(_arduino_props_sketch_arg)"|perl -p -e"s/ /🔥/g")
|
||||
|
||||
_arduino_prop = $(subst $1=,,$(subst 🔥, ,$(filter $1=%,$(_arduino_props))))
|
||||
|
||||
# How to use_arduino_prop
|
||||
# $(call _arduino_prop,recipe.hooks.sketch.prebuild.2.pattern)
|
||||
|
||||
ifneq ($(KALEIDOSCOPE_CCACHE),)
|
||||
ccache_wrapper_property := --build-properties "compiler.wrapper.cmd=ccache"
|
||||
endif
|
||||
|
||||
.PHONY: configure-arduino-cli install-arduino-core-kaleidoscope install-arduino-core-avr
|
||||
.PHONY: stupid-workaround-for-make-inclusion-semantics
|
||||
|
||||
stupid-workaround-for-make-inclusion-semantics: DEFAULT_GOAL
|
||||
@: # This is here so that the sketch makefile including this file doesn't
|
||||
@: # default to arduino-cli installation as its priamry target
|
||||
|
||||
$(KALEIDOSCOPE_BIN_DIR)/arduino-cli:
|
||||
$(QUIET) curl -fsSL https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | BINDIR="$(KALEIDOSCOPE_BIN_DIR)" sh
|
||||
|
||||
install-arduino-cli: $(KALEIDOSCOPE_BIN_DIR)/arduino-cli
|
||||
|
||||
configure-arduino-cli:
|
||||
$(QUIET) $(ARDUINO_CLI) config init
|
||||
|
||||
install-arduino-core-kaleidoscope:
|
||||
$(QUIET) $(ARDUINO_CLI) core install "keyboardio:avr"
|
||||
|
||||
install-arduino-core-avr:
|
||||
$(QUIET) $(ARDUINO_CLI) core install "arduino:avr"
|
||||
|
@ -0,0 +1,211 @@
|
||||
mkfile_dir := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
|
||||
|
||||
# If the sketch is defined
|
||||
ifneq ($(SKETCH),)
|
||||
# If the sketch isn't a directory, we want to get the directory the sketch is in
|
||||
ifeq ($(wildcard $(SKETCH)/.),)
|
||||
SKETCH_DIR := $(dir $(SKETCH))
|
||||
endif
|
||||
else
|
||||
# If the sketch wasn't defined as we came in, assume the current directory
|
||||
# is where we're looking
|
||||
SKETCH_DIR := $(realpath $(CURDIR))
|
||||
endif
|
||||
|
||||
SKETCH_BASE_NAME := $(notdir $(SKETCH_DIR))
|
||||
SKETCH_FILE_NAME := $(addsuffix .ino, $(SKETCH_BASE_NAME))
|
||||
|
||||
# Find the path of the sketch file
|
||||
SKETCH_DIR_CANDIDATES = $(sketch_dir) src/ .
|
||||
sketch_exists_p = $(realpath $(wildcard $(dir)/$(SKETCH_FILE_NAME)))
|
||||
SKETCH_FILE_PATH := $(firstword $(foreach dir,$(SKETCH_DIR_CANDIDATES),$(sketch_exists_p)))
|
||||
|
||||
include $(mkfile_dir)/arduino-cli.mk
|
||||
|
||||
ifeq ($(FQBN),)
|
||||
export FQBN = $(call _arduino_prop,build.fqbn)
|
||||
ifneq ($(VERBOSE),)
|
||||
$(info Arduino provided FQBN $(call _arduino_prop,build.fqbn))
|
||||
endif
|
||||
endif
|
||||
|
||||
# We -could- check to see if sketch-dir is in git before running this command
|
||||
# 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)
|
||||
|
||||
|
||||
BUILD_PATH ?= $(KALEIDOSCOPE_BUILD_PATH)/$(SKETCH_IDENTIFIER)
|
||||
OUTPUT_PATH ?= $(KALEIDOSCOPE_OUTPUT_PATH)/$(SKETCH_IDENTIFIER)
|
||||
|
||||
|
||||
OUTPUT_FILE_PREFIX := $(SKETCH_BASE_NAME)-$(GIT_VERSION)
|
||||
HEX_FILE_PATH := $(OUTPUT_PATH)/$(OUTPUT_FILE_PREFIX).hex
|
||||
HEX_FILE_WITH_BOOTLOADER_PATH := $(OUTPUT_PATH)/$(OUTPUT_FILE_PREFIX)-with-bootloader.hex
|
||||
ELF_FILE_PATH := $(OUTPUT_PATH)/$(OUTPUT_FILE_PREFIX).elf
|
||||
LIB_FILE_PATH := $(OUTPUT_PATH)/$(OUTPUT_FILE_PREFIX).a
|
||||
|
||||
|
||||
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_fqbn = $(firstword $(possible_fqbns))
|
||||
|
||||
$(info *************************************************************** )
|
||||
$(info )
|
||||
$(info Arduino couldn't figure out what kind of device this sketch )
|
||||
$(info is for. Usually, Arduino looks in a file called `sketch.json` )
|
||||
$(info to figure this out. )
|
||||
ifneq ($(possible_fqbn),)
|
||||
|
||||
fake_var_to_run_shell := $(shell $(ARDUINO_CLI) board attach $(possible_fqbn))
|
||||
|
||||
$(info )
|
||||
$(info I have detected a connected device supported by Kaleidoscope and)
|
||||
$(info attepted to automatically resolve this issue by running the)
|
||||
$(info following command:)
|
||||
$(info )
|
||||
$(info $(ARDUINO_CLI) board attach $(possible_fqbn))
|
||||
$(info )
|
||||
$(info If the build fails or $(possible_fqbn) doesn't)
|
||||
$(info look like your keyboard, you may need to manually edit your)
|
||||
$(info `sketch.json` file or run )
|
||||
$(info )
|
||||
$(info $(ARDUINO_CLI) board attach )
|
||||
$(info )
|
||||
$(info manually, specifying the FQBN for your keyboard. )
|
||||
$(info )
|
||||
$(info *************************************************************** )
|
||||
|
||||
else
|
||||
|
||||
$(info )
|
||||
$(info I'm unable to detect your keyboard, you may need to manually )
|
||||
$(info edit your `sketch.json` file or run )
|
||||
$(info )
|
||||
$(info $(ARDUINO_CLI) board attach )
|
||||
$(info )
|
||||
$(info manually, specifying the FQBN for your keyboard. )
|
||||
$(info )
|
||||
$(info *************************************************************** )
|
||||
$(error )
|
||||
|
||||
endif
|
||||
endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# Flashing related config
|
||||
ifneq ($(FQBN),)
|
||||
KALEIDOSCOPE_DEVICE_PORT ?= $(shell $(ARDUINO_CLI) board list --format=text | grep $(FQBN) |cut -d' ' -f 1)
|
||||
endif
|
||||
|
||||
flashing_instructions := $(shell printf $(call _arduino_prop,build.flashing_instructions))
|
||||
ifeq ($(flashing_instructions),)
|
||||
flashing_instruction := "If your keyboard needs you to do something to put it in flashing mode, do that now."
|
||||
endif
|
||||
|
||||
DEFAULT_GOAL: compile
|
||||
|
||||
|
||||
#$(SKETCH_FILE_PATH):
|
||||
# @: # dummy recipe for the sketch file
|
||||
|
||||
|
||||
.PHONY: compile configure-arduino-cli install-arduino-core-kaleidoscope install-arduino-core-avr
|
||||
.PHONY: disassemble decompile size-map flash clean all test
|
||||
|
||||
all: compile
|
||||
@: ## Do not remove this line, otherwise `make all` will trigger the `%` rule too.
|
||||
|
||||
|
||||
disassemble: ${ELF_FILE_PATH}
|
||||
$(call _arduino_prop,compiler.objdump.cmd) \
|
||||
$(call _arduino_prop,compiler.objdump.flags) \
|
||||
"${ELF_FILE_PATH}"
|
||||
|
||||
size-map: ${ELF_FILE_PATH}
|
||||
$(call _arduino_prop,compiler.size-map.cmd) \
|
||||
$(call _arduino_prop,compiler.size-map.flags) \
|
||||
"${ELF_FILE_PATH}"
|
||||
|
||||
flash: ${HEX_FILE_PATH}
|
||||
|
||||
${ELF_FILE_PATH}: compile
|
||||
${HEX_FILE_PATH}: compile
|
||||
|
||||
|
||||
BOOTLOADER_PATH := $(call _arduino_prop,runtime.platform.path)/bootloaders/$(call _arduino_prop,bootloader.file)
|
||||
|
||||
hex-with-bootloader: ${HEX_FILE_PATH}
|
||||
$(QUIET) awk '/^:00000001FF/ == 0' "${HEX_FILE_PATH}" >"${HEX_FILE_WITH_BOOTLOADER_PATH}"
|
||||
$(QUIET) cat "${BOOTLOADER_PATH}" >>"${HEX_FILE_WITH_BOOTLOADER_PATH}"
|
||||
$(QUIET) ln -sf -- "${OUTPUT_FILE_PREFIX}-with-bootloader.hex" "${OUTPUT_PATH}/${SKETCH_BASE_NAME}-latest-with-bootloader.hex"
|
||||
$(info Combined firmware and bootloader are now at)
|
||||
$(info ${HEX_FILE_WITH_BOOTLOADER_PATH})
|
||||
$(info )
|
||||
$(info Make sure you have the bootloader version you expect.)
|
||||
$(info )
|
||||
$(info )
|
||||
$(info And TEST THIS ON REAL HARDWARE BEFORE YOU GIVE IT TO ANYONE.)
|
||||
|
||||
clean:
|
||||
$(QUIET) rm -rf -- "${OUTPUT_PATH}"/*
|
||||
|
||||
|
||||
ifneq ($(LOCAL_CFLAGS),)
|
||||
local_cflags_property = --build-properties "compiler.cpp.extra_flags=${LOCAL_CFLAGS}"
|
||||
else
|
||||
local_cflags_property =
|
||||
endif
|
||||
|
||||
compile:
|
||||
$(QUIET) install -d "${OUTPUT_PATH}"
|
||||
$(QUIET) $(ARDUINO_CLI) compile --fqbn "${FQBN}" ${ARDUINO_VERBOSE} --warnings all ${ccache_wrapper_property} ${local_cflags_property} \
|
||||
--libraries "${KALEIDOSCOPE_PLATFORM_LIB_DIR}" \
|
||||
--build-path "${BUILD_PATH}" \
|
||||
--output-dir "${OUTPUT_PATH}" \
|
||||
--build-cache-path "${CORE_CACHE_PATH}" \
|
||||
"${SKETCH_FILE_PATH}"
|
||||
ifeq ($(LIBONLY),)
|
||||
$(QUIET) cp "${BUILD_PATH}/${SKETCH_FILE_NAME}.hex" "${HEX_FILE_PATH}"
|
||||
$(QUIET) cp "${BUILD_PATH}/${SKETCH_FILE_NAME}.elf" "${ELF_FILE_PATH}"
|
||||
$(QUIET) ln -sf "${OUTPUT_FILE_PREFIX}.hex" "${OUTPUT_PATH}/${SKETCH_BASE_NAME}-latest.hex"
|
||||
$(QUIET) ln -sf "${OUTPUT_FILE_PREFIX}.elf" "${OUTPUT_PATH}/${SKETCH_BASE_NAME}-latest.elf"
|
||||
else
|
||||
$(QUIET) cp "${BUILD_PATH}/${SKETCH_FILE_NAME}.a" "${LIB_FILE_PATH}"
|
||||
$(QUIET) ln -sf "${OUTPUT_FILE_PREFIX}.a" "${OUTPUT_PATH}/${SKETCH_BASE_NAME}-latest.a"
|
||||
endif
|
||||
ifneq ($(VERBOSE),)
|
||||
$(info Build artifacts can be found in ${BUILD_PATH})
|
||||
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 )
|
||||
endif
|
||||
$(info $(flashing_instructions))
|
||||
$(info )
|
||||
$(info When you're ready to proceed, press 'Enter'.)
|
||||
$(info )
|
||||
@$(shell read)
|
||||
$(QUIET) $(ARDUINO_CLI) upload --fqbn $(FQBN) \
|
||||
--input-dir "${OUTPUT_PATH}" \
|
||||
--port $(KALEIDOSCOPE_DEVICE_PORT) $(ARDUINO_VERBOSE)
|
Loading…
Reference in new issue