From b1f2bcfd4eff4835d33a7c1d559745c5702e8cd3 Mon Sep 17 00:00:00 2001
From: Philippe Coval
Date: Wed, 25 Jul 2018 19:27:38 +0200
Subject: [PATCH 1/2] build: Add makefile to build without IDE
Other examples could follow this pattern
Change-Id: I8070201762351167b030bfba6dba71e207680166
Bug: https://github.com/mozilla-iot/webthing-arduino/issues/21
Forwarded: https://github.com/mozilla-iot/webthing-arduino/pull/24
Signed-off-by: Philippe Coval
---
Makefile | 69 +++++++++++++++++++++++++++++++++++
examples/LevelSensor/Makefile | 43 ++++++++++++++++++++++
2 files changed, 112 insertions(+)
create mode 100644 Makefile
create mode 100644 examples/LevelSensor/Makefile
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..e801b13
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,69 @@
+#!/usr/bin/make -f
+# SPDX-License-Identifier: MPL-2.0
+#{
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/
+#}
+
+default: help
+
+topdir?=${CURDIR}
+extra_dir?=${topdir}/tmp
+
+arduino_version?=1.8.5
+arduino_host?=linux32
+arduino_url?=https://downloads.arduino.cc/arduino-${arduino_version}-${arduino_host}.tar.xz
+ARDUINO_DIR?=${extra_dir}/arduino-${arduino_version}
+
+arduino_mk_url?=https://github.com/sudar/Arduino-Makefile
+ARDMK_DIR?=${extra_dir}/arduino-mk
+
+
+help:
+ @echo "# Usage:"
+ @echo "# make setup # Will install tools and deps"
+ @echo "# make all # Will build all examples"
+
+${ARDUINO_DIR}:
+ mkdir -p ${@D}
+ cd ${@D} && curl ${arduino_url} | tar -xJ
+
+rule/arduino_dir: ${ARDUINO_DIR}
+ ls $<
+
+${ARDMK_DIR}:
+ mkdir -p ${@D}
+ git clone --recursive --depth 1 ${arduino_mk_url} $@
+
+rule/arduino_mk_dir: ${ARDMK_DIR}
+ ls $<
+
+#{ Libraries
+USER_LIB_PATH?=${extra_dir}/Arduino/libraries
+
+ArduinoJson_url?=https://github.com/bblanchon/ArduinoJson
+ArduinoJson_dir?=${extra_dir}/Arduino/libraries/ArduinoJson
+
+${ArduinoJson_dir}:
+ @mkdir -p ${@D}
+ git clone --depth 1 --recursive ${ArduinoJson_url} $@
+
+ArduinoMDNS_url=https://github.com/arduino-libraries/ArduinoMDNS
+ArduinoMDNS_dir?=${extra_dir}/Arduino/libraries/ArduinoMDNS
+
+${ArduinoMDNS_dir}:
+ @mkdir -p ${@D}
+ git clone --depth 1 --recursive ${ArduinoMDNS_url} $@
+
+rule/arduino_lib_dirs: ${ArduinoMDNS_dir} ${ArduinoJson_dir}
+ ls $^
+#}
+
+setup: rule/arduino_dir rule/arduino_mk_dir rule/arduino_lib_dirs
+ sync
+
+all: $(wildcard examples/*/Makefile | sort)
+ for file in $^; do \
+ dirname=$$(dirname -- "$${file}") ; ${MAKE} -C $${dirname}; \
+ done
diff --git a/examples/LevelSensor/Makefile b/examples/LevelSensor/Makefile
new file mode 100644
index 0000000..6f5d094
--- /dev/null
+++ b/examples/LevelSensor/Makefile
@@ -0,0 +1,43 @@
+#!/usr/bin/make -f
+# SPDX-License-Identifier: MPL-2.0
+#{
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/
+#}
+
+default: all
+ @echo "# $@: $^"
+
+all: rule/setup
+
+top_reldir?=../..
+topdir?=${CURDIR}/${top_reldir}
+-include ${topdir}/Makefile
+
+AVR_TOOLS_DIR?=${ARDUINO_DIR}/hardware/tools/avr
+ARDUINO_DIR?=/usr/share/arduino
+ARDMK_DIR?=${ARDUINO_DIR}
+arduino_mk?=${ARDMK_DIR}/Arduino.mk
+
+#{ Config part
+VARIANT?=mega
+BOARD_TAG=mega2560
+BOARD_SUB=
+MCU?=at${BOARD_TAG}
+F_CPU?=16000000L
+MONITOR_PORT?=$(shell ls /dev/ttyUSB* /dev/ttyACM* | head -n1)
+#}
+
+ARCHITECTURE=avr
+AVRDUDE_ARD_BAUDRATE?=115200
+MONITOR_BAUDRATE?=${AVRDUDE_ARD_BAUDRATE}
+AVRDUDE_ARD_PROGRAMMER?=wiring
+
+CPPFLAGS+=-I${top_reldir}
+
+ARDUINO_LIBS += Ethernet SPI
+ARDUINO_LIBS += ArduinoMDNS
+ARDUINO_LIBS += ArduinoJson
+
+-include ${arduino_mk}
From 5c67ea5e8a9b4169d950658bbc39f402e78ce00a Mon Sep 17 00:00:00 2001
From: Philippe Coval
Date: Wed, 11 Jul 2018 19:46:11 +0200
Subject: [PATCH 2/2] ignore: Emacs backup files
Change-Id: I35aebb540c72507423456d133e9f0150ff916174
Signed-off-by: Philippe Coval
---
.gitignore | 4 ++++
1 file changed, 4 insertions(+)
create mode 100644 .gitignore
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..14d78d1
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,4 @@
+*~
+**/build-*/*
+/tmp/
+