-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
242 lines (221 loc) · 7.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
BOARD ?= arduino_101_factory
KERNEL ?= micro
UPDATE ?= exit
# pass TRACE=y to trace malloc/free in the ZJS API
TRACE ?= n
ifndef ZJS_BASE
$(error ZJS_BASE not defined. You need to source zjs-env.sh)
endif
OCF_ROOT ?= deps/iotivity-constrained
JERRY_BASE ?= $(ZJS_BASE)/deps/jerryscript
JS ?= samples/HelloWorld.js
VARIANT ?= release
# Dump memory information: on = print allocs, full = print allocs + dump pools
TRACE ?= off
# Specify pool malloc or heap malloc
MALLOC ?= pool
# Build for zephyr, default target
.PHONY: zephyr
zephyr: analyze generate
@make -f Makefile.zephyr BOARD=$(BOARD) KERNEL=$(KERNEL) VARIANT=$(VARIANT) MEM_STATS=$(MEM_STATS)
.PHONY: analyze
analyze:
ifeq ($(DEV), ashell)
@cp prj.mdef.dev prj.mdef
else
@cat prj.mdef.base > prj.mdef
endif
@cat src/Makefile.base > src/Makefile
@if [ "$(TRACE)" = "on" ] || [ "$(TRACE)" = "full" ]; then \
echo "ccflags-y += -DZJS_TRACE_MALLOC" >> src/Makefile; \
fi
@if [ $(MALLOC) = "pool" ]; then \
echo "obj-y += zjs_pool.o" >> src/Makefile; \
echo "ccflags-y += -DZJS_POOL_CONFIG" >> src/Makefile; \
if [ "$(TRACE)" = "full" ]; then \
echo "ccflags-y += -DDUMP_MEM_STATS" >> src/Makefile; \
fi; \
echo "" >> prj.mdef; \
echo "% POOL NAME SIZE_SMALL SIZE_LARGE BLOCK_NUMBER" >> prj.mdef; \
echo "% ====================================================" >> prj.mdef; \
echo "POOL POOL_8 8 8 64" >> prj.mdef; \
echo "POOL POOL_16 16 16 32" >> prj.mdef; \
echo "POOL POOL_36 36 36 16" >> prj.mdef; \
echo "POOL POOL_64 64 64 10" >> prj.mdef; \
echo "POOL POOL_128 128 128 4" >> prj.mdef; \
echo "POOL POOL_256 256 256 2" >> prj.mdef; \
else \
echo "" >> prj.mdef; \
echo "% HEAP CONFIG: " >> prj.mdef; \
if [ $(DEV) != "ashell" ]; then \
echo "HEAP_SIZE 5120" >> prj.mdef; \
fi; \
fi
@echo "ccflags-y += $(shell ./scripts/analyze.sh $(JS))" >> src/Makefile
.PHONY: all
all: zephyr arc
# MAKECMDGOALS is a Make variable that is set to the target your building for.
# This is how we can check if we are building for linux and if a clean is needed.
# The linux target does not use the BOARD variable, so without this special
# case, the linux target would clean every time.
ifneq ($(MAKECMDGOALS), linux)
# Building for Zephyr, check for .$(BOARD).last_build to see if a clean is needed
ifeq ("$(wildcard .$(BOARD).last_build)", "")
PRE_ACTION=clean
endif
else
# Building for Linux, check for .linux.last_build to see if a clean is needed
ifeq ("$(wildcard .linux.last_build)", "")
PRE_ACTION=clean
endif
endif
# Update dependency repos using deps/repos.txt
.PHONY: update
update:
@cd deps/; \
while read line; do \
case \
"$$line" in \#*) \
continue ;; \
*) \
name=$$(echo $$line | cut -d ' ' -f 1); \
repo=$$(echo $$line | cut -d ' ' -f 2); \
commit=$$(echo $$line | cut -d ' ' -f 3); \
if [ ! -d $$name ]; then \
git clone -q $$repo $$name; \
fi; \
echo Found dependency: $$name; \
cd $$name; \
if ! git checkout -q $$commit; then \
if ! git pull -q; then \
echo "Error attempting git pull on $$name"; \
fi; \
if ! git checkout -q $$commit; then \
echo "Error checking out commit '$$commit' on $$name"; \
if [ $(UPDATE) = "force" ]; then \
echo "Continuing anyway (UPDATE=force)"; \
else \
echo "Exiting"; \
exit 1; \
fi; \
fi; \
fi; \
cd ..; \
continue ;; \
esac \
done < repos.txt
@if ! env | grep -q ^ZEPHYR_BASE=; then \
echo; \
echo "ZEPHYR_BASE has not been set! It must be set to build"; \
echo "e.g. export ZEPHYR_BASE=$(ZJS_BASE)/deps/zephyr"; \
echo; \
exit 1; \
fi
# Sets up prj/last_build files
.PHONY: setup
setup: update
ifeq ($(BOARD), qemu_x86)
cp prj.conf.qemu_x86 prj.conf
else
ifeq ($(DEV), ashell)
cp prj.conf.arduino_101_dev prj.conf
else
cp prj.conf.base prj.conf
endif
ifeq ($(BOARD), arduino_101_factory)
ifeq ($(ZJS_PARTITION), 256)
cat prj.conf.partition_256 >> prj.conf
endif
endif
endif
# Append script specific modules to prj.conf
@if [ -e prj.conf.tmp ]; then \
cat prj.conf.tmp >> prj.conf; \
fi
# Remove .last_build file
@rm -f .*.last_build
@echo "" > .$(BOARD).last_build
# Explicit clean
.PHONY: clean
clean:
@if [ -d deps/zephyr ] && [ -e src/Makefile ]; then \
make -f Makefile.zephyr clean; \
fi
@if [ -d deps/jerryscript ]; then \
make -C $(JERRY_BASE) -f targets/zephyr/Makefile.zephyr clean; \
make -C $(JERRY_BASE) -f targets/zephyr/Makefile clean; \
rm -rf deps/jerryscript/build/$(BOARD)/; \
fi
make -f Makefile.linux clean
rm -f src/*.o
cd arc; make clean
# Flash Arduino 101 x86 image
.PHONY: dfu
dfu:
dfu-util -a x86_app -D outdir/zephyr.bin
# Flash Arduino 101 ARC image
.PHONY: dfu-arc
dfu-arc:
dfu-util -a sensor_core -D arc/outdir/zephyr.bin
# Flash both
.PHONY: dfu-all
dfu-all: dfu dfu-arc
# Generate the script file from the JS variable
.PHONY: generate
generate: setup $(PRE_ACTION)
@echo Creating C string from JS application...
@./scripts/convert.sh $(JS) src/zjs_script_gen.c
# Run QEMU target
.PHONY: qemu
qemu: analyze generate
make -f Makefile.zephyr BOARD=qemu_x86 KERNEL=$(KERNEL) MEM_STATS=$(MEM_STATS) qemu
# Builds ARC binary
.PHONY: arc
arc:
@cp arc/prj.conf.base arc/prj.conf
ifeq ($(ZJS_PARTITION), 256)
@cat arc/prj.conf.partition_256 >> arc/prj.conf
endif
@cd arc; make BOARD=arduino_101_sss_factory
# Run debug server over JTAG
.PHONY: debug
debug:
make -f Makefile.zephyr BOARD=arduino_101 debugserver
# Run gdb to connect to debug server for x86
.PHONY: gdb
gdb:
gdb outdir/zephyr.elf -ex "target remote :3333"
# Run gdb to connect to debug server for ARC
.PHONY: arcgdb
arcgdb:
$$ZEPHYR_SDK_INSTALL_DIR/sysroots/i686-pokysdk-linux/usr/bin/arc-poky-elf/arc-poky-elf-gdb arc/outdir/zephyr.elf -ex "target remote :3334"
# Linux target
.PHONY: linux
# Linux command line target, script can be specified on the command line
linux: generate
rm -f .*.last_build
echo "" > .linux.last_build
make -f Makefile.linux JS=$(JS) VARIANT=$(VARIANT)
.PHONY: help
help:
@echo "Build targets:"
@echo " zephyr: Build the main Zephyr target (default)"
@echo " arc: Build the ARC Zephyr target for Arduino 101"
@echo " all: Build the zephyr and arc targets"
@echo " linux: Build the Linux target"
@echo " dfu: Flash the x86 core binary with dfu-util"
@echo " dfu-arc: Flash the ARC binary with dfu-util"
@echo " dfu-all: Flash both binaries with dfu-util"
@echo " debug: Run debug server using JTAG"
@echo " gdb: Run gdb to connect to debug server for x86"
@echo " arcgdb: Run gdb to connect to debug server for ARC"
@echo " qemu: Run QEMU after building"
@echo " clean: Clean stale build objects"
@echo " setup: Sets up dependencies"
@echo " update: Updates dependencies"
@echo
@echo "Build options:"
@echo " BOARD= Specify a Zephyr board to build for"
@echo " JS= Specify a JS script to compile into the binary"
@echo " KERNEL= Specify the kernel to use (micro or nano)"
@echo