Skip to content

Commit 3dfafcf

Browse files
rzrhobinjk
authored andcommitted
build: Add makefile to build without IDE
Other examples could follow this pattern Change-Id: I8070201762351167b030bfba6dba71e207680166 Bug: WebThingsIO#21 Forwarded: WebThingsIO#24 Signed-off-by: Philippe Coval <[email protected]>
1 parent bca3d5d commit 3dfafcf

File tree

2 files changed

+112
-0
lines changed

2 files changed

+112
-0
lines changed

Makefile

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#!/usr/bin/make -f
2+
# SPDX-License-Identifier: MPL-2.0
3+
#{
4+
# This Source Code Form is subject to the terms of the Mozilla Public
5+
# License, v. 2.0. If a copy of the MPL was not distributed with this
6+
# file, You can obtain one at http://mozilla.org/MPL/2.0/
7+
#}
8+
9+
default: help
10+
11+
topdir?=${CURDIR}
12+
extra_dir?=${topdir}/tmp
13+
14+
arduino_version?=1.8.5
15+
arduino_host?=linux32
16+
arduino_url?=https://downloads.arduino.cc/arduino-${arduino_version}-${arduino_host}.tar.xz
17+
ARDUINO_DIR?=${extra_dir}/arduino-${arduino_version}
18+
19+
arduino_mk_url?=https://github.com/sudar/Arduino-Makefile
20+
ARDMK_DIR?=${extra_dir}/arduino-mk
21+
22+
23+
help:
24+
@echo "# Usage:"
25+
@echo "# make setup # Will install tools and deps"
26+
@echo "# make all # Will build all examples"
27+
28+
${ARDUINO_DIR}:
29+
mkdir -p ${@D}
30+
cd ${@D} && curl ${arduino_url} | tar -xJ
31+
32+
rule/arduino_dir: ${ARDUINO_DIR}
33+
ls $<
34+
35+
${ARDMK_DIR}:
36+
mkdir -p ${@D}
37+
git clone --recursive --depth 1 ${arduino_mk_url} $@
38+
39+
rule/arduino_mk_dir: ${ARDMK_DIR}
40+
ls $<
41+
42+
#{ Libraries
43+
USER_LIB_PATH?=${extra_dir}/Arduino/libraries
44+
45+
ArduinoJson_url?=https://github.com/bblanchon/ArduinoJson
46+
ArduinoJson_dir?=${extra_dir}/Arduino/libraries/ArduinoJson
47+
48+
${ArduinoJson_dir}:
49+
@mkdir -p ${@D}
50+
git clone --depth 1 --recursive ${ArduinoJson_url} $@
51+
52+
ArduinoMDNS_url=https://github.com/arduino-libraries/ArduinoMDNS
53+
ArduinoMDNS_dir?=${extra_dir}/Arduino/libraries/ArduinoMDNS
54+
55+
${ArduinoMDNS_dir}:
56+
@mkdir -p ${@D}
57+
git clone --depth 1 --recursive ${ArduinoMDNS_url} $@
58+
59+
rule/arduino_lib_dirs: ${ArduinoMDNS_dir} ${ArduinoJson_dir}
60+
ls $^
61+
#}
62+
63+
setup: rule/arduino_dir rule/arduino_mk_dir rule/arduino_lib_dirs
64+
sync
65+
66+
all: $(wildcard examples/*/Makefile | sort)
67+
for file in $^; do \
68+
dirname=$$(dirname -- "$${file}") ; ${MAKE} -C $${dirname}; \
69+
done

examples/LevelSensor/Makefile

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/make -f
2+
# SPDX-License-Identifier: MPL-2.0
3+
#{
4+
# This Source Code Form is subject to the terms of the Mozilla Public
5+
# License, v. 2.0. If a copy of the MPL was not distributed with this
6+
# file, You can obtain one at http://mozilla.org/MPL/2.0/
7+
#}
8+
9+
default: all
10+
@echo "# $@: $^"
11+
12+
all: rule/setup
13+
14+
top_reldir?=../..
15+
topdir?=${CURDIR}/${top_reldir}
16+
-include ${topdir}/Makefile
17+
18+
AVR_TOOLS_DIR?=${ARDUINO_DIR}/hardware/tools/avr
19+
ARDUINO_DIR?=/usr/share/arduino
20+
ARDMK_DIR?=${ARDUINO_DIR}
21+
arduino_mk?=${ARDMK_DIR}/Arduino.mk
22+
23+
#{ Config part
24+
VARIANT?=mega
25+
BOARD_TAG=mega2560
26+
BOARD_SUB=
27+
MCU?=at${BOARD_TAG}
28+
F_CPU?=16000000L
29+
MONITOR_PORT?=$(shell ls /dev/ttyUSB* /dev/ttyACM* | head -n1)
30+
#}
31+
32+
ARCHITECTURE=avr
33+
AVRDUDE_ARD_BAUDRATE?=115200
34+
MONITOR_BAUDRATE?=${AVRDUDE_ARD_BAUDRATE}
35+
AVRDUDE_ARD_PROGRAMMER?=wiring
36+
37+
CPPFLAGS+=-I${top_reldir}
38+
39+
ARDUINO_LIBS += Ethernet SPI
40+
ARDUINO_LIBS += ArduinoMDNS
41+
ARDUINO_LIBS += ArduinoJson
42+
43+
-include ${arduino_mk}

0 commit comments

Comments
 (0)