From 00ba5a2c941404642f371d17351b8451b5554654 Mon Sep 17 00:00:00 2001 From: Steven Date: Thu, 30 Sep 2021 18:00:21 -0400 Subject: cleaned up makefile --- src/main/Makefile | 122 +++++------------------------------------------------- 1 file changed, 11 insertions(+), 111 deletions(-) diff --git a/src/main/Makefile b/src/main/Makefile index d27d024..2000b24 100644 --- a/src/main/Makefile +++ b/src/main/Makefile @@ -1,42 +1,3 @@ -# Makefile for Arduino based scketches -# -# Copyright 2020 Valerio Di Giampietro http://va.ler.io v@ler.io -# MIT License - see License.txt file -# -# This Makefile uses the arduino-cli, the Arduino command line interface -# and has been designed and tested to run on Linux, not on Windows. -# Probably it will run on a Mac, but it has not been tested. -# -# Please note that: -# -# 1. each sketch must reside in his own folder with this Makefile -# -# 2. the main make targets are: -# - all compiles and upload -# - compile compiles only -# - upload upload via serial port, compile if the binary file is -# not available -# - ota upload Over The Air, automatically find the device -# IP address using the IOT_NAME (device hostname) -# - clean clean the build directory -# - find find OTA updatable devices on the local subnet -# - requirements it the file "requirements.txt" exists it will -# install the libraries listed in this file -# -# default is "all" -# -# 3. it gets the name of the sketch using the wildcard make command; -# the name is *.ino; this means that you must have ONLY a file -# with .ino extension, otherwise this makefile will break. This -# also means that you can use this Makefile, almost unmodified, -# for any sketch as long as you keep a single .ino file in each -# folder -# -# 4. you can split your project in multiple files, if you wish, -# using a single .ino file and multiple .h files, that you can -# include in the .ino file with an '#include "myfile.h"' -# directive -# # Optionally some environment variables can be set: # # FQBN Fully Qualified Board Name; if not set in the environment @@ -59,59 +20,23 @@ # # OTA_PASS Password used for OTA update; if not set in the environment # it will be assigned the default value of an empty string -# -# V verbose flag; can be 0 (quiet) or 1 (verbose); if not set -# in the environment it will be assigned a default value -# in this makefile +FQBN = esp8266:esp8266:espmxdevkit +IOT_NAME = mush +OTA_PORT = 8266 +OTA_PASS = -MAKE_DIR := $(PWD) -# -# ----- setup wor Wemos D1 mini ----- -FQBN ?= esp8266:esp8266:espmxdevkit -IOT_NAME ?= mush -OTA_PORT ?= 8266 -OTA_PASS ?= -# ----- setup for Arduino Uno -#FQBN ?= arduino:avr:uno -# ----- --------------------- -V ?= 0 -VFLAG = - -ifeq "$(V)" "1" -VFLAG =-v -endif +SERIAL_DEV = $(firstword $(wildcard /dev/ttyUSB* /dev/ttyACM*)) -ifndef SERIAL_DEV - ifneq (,$(wildcard /dev/ttyUSB0)) - SERIAL_DEV = /dev/ttyUSB0 - else ifneq (,$(wildcard /dev/ttyACM0)) - SERIAL_DEV = /dev/ttyACM0 - else - SERIAL_DEV = unknown - endif -endif +cli = arduino-cli -b "$(FQBN)" -BUILD_DIR != arduino-cli compile -b $(FQBN) --show-properties | sed -ne 's/^build.path=//p' +BUILD_DIR != $(cli) compile --show-properties | sed -ne 's/^build.path=//p' SRC := main.ino HDRS := $(wildcard *.h) BIN := $(BUILD_DIR)/main.ino.bin ELF := $(BUILD_DIR)/main.ino.elf -$(info FQBN is [${FQBN}]) -$(info IOT_NAME is [${IOT_NAME}]) -$(info OTA_PORT is [${OTA_PORT}]) -$(info OTA_PASS is [${OTA_PASS}]) -$(info V is [${V}]) -$(info VFLAG is [${VFLAG}]) -$(info MAKE_DIR is [${MAKE_DIR}]) -$(info BUILD_DIR is [${BUILD_DIR}]) -$(info SRC is [${SRC}]) -$(info HDRS is [${HDRS}]) -$(info BIN is [${BIN}]) -$(info SERIAL_DEV is [${SERIAL_DEV}]) - all: $(ELF) .PHONY: all @@ -119,40 +44,15 @@ compile: $(ELF) .PHONY: compile $(BIN) $(ELF): $(SRC) $(HDRS) - arduino-cli compile -b $(FQBN) $(VFLAG) - @if which arduino-manifest.pl; \ - then echo "---> Generating manifest.txt"; \ - arduino-manifest.pl -b $(FQBN) $(SRC) $(HDRS) > manifest.txt; \ - else echo "---> If you want to generate manifest.txt, listing used libraries and their versions,"; \ - echo "---> please install arduino-manifest, see https://github.com/digiampietro/arduino-manifest"; \ - fi + $(cli) compile upload: - @if [ ! -c $(SERIAL_DEV) ] ; \ - then echo "---> ERROR: Serial Device not available, please set the SERIAL_DEV environment variable" ; \ - else echo "---> Uploading sketch\n"; \ - arduino-cli upload -b $(FQBN) -p $(SERIAL_DEV) $(VFLAG); \ - fi + $(cli) upload -p "$(SERIAL_DEV)" -PLAT_PATH != arduino-cli compile -b "$(FQBN)" --show-properties | grep '^runtime.platform.path' | awk -F= '{print $$2}' -PY_PATH != arduino-cli compile -b "$(FQBN)" --show-properties | grep '^runtime.tools.python3.path' | awk -F= '{print $$2}' +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' IOT_IP != getent ahostsv4 mush.local | (read ip _; echo $$ip) ota: $(BIN) "$(PY_PATH)/python3" "$(PLAT_PATH)/tools/espota.py" -i "$(IOT_IP)" -p "$(OTA_PORT)" --auth="$(OTA_PASS)" -f "$(BIN)" -clean: - @echo "---> Cleaning the build directory" - rm -rf build - -find: - avahi-browse _arduino._tcp --resolve --parsable --terminate - -requirements: - @if [ -e requirements.txt ]; \ - then while read -r i ; do echo ; \ - echo "---> Installing " '"'$$i'"' ; \ - arduino-cli lib install "$$i" ; \ - done < requirements.txt ; \ - else echo "---> MISSING requirements.txt file"; \ - fi -- cgit v1.2.3