From 3626ad2442bb38fda9fa28492f7f1a3e861fcbd2 Mon Sep 17 00:00:00 2001 From: Andrew Cady Date: Tue, 12 Oct 2021 05:55:31 -0400 Subject: improve Makefile --- Makefile | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index 507f95d..7043b20 100644 --- a/Makefile +++ b/Makefile @@ -29,6 +29,7 @@ FQBN = $(CORE):espmxdevkit MDNS_NAME = $(PROGNAME) OTA_PORT = 8266 OTA_PASS = +SERIAL_DEV = $(firstword $(wildcard /dev/ttyUSB* /dev/ttyACM*)) .DEFAULT_GOAL = all @@ -39,33 +40,43 @@ init: arduino-cli core install $(CORE) arduino-cli lib update-index arduino-cli lib install 'DHT sensor library' + $(cli) compile --show-properties > $@ -SERIAL_DEV = $(firstword $(wildcard /dev/ttyUSB* /dev/ttyACM*)) +cli = arduino-cli -b "$(FQBN)" -ifneq (,$(wildcard init)) -BUILD_DIR != $(cli) compile --show-properties | sed -ne 's/^build.path=//p' -PLAT_PATH != $(cli) compile --show-properties | sed -ne 's/^runtime.platform.path=//p' -PY_PATH != $(cli) compile --show-properties | sed -ne 's/^runtime.tools.python3.path=//p' +ifeq (,$(wildcard init)) +ifneq ($(MAKECMDGOALS),init) +$(error please run make init) +endif +else +BUILD_DIR != sed -ne 's/^build.path=//p' < init +PLAT_PATH != sed -ne 's/^runtime.platform.path=//p' < init +PY_PATH != sed -ne 's/^runtime.tools.python3.path=//p' < init +endif +ifneq (,$(filter ota, $(MAKECMDGOALS))) MDNS_IP != getent ahostsv4 $(MDNS_NAME).local | (read ip _; echo $$ip) endif -cli = arduino-cli -b "$(FQBN)" - SRC := CCS811.cpp $(PROGNAME).ino HDRS := CCS811.h ota.h wifiinfo.h BIN := $(BUILD_DIR)/$(PROGNAME).ino.bin ELF := $(BUILD_DIR)/$(PROGNAME).ino.elf -all: $(ELF) .PHONY: all +all: $(ELF) + @ls -l $(ELF) compile: $(ELF) .PHONY: compile +build_flags = + $(BIN) $(ELF): $(SRC) $(HDRS) - $(cli) compile --warnings all + $(cli) compile $() $(addprefix --build-property build.extra_flags=,$(build_flags)) --warnings all + upload: $(ELF) + [ -w "$(SERIAL_DEV)" ] || sudo chmod 666 "$(SERIAL_DEV)" $(cli) upload -p "$(SERIAL_DEV)" ota: $(BIN) -- cgit v1.2.3