extract sketch detection to makefile

tmp/arduino-cli-pre-rebase
Jesse Vincent 4 years ago
parent c44eb57f05
commit 712db15f3e
No known key found for this signature in database
GPG Key ID: CC228463465E40BC

@ -133,31 +133,11 @@ _absolute_filename() {
}
_find_sketch() {
# If we got a path to the .ino, get the directory we really want
if [[ -n "$SKETCH" && -f "$SKETCH" ]]; then
SKETCH="$(dirname "$SKETCH")"
fi
SKETCH_DIR="${SKETCH:-$(_absolute_filename "$(pwd)")}"
SKETCH_BASE_NAME=$(basename "${SKETCH_DIR}")
SKETCH_FILE_NAME="${SKETCH_BASE_NAME}.ino"
# Arduino sketches are usually a file inside directory Foo named Foo.ino, so try that as a fallback
for dir in \
"${SKETCH_DIR}" \
"src/" \
"."; do
if [ -f "${dir}/${SKETCH_FILE_NAME}" ]; then
SKETCH_DIR="${dir}"
SKETCH_FILE_PATH=$(_absolute_filename "${dir}/${SKETCH_FILE_NAME}")
return
fi
done
if [ -z ${SKETCH_FILE_PATH} ] || [ ! -f ${SKETCH_FILE_PATH} ]; then
# Didn't find a sketch
echo "I couldn't find your sketch (.ino file)" >&2
exit 1
fi
}

@ -39,12 +39,32 @@ export KALEIDOSCOPE_OUTPUT_PATH ?= $(KALEIDOSCOPE_TEMP_PATH)/output
export CORE_CACHE_PATH ?= $(KALEIDOSCOPE_TEMP_PATH)/arduino-cores
# 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
export SKETCH_BASE_NAME := $(notdir $(sketch_dir))
export SKETCH_FILE_NAME := $(addsuffix .ino, $(SKETCH_BASE_NAME))
sketch_dir_candidates = $(sketch_dir) src/ .
sketch_exists_p = $(realpath $(wildcard $(dir)/$(SKETCH_FILE_NAME)))
# FIND the path of the sketch file
export SKETCH_FILE_PATH := $(firstword $(foreach dir,$(sketch_dir_candidates),$(sketch_exists_p)))
$(SKETCH_FILE_PATH):
@echo "Sketch is $(SKETCH_FILE_PATH)"
.DEFAULT_GOAL := compile

Loading…
Cancel
Save