forked from microflo/microflo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
280 lines (231 loc) · 12.1 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
# User configuration options
GRAPH=examples/blink.fbp
MODEL=uno
AVRMODEL=at90usb1287
MBED_GRAPH=examples/blink-mbed.fbp
LINUX_GRAPH=examples/blink-rpi.fbp
STELLARIS_GRAPH=examples/blink-stellaris.fbp
UPLOAD_DIR=/mnt
BUILD_DIR=$(shell echo `pwd`/build)
MICROFLO_SOURCE_DIR=$(shell echo `pwd`/microflo)
MICROFLO=./microflo.js
# SERIALPORT=/dev/somecustom
# ARDUINO=/home/user/Arduino-1.0.5
# ENERGIA=/opt/energia/
AVRSIZE=avr-size
AVRGCC=avr-g++
AVROBJCOPY=avr-objcopy
DFUPROGRAMMER=dfu-programmer
VERSION=$(shell git describe --tags --always)
OSX_ARDUINO_APP=/Applications/Arduino.app
AVR_FCPU=1000000UL
# Not normally customized
CPPFLAGS=-ffunction-sections -fshort-enums -fdata-sections -g -Os -w
DEFINES=
ifeq ($(LIBRARY),arduino-standard)
DEFINES+=-DHAVE_DALLAS_TEMPERATURE -DHAVE_ADAFRUIT_NEOPIXEL -DHAVE_ADAFRUIT_WS2801
endif
ifdef NO_DEBUG
DEFINES+=-DMICROFLO_DISABLE_DEBUG
endif
ifdef NO_SUBGRAPHS
DEFINES+=-DMICROFLO_DISABLE_SUBGRAPHS
endif
ifdef LIBRARY
LIBRARYOPTION=--library=$(LIBRARY)
endif
ESP_OPTS = ESPRESSIF_DIR=/home/jon/temp/Espressif ESPTOOL=/usr/bin/esptool.py V=1 ESPTOOL_CK=/home/jon/temp/Espressif/esptool-ck/esptool SDK_EXTRA_INCLUDES=$(MICROFLO_SOURCE_DIR) LD_SCRIPT="-T ./eagle.app.v6.ld"
INOOPTIONS=--board-model=$(MODEL)
ifdef SERIALPORT
INOUPLOADOPTIONS=--serial-port=$(SERIALPORT)
ESP_OPTS+=ESPPORT=$(SERIALPORT)
endif
ifdef ARDUINO
INOOPTIONS+=--arduino-dist=$(ARDUINO)
endif
ifndef ENERGIA
ENERGIA=/opt/energia/
endif
EMSCRIPTEN_EXPORTS='["_emscripten_runtime_new", "_emscripten_runtime_free", "_emscripten_runtime_run", "_emscripten_runtime_send", "_emscripten_runtime_setup"]'
COMMON_CFLAGS:=-I. -I${MICROFLO_SOURCE_DIR} -Wall
# Platform specifics
ifeq ($(OS),Windows_NT)
# TODO, test and fix
else
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Darwin)
AVRSIZE=$(OSX_ARDUINO_APP)/Contents/Resources/Java/hardware/tools/avr/bin/avr-size
AVRGCC=$(OSX_ARDUINO_APP)/Contents/Resources/Java/hardware/tools/avr/bin/avr-g++
AVROBJCOPY=$(OSX_ARDUINO_APP)/Contents/Resources/Java/hardware/tools/avr/bin/avr-objcopy
endif
ifeq ($(UNAME_S),Linux)
# Nothing needed :D
endif
endif
# Rules
all: build
update-defs:
$(MICROFLO) update-defs $(MICROFLO_SOURCE_DIR)
build-arduino-min:
rm -rf $(BUILD_DIR)/arduino || echo 'WARN: failure to clean Arduino build'
mkdir -p $(BUILD_DIR)/arduino/src
mkdir -p $(BUILD_DIR)/arduino/lib
cp -r $(MICROFLO_SOURCE_DIR) $(BUILD_DIR)/arduino/lib/
$(MICROFLO) generate $(GRAPH) $(BUILD_DIR)/arduino/src/ --target arduino
cd $(BUILD_DIR)/arduino && ino build $(INOOPTIONS) --verbose --cppflags="$(CPPFLAGS) $(DEFINES) -I./src"
$(AVRSIZE) -A $(BUILD_DIR)/arduino/.build/$(MODEL)/firmware.elf
build-arduino:
# rm -rf $(BUILD_DIR)/arduino || echo 'WARN: failure to clean Arduino build'
mkdir -p $(BUILD_DIR)/arduino/src
mkdir -p $(BUILD_DIR)/arduino/lib
cp -r $(MICROFLO_SOURCE_DIR) $(BUILD_DIR)/arduino/lib/
unzip -q -n ./thirdparty/OneWire.zip -d $(BUILD_DIR)/arduino/lib/
unzip -q -n ./thirdparty/DallasTemperature.zip -d $(BUILD_DIR)/arduino/lib/
cd thirdparty/Adafruit_NeoPixel && git checkout-index -f -a --prefix=$(BUILD_DIR)/arduino/lib/Adafruit_NeoPixel/
cd thirdparty/Adafruit_WS2801 && git checkout-index -f -a --prefix=$(BUILD_DIR)/arduino/lib/Adafruit_WS2801/
cd thirdparty/NewPing && git checkout-index -f -a --prefix=$(BUILD_DIR)/arduino/lib/NewPing/
cd $(BUILD_DIR)/arduino/lib && test -e patched || patch -p0 < ../../../thirdparty/DallasTemperature.patch
cd $(BUILD_DIR)/arduino/lib && test -e patched || patch -p0 < ../../../thirdparty/OneWire.patch
touch $(BUILD_DIR)/arduino/lib/patched
$(MICROFLO) generate $(GRAPH) $(BUILD_DIR)/arduino/src/ arduino
cd $(BUILD_DIR)/arduino && ino build $(INOOPTIONS) --verbose --cppflags="$(CPPFLAGS) $(DEFINES) -I./src"
$(AVRSIZE) -A $(BUILD_DIR)/arduino/.build/$(MODEL)/firmware.elf
build-avr:
mkdir -p $(BUILD_DIR)/avr
node microflo.js generate $(GRAPH) $(BUILD_DIR)/avr/ --target avr
cd $(BUILD_DIR)/avr && $(AVRGCC) -o firmware.elf main.cpp -DF_CPU=$(AVR_FCPU) -DAVR=1 $(COMMON_CFLAGS) -Werror -Wno-error=overflow -mmcu=$(AVRMODEL) -fno-exceptions -fno-rtti $(CPPFLAGS)
cd $(BUILD_DIR)/avr && $(AVROBJCOPY) -j .text -j .data -O ihex firmware.elf firmware.hex
$(AVRSIZE) -A $(BUILD_DIR)/avr/firmware.elf
build-mbed:
cd thirdparty/mbed && python2 workspace_tools/build.py -t GCC_ARM -m LPC1768
rm -rf $(BUILD_DIR)/mbed
mkdir -p $(BUILD_DIR)/mbed
node microflo.js generate $(MBED_GRAPH) $(BUILD_DIR)/mbed/ --target mbed --library microflo-core/components/arm-standard.json
cp Makefile.mbed $(BUILD_DIR)/mbed/Makefile
cd $(BUILD_DIR)/mbed && make ROOT_DIR=./../../
build-stellaris:
rm -rf $(BUILD_DIR)/stellaris
mkdir -p $(BUILD_DIR)/stellaris/gcc
# driverlib
cp -r $(ENERGIA)/hardware/lm4f/cores/lm4f/driverlib $(BUILD_DIR)/stellaris/
cp Makefile.stellaris.driverlib $(BUILD_DIR)/stellaris/driverlib/
cp makedefs.stellaris $(BUILD_DIR)/stellaris/driverlib/makedefs
cd $(BUILD_DIR)/stellaris/driverlib && make -f Makefile.stellaris.driverlib IPATH=$(ENERGIA)/hardware/lm4f/cores/lm4f
# app
cp ./startup_gcc.c $(BUILD_DIR)/stellaris/
cp $(ENERGIA)/hardware/lm4f/cores/lm4f/lm4fcpp_blizzard.ld $(BUILD_DIR)/stellaris/gcc/standalone.ld
$(MICROFLO) generate $(STELLARIS_GRAPH) $(BUILD_DIR)/stellaris/ --target stellaris --library microflo-core/components/arm-standard.json
cp Makefile.stellaris.app $(BUILD_DIR)/stellaris/Makefile
cd $(BUILD_DIR)/stellaris && make ROOT=./ IPATH="$(ENERGIA)/hardware/lm4f/cores/lm4f $(ENERGIA)/hardware/lm4f/variants/stellarpad ../../microflo/"
# Build microFlo components as an object library, build/lib/componentlib.o
build-microflo-complib:
mkdir -p $(BUILD_DIR)/lib
node microflo.js generate $(LINUX_GRAPH) $(BUILD_DIR)/lib --target linux --library microflo-core/components/linux-standard.json
cp -r $(BUILD_DIR)/lib/componentlib.hpp $(BUILD_DIR)/lib/componentlib.cpp
g++ -c $(BUILD_DIR)/lib/componentlib.cpp -o $(BUILD_DIR)/lib/componentlib.o -I$(BUILD_DIR)/lib -I./microflo -std=c++0x -DLINUX -Wall -Werror
# Build microFlo runtime as a dynamic loadable library, build/lib/libmicroflo.so
build-microflo-sharedlib:
rm -rf $(BUILD_DIR)/lib
mkdir -p $(BUILD_DIR)/lib
g++ -fPIC -c microflo/microflo.cpp -o microflo/microflo.o -std=c++0x -DLINUX -Wall -Werror
g++ -shared -Wl,-soname,libmicroflo.so -o $(BUILD_DIR)/lib/libmicroflo.so -I$(BUILD_DIR)/lib microflo/microflo.o
# Build microFlo runtime as an object library (to be static linked with app), $(BUILD_DIR)/lib/microflolib.o
build-microflo-objlib:
rm -rf $(BUILD_DIR)/lib
mkdir -p $(BUILD_DIR)/lib
# FIXME: only for internal defs...
# node microflo.js generate $(LINUX_GRAPH) $(BUILD_DIR)/lib --target linux --library microflo-core/components/linux-standard.json
g++ -c microflo/microflo.cpp -o $(BUILD_DIR)/lib/microflolib.o -std=c++0x -I$(BUILD_DIR)/lib -DLINUX -Wall -Werror
# Build firmware linked to microflo runtime as dynamic loadable library, $(BUILD_DIR)/lib/libmicroflo.so
build-linux-sharedlib: build-microflo-sharedlib
rm -rf $(BUILD_DIR)/linux
mkdir -p $(BUILD_DIR)/linux
node microflo.js generate $(LINUX_GRAPH) $(BUILD_DIR)/linux --target linux
g++ -o $(BUILD_DIR)/linux/firmware $(BUILD_DIR)/linux/main.cpp -std=c++0x -Wl,-rpath=$(BUILD_DIR)/lib -DLINUX -I./$(BUILD_DIR)/lib -I./microflo -Wall -Werror -lrt -L./$(BUILD_DIR)/lib -lmicroflo
# Build firmware statically linked to microflo runtime as object file, $(BUILD_DIR)/lib/microflolib.o
build-linux: build-microflo-objlib build-microflo-complib build-linux-embedding
rm -rf $(BUILD_DIR)/linux
mkdir -p $(BUILD_DIR)/linux
node microflo.js generate $(LINUX_GRAPH) $(BUILD_DIR)/linux --target linux --library microflo-core/components/linux-standard.json
g++ -o $(BUILD_DIR)/linux/firmware $(BUILD_DIR)/linux/main.cpp -std=c++0x $(BUILD_DIR)/lib/microflolib.o -DLINUX -I$(BUILD_DIR)/lib -I./microflo -Wall -Werror -lrt
# TODO: move to separate repo
build-linux-embedding:
rm -rf $(BUILD_DIR)/linux
mkdir -p $(BUILD_DIR)/linux
node microflo.js generate examples/embedding.cpp $(BUILD_DIR)/linux/ --target linux --library microflo-core/components/linux-standard.json
cd $(BUILD_DIR)/linux && g++ -o firmware ../../examples/embedding.cpp -std=c++0x $(COMMON_CFLAGS) -DLINUX -Werror -lrt
build-emscripten:
rm -rf $(BUILD_DIR)/emscripten
mkdir -p $(BUILD_DIR)/emscripten
$(MICROFLO) generate $(GRAPH) $(BUILD_DIR)/emscripten --target emscripten ${LIBRARYOPTION}
cd $(BUILD_DIR)/emscripten && emcc -o microflo-runtime.html --pre-js $(MICROFLO_SOURCE_DIR)/emscripten-pre.js main.cpp $(COMMON_CFLAGS) -DMICROFLO_MESSAGE_LIMIT=200 -s NO_DYNAMIC_EXECUTION=1 -s EXPORTED_FUNCTIONS=$(EMSCRIPTEN_EXPORTS) -s RESERVED_FUNCTION_POINTERS=10
build-esp:
rm -rf $(BUILD_DIR)/esp
mkdir -p $(BUILD_DIR)/esp
cp -r thirdparty/esp8266/esphttpd/include $(BUILD_DIR)/esp/
cp -r thirdparty/esp8266/ESP8266-EVB-blinkLED/* $(BUILD_DIR)/esp/
rm -rf $(BUILD_DIR)/esp/{firmware,build}
mkdir -p $(BUILD_DIR)/esp/{firmware,build}
rm $(BUILD_DIR)/esp/user/*.c || echo 'no C files'
rm $(BUILD_DIR)/esp/user/*.o || echo 'no .o files'
$(MICROFLO) generate $(GRAPH) $(BUILD_DIR)/esp/user/ --target esp8266 --library microflo-core/components/esp-minimal.json
cd $(BUILD_DIR)/esp && make $(ESP_OPTS)
flash-esp: build-esp
cd $(BUILD_DIR)/esp && make flash $(ESP_OPTS)
build: update-defs build-arduino build-avr
upload: build-arduino
cd $(BUILD_DIR)/arduino && ino upload $(INOUPLOADOPTIONS) $(INOOPTIONS)
upload-dfu: build-avr
cd $(BUILD_DIR)/avr && sudo $(DFUPROGRAMMER) $(AVRMODEL) erase
sleep 1
cd $(BUILD_DIR)/avr && sudo $(DFUPROGRAMMER) $(AVRMODEL) flash firmware.hex || sudo $(DFUPROGRAMMER) $(AVRMODEL) flash firmware.hex || sudo $(DFUPROGRAMMER) $(AVRMODEL) flash firmware.hex || sudo $(DFUPROGRAMMER) $(AVRMODEL) flash firmware.hex || sudo $(DFUPROGRAMMER) $(AVRMODEL) flash firmware.hex
sudo $(DFUPROGRAMMER) $(AVRMODEL) start
upload-mbed: build-mbed
cd $(BUILD_DIR)/mbed && sudo cp firmware.bin $(UPLOAD_DIR)
debug-stellaris:
arm-none-eabi-gdb $(BUILD_DIR)/stellaris/gcc/main.axf --command=./stellaris.load.gdb
upload-stellaris: build-stellaris
sudo lm4flash $(BUILD_DIR)/stellaris/gcc/main.bin
clean:
git clean -dfx --exclude=node_modules
release-arduino:
rm -rf $(BUILD_DIR)/microflo-arduino
mkdir -p $(BUILD_DIR)/microflo-arduino/microflo/examples/Standalone
cp -r microflo $(BUILD_DIR)/microflo-arduino/
cp -r build/arduino/src/componentlib* $(BUILD_DIR)/microflo-arduino/microflo/
ls -ls $(BUILD_DIR)/arduino/src
cp -r $(BUILD_DIR)/arduino/src/*.h $(BUILD_DIR)/microflo-arduino/microflo
cp $(BUILD_DIR)/arduino/src/main.cpp $(BUILD_DIR)/microflo-arduino/microflo/examples/Standalone/Standalone.pde
cd $(BUILD_DIR)/microflo-arduino && zip -q -r ../microflo-arduino.zip microflo
check-arduino-release:
rm -rf $(BUILD_DIR)/microflo-arduino-check
mkdir -p $(BUILD_DIR)/microflo-arduino-check/{src,lib}
cd $(BUILD_DIR)/microflo-arduino-check/lib && unzip ../../microflo-arduino.zip
cd $(BUILD_DIR)/microflo-arduino-check && cp lib/microflo/examples/Standalone/Standalone.pde src/Standalone.cpp
cd $(BUILD_DIR)/microflo-arduino-check && ino build
# FIXME: run on Travis CI
release-esp: build-esp
release-mbed: build-mbed
# TODO: package into something usable with MBed tools
release-linux: build-linux
# TODO: package?
release-stellaris: build-stellaris
# TODO: package?
release-emscripten: build-emscripten
# TODO: package?
release: build release-mbed release-linux release-microflo release-arduino release-stellaris release-emscripten
rm -rf $(BUILD_DIR)/microflo-$(VERSION)
mkdir -p $(BUILD_DIR)/microflo-$(VERSION)
cp -r $(BUILD_DIR)/microflo-arduino.zip $(BUILD_DIR)/microflo-$(VERSION)/
cp README.release.txt $(BUILD_DIR)/microflo-$(VERSION)/README.txt
# FIXME: copy in a README/HTML pointing to Flowhub app, and instructions to flash device
cd build && zip -q --symlinks -r microflo-$(VERSION).zip microflo-$(VERSION)
check-release: release
rm -rf $(BUILD_DIR)/check-release
mkdir -p $(BUILD_DIR)/check-release
cd $(BUILD_DIR)/check-release && unzip -q ../microflo-$(VERSION)
# TODO: check npm and component.io packages
# TODO: check arduino package by importing with ino, building
check: build-emscripten
npm test
.PHONY: all build update-defs clean release release-microflo release-arduino check-release