summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteven <steven.vasilogianis@gmail.com>2021-09-30 18:00:21 -0400
committerSteven <steven.vasilogianis@gmail.com>2021-09-30 18:00:21 -0400
commit00ba5a2c941404642f371d17351b8451b5554654 (patch)
tree8a3e541769139d75da37f5b5d170550709f8dd16
parent8aa4487fb991a0d0547e381c2949a3dc965dd106 (diff)
cleaned up makefile
-rw-r--r--src/main/Makefile122
1 files 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 @@
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: 1# Optionally some environment variables can be set:
41# 2#
42# FQBN Fully Qualified Board Name; if not set in the environment 3# FQBN Fully Qualified Board Name; if not set in the environment
@@ -59,59 +20,23 @@
59# 20#
60# OTA_PASS Password used for OTA update; if not set in the environment 21# 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 22# 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 23
24FQBN = esp8266:esp8266:espmxdevkit
25IOT_NAME = mush
26OTA_PORT = 8266
27OTA_PASS =
67 28
68MAKE_DIR := $(PWD) 29SERIAL_DEV = $(firstword $(wildcard /dev/ttyUSB* /dev/ttyACM*))
69#
70# ----- setup wor Wemos D1 mini -----
71FQBN ?= esp8266:esp8266:espmxdevkit
72IOT_NAME ?= mush
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 30
85ifndef SERIAL_DEV 31cli = arduino-cli -b "$(FQBN)"
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 32
95BUILD_DIR != arduino-cli compile -b $(FQBN) --show-properties | sed -ne 's/^build.path=//p' 33BUILD_DIR != $(cli) compile --show-properties | sed -ne 's/^build.path=//p'
96 34
97SRC := main.ino 35SRC := main.ino
98HDRS := $(wildcard *.h) 36HDRS := $(wildcard *.h)
99BIN := $(BUILD_DIR)/main.ino.bin 37BIN := $(BUILD_DIR)/main.ino.bin
100ELF := $(BUILD_DIR)/main.ino.elf 38ELF := $(BUILD_DIR)/main.ino.elf
101 39
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) 40all: $(ELF)
116.PHONY: all 41.PHONY: all
117 42
@@ -119,40 +44,15 @@ compile: $(ELF)
119.PHONY: compile 44.PHONY: compile
120 45
121$(BIN) $(ELF): $(SRC) $(HDRS) 46$(BIN) $(ELF): $(SRC) $(HDRS)
122 arduino-cli compile -b $(FQBN) $(VFLAG) 47 $(cli) compile
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 48
130upload: 49upload:
131 @if [ ! -c $(SERIAL_DEV) ] ; \ 50 $(cli) upload -p "$(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 51
137PLAT_PATH != arduino-cli compile -b "$(FQBN)" --show-properties | grep '^runtime.platform.path' | awk -F= '{print $$2}' 52PLAT_PATH != $(cli) compile --show-properties | sed -ne 's/^runtime.platform.path=//p'
138PY_PATH != arduino-cli compile -b "$(FQBN)" --show-properties | grep '^runtime.tools.python3.path' | awk -F= '{print $$2}' 53PY_PATH != $(cli) compile --show-properties | sed -ne 's/^runtime.tools.python3.path=//p'
139IOT_IP != getent ahostsv4 mush.local | (read ip _; echo $$ip) 54IOT_IP != getent ahostsv4 mush.local | (read ip _; echo $$ip)
140 55
141ota: $(BIN) 56ota: $(BIN)
142 "$(PY_PATH)/python3" "$(PLAT_PATH)/tools/espota.py" -i "$(IOT_IP)" -p "$(OTA_PORT)" --auth="$(OTA_PASS)" -f "$(BIN)" 57 "$(PY_PATH)/python3" "$(PLAT_PATH)/tools/espota.py" -i "$(IOT_IP)" -p "$(OTA_PORT)" --auth="$(OTA_PASS)" -f "$(BIN)"
143 58
144clean:
145 @echo "---> Cleaning the build directory"
146 rm -rf build
147
148find:
149 avahi-browse _arduino._tcp --resolve --parsable --terminate
150
151requirements:
152 @if [ -e requirements.txt ]; \
153 then while read -r i ; do echo ; \
154 echo "---> Installing " '"'$$i'"' ; \
155 arduino-cli lib install "$$i" ; \
156 done < requirements.txt ; \
157 else echo "---> MISSING requirements.txt file"; \
158 fi