|
|
|
@ -26,15 +26,17 @@ absolute_filename() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
build_version () {
|
|
|
|
|
GIT_VERSION="$(cd "${SKETCH_DIR}"; if [ -d .git ]; then echo -n '-g' && git describe --abbrev=4 --dirty --always; fi)"
|
|
|
|
|
LIB_PROPERTIES_PATH="${LIB_PROPERTIES_PATH:-"../.."}"
|
|
|
|
|
GIT_VERSION="$(cd "${SKETCH_DIR}"; if [ -d .git ]; then echo -n '-g' && git describe --abbrev=4 --dirty --always; fi)"
|
|
|
|
|
LIB_VERSION="$(cd "${SKETCH_DIR}"; (grep version= "${LIB_PROPERTIES_PATH}/library.properties" 2>/dev/null || echo version=0.0.0) | cut -d= -f2)${GIT_VERSION}"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
build_paths() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# We need that echo because we\re piping to cksum
|
|
|
|
|
# shellcheck disable=SC2005
|
|
|
|
|
SKETCH_IDENTIFIER="$(echo "$(absolute_filename "${SKETCH_DIR}/${SKETCH}.ino")" | cksum | cut -d ' ' -f 1)-${SKETCH}.ino"
|
|
|
|
|
SKETCH_IDENTIFIER="$(echo "${SKETCH_FILE_PATH}" | cksum | cut -d ' ' -f 1)-${SKETCH_FILE_NAME}"
|
|
|
|
|
KALEIDOSCOPE_TEMP_PATH="${KALEIDOSCOPE_TEMP_PATH:-${TMPDIR:-/tmp}/kaleidoscope-${USER}}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -55,7 +57,7 @@ build_paths() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
build_filenames () {
|
|
|
|
|
OUTPUT_FILE_PREFIX="${OUTPUT_FILE_PREFIX:-${SKETCH}-${LIB_VERSION}}"
|
|
|
|
|
OUTPUT_FILE_PREFIX="${OUTPUT_FILE_PREFIX:-${SKETCH_BASE_NAME}-${LIB_VERSION}}"
|
|
|
|
|
HEX_FILE_PATH="${HEX_FILE_PATH:-${OUTPUT_PATH}/${OUTPUT_FILE_PREFIX}.hex}"
|
|
|
|
|
HEX_FILE_WITH_BOOTLOADER_PATH="${HEX_FILE_WITH_BOOTLOADER_PATH:-${OUTPUT_PATH}/${OUTPUT_FILE_PREFIX}-with-bootloader.hex}"
|
|
|
|
|
ELF_FILE_PATH="${ELF_FILE_PATH:-${OUTPUT_PATH}/${OUTPUT_FILE_PREFIX}.elf}"
|
|
|
|
@ -105,9 +107,10 @@ firmware_size () {
|
|
|
|
|
return
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
MAX_PROG_SIZE=${MAX_PROG_SIZE:-$(get_arduino_pref 'upload.maximum_size')}
|
|
|
|
|
|
|
|
|
|
## This is a terrible hack, please don't hurt me. - algernon
|
|
|
|
|
|
|
|
|
|
find_max_prog_size
|
|
|
|
|
set +e
|
|
|
|
|
raw_output=$("$@" 2> /dev/null)
|
|
|
|
|
rc=$?
|
|
|
|
@ -130,23 +133,21 @@ firmware_size () {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
find_sketch () {
|
|
|
|
|
SKETCH="${SKETCH:-${DEFAULT_SKETCH}}"
|
|
|
|
|
LIBRARY="${LIBRARY:-${SKETCH}}"
|
|
|
|
|
if [ -z "${SKETCH}" ] || [ -z "${LIBRARY}" ] || [ -z "${ROOT}" ] || [ -z "${SOURCEDIR}" ]; then
|
|
|
|
|
echo "SKETCH, LIBRARY, SOURCEDIR, and ROOT need to be set before including this file!" >&2
|
|
|
|
|
if [ -z "${SKETCH}" ]; then
|
|
|
|
|
echo "SKETCH needs to be set before including this file!" >&2
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
SKETCH_DIR="$SKETCH"
|
|
|
|
|
SKETCH_FILE=$(basename "$SKETCH")
|
|
|
|
|
SKETCH_DIR="${SKETCH}"
|
|
|
|
|
SKETCH_BASE_NAME=$(basename "$SKETCH")
|
|
|
|
|
SKETCH_FILE_NAME="${SKETCH_BASE_NAME}.ino"
|
|
|
|
|
|
|
|
|
|
for path in "${SKETCH_DIR}" \
|
|
|
|
|
"examples/${LIBRARY}" \
|
|
|
|
|
"src" \
|
|
|
|
|
"."; do
|
|
|
|
|
if [ -f "${path}/${SKETCH_FILE}.ino" ]; then
|
|
|
|
|
if [ -f "${path}/${SKETCH_FILE_NAME}" ]; then
|
|
|
|
|
SKETCH_DIR="${path}"
|
|
|
|
|
SKETCH="${SKETCH_FILE}"
|
|
|
|
|
SKETCH_FILE_PATH=$(absolute_filename "${SKETCH_DIR}/${SKETCH_FILE_NAME}")
|
|
|
|
|
return
|
|
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
@ -301,6 +302,13 @@ flash_with_programmer() {
|
|
|
|
|
"-Uflash:w:${HEX_FILE_PATH}:i"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
find_bootloader_path() {
|
|
|
|
|
BOOTLOADER_FILE=$( get_arduino_pref 'bootloader.file' )
|
|
|
|
|
BOOTLOADER_FILE="${BOOTLOADER_FILE:-caterina/Caterina.hex}"
|
|
|
|
|
BOOTLOADER_PATH="${BOOTLOADER_PATH:-${BOARD_HARDWARE_PATH}/keyboardio/avr/bootloaders/${BOOTLOADER_FILE}}"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
hex_with_bootloader () {
|
|
|
|
|
if [ ! -e "${HEX_FILE_PATH}" ]; then
|
|
|
|
|
compile
|
|
|
|
@ -312,7 +320,7 @@ hex_with_bootloader () {
|
|
|
|
|
echo "Using ${BOOTLOADER_PATH}"
|
|
|
|
|
${MD5} "${BOOTLOADER_PATH}"
|
|
|
|
|
cat "${BOOTLOADER_PATH}" >> "${HEX_FILE_WITH_BOOTLOADER_PATH}"
|
|
|
|
|
ln -sf -- "${OUTPUT_FILE_PREFIX}-with-bootloader.hex" "${OUTPUT_PATH}/${SKETCH}-latest-with-bootloader.hex"
|
|
|
|
|
ln -sf -- "${OUTPUT_FILE_PREFIX}-with-bootloader.hex" "${OUTPUT_PATH}/${SKETCH_BASE_NAME}-latest-with-bootloader.hex"
|
|
|
|
|
cat <<- EOF
|
|
|
|
|
|
|
|
|
|
Combined firmware and bootloader are now at ${HEX_FILE_WITH_BOOTLOADER_PATH}
|
|
|
|
@ -332,7 +340,6 @@ maybe_build () {
|
|
|
|
|
# then rebuild. This is not as correct as letting make check our dependencies
|
|
|
|
|
# But it's less broken for most user use cases
|
|
|
|
|
# TODO(anyone): Make this suck less
|
|
|
|
|
SKETCH_FILE_PATH=$(absolute_filename "${SKETCH_DIR}/${SKETCH}.ino")
|
|
|
|
|
if [ "${HEX_FILE_PATH}" -ot "${SKETCH_FILE_PATH}" ]; then
|
|
|
|
|
build "$@"
|
|
|
|
|
fi
|
|
|
|
@ -359,7 +366,7 @@ compile () {
|
|
|
|
|
|
|
|
|
|
install -d "${OUTPUT_PATH}"
|
|
|
|
|
|
|
|
|
|
echo "Building ${SKETCH_DIR}/${SKETCH}"
|
|
|
|
|
echo "Building ${SKETCH_FILE_PATH}"
|
|
|
|
|
|
|
|
|
|
# This is defined in the (optional) user config.
|
|
|
|
|
# shellcheck disable=SC2154
|
|
|
|
@ -410,7 +417,7 @@ compile () {
|
|
|
|
|
-tools "${ARDUINO_PATH}/tools-builder" \
|
|
|
|
|
-fqbn "${FQBN}" \
|
|
|
|
|
-libraries "." \
|
|
|
|
|
-libraries "${ROOT}" \
|
|
|
|
|
-libraries "${KALEIDOSCOPE_DIR}" \
|
|
|
|
|
-libraries "${BOARD_HARDWARE_PATH}/.." \
|
|
|
|
|
${local_LIBS} \
|
|
|
|
|
${EXTRA_BUILDER_ARGS} \
|
|
|
|
@ -428,16 +435,16 @@ compile () {
|
|
|
|
|
-warnings all \
|
|
|
|
|
${ARDUINO_VERBOSE} \
|
|
|
|
|
${ARDUINO_AVR_GCC_PREFIX_PARAM} \
|
|
|
|
|
"${SKETCH_DIR}/${SKETCH}.ino"
|
|
|
|
|
"${SKETCH_FILE_PATH}"
|
|
|
|
|
|
|
|
|
|
if [ -z "${LIBONLY}" ]; then
|
|
|
|
|
cp "${BUILD_PATH}/${SKETCH}.ino.hex" "${HEX_FILE_PATH}"
|
|
|
|
|
cp "${BUILD_PATH}/${SKETCH}.ino.elf" "${ELF_FILE_PATH}"
|
|
|
|
|
ln -sf "${OUTPUT_FILE_PREFIX}.hex" "${OUTPUT_PATH}/${SKETCH}-latest.hex"
|
|
|
|
|
ln -sf "${OUTPUT_FILE_PREFIX}.elf" "${OUTPUT_PATH}/${SKETCH}-latest.elf"
|
|
|
|
|
cp "${BUILD_PATH}/${SKETCH_FILE_NAME}.hex" "${HEX_FILE_PATH}"
|
|
|
|
|
cp "${BUILD_PATH}/${SKETCH_FILE_NAME}.elf" "${ELF_FILE_PATH}"
|
|
|
|
|
ln -sf "${OUTPUT_FILE_PREFIX}.hex" "${OUTPUT_PATH}/${SKETCH_BASE_NAME}-latest.hex"
|
|
|
|
|
ln -sf "${OUTPUT_FILE_PREFIX}.elf" "${OUTPUT_PATH}/${SKETCH_BASE_NAME}-latest.elf"
|
|
|
|
|
else
|
|
|
|
|
cp "${BUILD_PATH}/${SKETCH}.ino.a" "${LIB_FILE_PATH}"
|
|
|
|
|
ln -sf "${OUTPUT_FILE_PREFIX}.a" "${OUTPUT_PATH}/${SKETCH}-latest.a"
|
|
|
|
|
cp "${BUILD_PATH}/${SKETCH_FILE_NAME}.a" "${LIB_FILE_PATH}"
|
|
|
|
|
ln -sf "${OUTPUT_FILE_PREFIX}.a" "${OUTPUT_PATH}/${SKETCH_BASE_NAME}-latest.a"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if [ "${ARDUINO_VERBOSE}" = "-verbose" ]; then
|
|
|
|
@ -473,7 +480,6 @@ build_all () {
|
|
|
|
|
|
|
|
|
|
for plugin in ${plugins}; do
|
|
|
|
|
export SKETCH="${plugin}"
|
|
|
|
|
export LIBRARY="${plugin}"
|
|
|
|
|
$0 "${plugin}" build
|
|
|
|
|
done
|
|
|
|
|
}
|
|
|
|
@ -484,7 +490,6 @@ compile_all () {
|
|
|
|
|
|
|
|
|
|
for plugin in ${plugins}; do
|
|
|
|
|
export SKETCH="${plugin}"
|
|
|
|
|
export LIBRARY="${plugin}"
|
|
|
|
|
$0 "${plugin}" compile
|
|
|
|
|
done
|
|
|
|
|
}
|
|
|
|
@ -495,7 +500,7 @@ size () {
|
|
|
|
|
compile
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
echo "- Size: firmware/${LIBRARY}/${OUTPUT_FILE_PREFIX}.elf"
|
|
|
|
|
echo "- Size: ${ELF_FILE_PATH}"
|
|
|
|
|
# shellcheck disable=SC2086
|
|
|
|
|
firmware_size "${AVR_SIZE}" ${AVR_SIZE_FLAGS} "${ELF_FILE_PATH}"
|
|
|
|
|
echo
|
|
|
|
@ -650,8 +655,13 @@ fi
|
|
|
|
|
##
|
|
|
|
|
## - if there is only one argument, that's a command
|
|
|
|
|
|
|
|
|
|
ROOT="$(cd "$(dirname "$0")"/..; pwd)"
|
|
|
|
|
export ROOT
|
|
|
|
|
KALEIDOSCOPE_DIR="$(cd "$(dirname "$0")"/..; pwd)"
|
|
|
|
|
# shellcheck disable=SC2034
|
|
|
|
|
KALEIDOSCOPE_BIN_DIR="${KALEIDOSCOPE_DIR}/bin/"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# shellcheck disable=SC2155
|
|
|
|
|
export SOURCEDIR="$(pwd)"
|
|
|
|
|
|
|
|
|
@ -671,7 +681,7 @@ if [ -e "${SOURCEDIR}/kaleidoscope-builder.conf" ]; then
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# shellcheck disable=SC1090
|
|
|
|
|
. "${ROOT}/etc/kaleidoscope-builder.conf"
|
|
|
|
|
. "${KALEIDOSCOPE_DIR}/etc/kaleidoscope-builder.conf"
|
|
|
|
|
|
|
|
|
|
if [ -n "${VERBOSE}" ] && [[ "${VERBOSE}" -gt 0 ]]; then
|
|
|
|
|
ARDUINO_VERBOSE="-verbose"
|
|
|
|
@ -723,11 +733,6 @@ for i in $(seq 1 $#); do
|
|
|
|
|
shift
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
LIBRARY="${SKETCH}"
|
|
|
|
|
|
|
|
|
|
export SKETCH
|
|
|
|
|
export LIBRARY
|
|
|
|
|
|
|
|
|
|
for cmd in ${cmds}; do
|
|
|
|
|
${cmd}
|
|
|
|
|
done
|
|
|
|
|