summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteven <steven.vasilogianis@gmail.com>2021-09-30 13:00:09 -0400
committerSteven <steven.vasilogianis@gmail.com>2021-09-30 13:00:09 -0400
commit862c489cd21c224c7934ba1cd6f9f2dc94395c9d (patch)
treebc0d25d8fa543c6a52573bd2971a77533dc527a9
parentc915e95f7564f2ec9def6f6f6b15e25fe86a6dc1 (diff)
Makefile from https://github.com/digiampietro/arduino-makefile/tree/master/blink-wemos-ota
-rw-r--r--src/main/Makefile166
1 files changed, 166 insertions, 0 deletions
diff --git a/src/main/Makefile b/src/main/Makefile
new file mode 100644
index 0000000..cd0b8f9
--- /dev/null
+++ b/src/main/Makefile
@@ -0,0 +1,166 @@
1# Makefile for Arduino based scketches
2#
3# Copyright 2020 Valerio Di Giampietro http://va.ler.io v@ler.io
4# MIT License - see License.txt file
5#
6# This Makefile uses the arduino-cli, the Arduino command line interface
7# and has been designed and tested to run on Linux, not on Windows.
8# Probably it will run on a Mac, but it has not been tested.
9#
10# Please note that:
11#
12# 1. each sketch must reside in his own folder with this Makefile
13#
14# 2. the main make targets are:
15# - all compiles and upload
16# - compile compiles only
17# - upload upload via serial port, compile if the binary file is
18# not available
19# - ota upload Over The Air, automatically find the device
20# IP address using the IOT_NAME (device hostname)
21# - clean clean the build directory
22# - find find OTA updatable devices on the local subnet
23# - requirements it the file "requirements.txt" exists it will
24# install the libraries listed in this file
25#
26# default is "all"
27#
28# 3. it gets the name of the sketch using the wildcard make command;
29# the name is *.ino; this means that you must have ONLY a file
30# with .ino extension, otherwise this makefile will break. This
31# also means that you can use this Makefile, almost unmodified,
32# for any sketch as long as you keep a single .ino file in each
33# folder
34#
35# 4. you can split your project in multiple files, if you wish,
36# using a single .ino file and multiple .h files, that you can
37# include in the .ino file with an '#include "myfile.h"'
38# directive
39#
40# Optionally some environment variables can be set:
41#
42# FQBN Fully Qualified Board Name; if not set in the environment
43# it will be assigned a value in this makefile
44#
45# SERIAL_DEV Serial device to upload the sketch; if not set in the
46# environment it will be assigned:
47# /dev/ttyUSB0 if it exists, or
48# /dev/ttyACM0 if it exists, or
49# unknown
50#
51# IOT_NAME Name of the IOT device; if not set in the environment
52# it will be assigned a value in this makefile. This is
53# very useful for OTA update, the device will be searched
54# on the local subnet using this name
55#
56# OTA_PORT Port used by OTA update; if not set in the environment
57# it will be assigned the default value of 8266 in this
58# makefile
59#
60# OTA_PASS Password used for OTA update; if not set in the environment
61# it will be assigned the default value of an empty string
62#
63# V verbose flag; can be 0 (quiet) or 1 (verbose); if not set
64# in the environment it will be assigned a default value
65# in this makefile
66
67
68MAKE_DIR := $(PWD)
69#
70# ----- setup wor Wemos D1 mini -----
71FQBN ?= esp8266:esp8266:d1_mini
72IOT_NAME ?= esp8266-blink
73OTA_PORT ?= 8266
74OTA_PASS ?=
75# ----- setup for Arduino Uno
76#FQBN ?= arduino:avr:uno
77# ----- ---------------------
78V ?= 0
79VFLAG =
80
81ifeq "$(V)" "1"
82VFLAG =-v
83endif
84
85ifndef SERIAL_DEV
86 ifneq (,$(wildcard /dev/ttyUSB0))
87 SERIAL_DEV = /dev/ttyUSB0
88 else ifneq (,$(wildcard /dev/ttyACM0))
89 SERIAL_DEV = /dev/ttyACM0
90 else
91 SERIAL_DEV = unknown
92 endif
93endif
94
95BUILD_DIR := $(subst :,.,build/$(FQBN))
96
97SRC := $(wildcard *.ino)
98HDRS := $(wildcard *.h)
99BIN := $(BUILD_DIR)/$(SRC).bin
100ELF := $(BUILD_DIR)/$(SRC).elf
101
102$(info FQBN is [${FQBN}])
103$(info IOT_NAME is [${IOT_NAME}])
104$(info OTA_PORT is [${OTA_PORT}])
105$(info OTA_PASS is [${OTA_PASS}])
106$(info V is [${V}])
107$(info VFLAG is [${VFLAG}])
108$(info MAKE_DIR is [${MAKE_DIR}])
109$(info BUILD_DIR is [${BUILD_DIR}])
110$(info SRC is [${SRC}])
111$(info HDRS is [${HDRS}])
112$(info BIN is [${BIN}])
113$(info SERIAL_DEV is [${SERIAL_DEV}])
114
115all: $(ELF) upload
116.PHONY: all
117
118compile: $(ELF)
119.PHONY: compile
120
121$(ELF): $(SRC) $(HDRS)
122 arduino-cli compile -b $(FQBN) $(VFLAG)
123 @if which arduino-manifest.pl; \
124 then echo "---> Generating manifest.txt"; \
125 arduino-manifest.pl -b $(FQBN) $(SRC) $(HDRS) > manifest.txt; \
126 else echo "---> If you want to generate manifest.txt, listing used libraries and their versions,"; \
127 echo "---> please install arduino-manifest, see https://github.com/digiampietro/arduino-manifest"; \
128 fi
129
130upload:
131 @if [ ! -c $(SERIAL_DEV) ] ; \
132 then echo "---> ERROR: Serial Device not available, please set the SERIAL_DEV environment variable" ; \
133 else echo "---> Uploading sketch\n"; \
134 arduino-cli upload -b $(FQBN) -p $(SERIAL_DEV) $(VFLAG); \
135 fi
136
137ota:
138 @PLAT_PATH=`arduino-cli compile -b $(FQBN) --show-properties | grep '^runtime.platform.path' | awk -F= '{print $$2}'` ; \
139 PY_PATH=`arduino-cli compile -b $(FQBN) --show-properties | grep '^runtime.tools.python3.path' | awk -F= '{print $$2}'` ; \
140 IOT_IP=`avahi-browse _arduino._tcp --resolve --parsable --terminate|grep -i ';$(IOT_NAME);'|grep ';$(OTA_PORT);'| awk -F\; '{print $$8}'|head -1`; \
141 BINFILE=$(wildcard $(BUILD_DIR)/$(SRC)*bin); \
142 echo "PLAT_PATH is [$$PLAT_PATH]" ; \
143 echo "PY_PATH: is [$$PY_PATH]" ; \
144 echo "IOT_IP: is [$$IOT_IP]" ; \
145 echo "BINFILE: is [$$BINFILE]" ; \
146 if [ "$$IOT_IP" = "" ] ; \
147 then echo "Unable to find device IP. Check that the IOT_NAME environment variable is correctly set. Use 'make find' to search devices"; \
148 else echo "---> Uploading Over The Air"; \
149 $$PY_PATH/python3 $$PLAT_PATH/tools/espota.py -i $$IOT_IP -p $(OTA_PORT) --auth=$(OTA_PASS) -f $$BINFILE ;\
150 fi
151
152clean:
153 @echo "---> Cleaning the build directory"
154 rm -rf build
155
156find:
157 avahi-browse _arduino._tcp --resolve --parsable --terminate
158
159requirements:
160 @if [ -e requirements.txt ]; \
161 then while read -r i ; do echo ; \
162 echo "---> Installing " '"'$$i'"' ; \
163 arduino-cli lib install "$$i" ; \
164 done < requirements.txt ; \
165 else echo "---> MISSING requirements.txt file"; \
166 fi