-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathMakefile
354 lines (301 loc) · 10.8 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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
include make/helpers.mk
include make/local_overrides.mk
include make/neuralspot_config.mk
include make/neuralspot_toolchain.mk
include make/jlink.mk
# NeuralSPOT is structured to ease adding modules
# Adding a module is as simple as creating a directory,
# populating it with a modules.mk, and adding it to the
# 'modules' list below.
# There are certain hardcoded assumptions that must be followed
# When adding a module. Module directories must look something like this:
# .../mymodule/
# module.mk
# src/ <- contains C, CC, S, and private H files
# includes-api/ <- contains public header files
#
# Build artifacts (.o, .d, etc) are placed
# in the $BINDIR directory (defaults to 'build') which is
# created when needed and remove by 'make clean'
#
# The module.mk contents differ slightly depending on
# the type of module (example, extern, or library), but
# generally work by adding values to a set of variables
# (see below). When adding a new module, it is best
# to copy an existing module.mk and modifying it.
# NeuralSPOT Library Modules
modules := neuralspot/ns-core
modules += neuralspot/ns-harness
modules += neuralspot/ns-peripherals
modules += neuralspot/ns-ipc
modules += neuralspot/ns-audio
modules += neuralspot/ns-utils
modules += neuralspot/ns-features
# ifeq ($(ARCH),apollo4)
modules += neuralspot/ns-i2c
ifeq ($(ARCH),apollo4)
modules += neuralspot/ns-spi
modules += neuralspot/ns-camera
endif
modules += neuralspot/ns-nnsp
ifeq ($(USB_PRESENT),1)
modules += neuralspot/ns-usb
modules += neuralspot/ns-rpc
endif
ifeq ($(BLE_SUPPORTED),1)
modules += neuralspot/ns-ble
endif
# External Component Modules
modules += extern/AmbiqSuite/$(AS_VERSION)
modules += extern/CMSIS/CMSIS-DSP-1.15.0
modules += extern/tensorflow/$(TF_VERSION)
modules += extern/SEGGER_RTT/$(SR_VERSION)
modules += extern/codecs/opus-precomp
# modules += extern/codecs/opus1.4
ifeq ($(BLE_SUPPORTED),1)
modules += extern/AmbiqSuite/$(AS_VERSION)/third_party/cordio
endif
ifeq ($(USB_PRESENT),1)
modules += extern/erpc/$(ERPC_VERSION)
endif
# Example (executable binary) Modules
ifeq ($(AUTODEPLOY),1)
# This is used for tflm_validator, genLib, and power binaries
modules += $(ADPATH)/$(EXAMPLE)
else
ifeq ($(EXAMPLE),all)
modules += examples/basic_tf_stub
modules += examples/har
ifeq ($(BLE_SUPPORTED),1)
modules += examples/nnse
modules += examples/nnid
endif
ifeq ($(USB_PRESENT),1)
modules += examples/rpc_client
modules += examples/rpc_server
modules += examples/ic
modules += examples/mpu_data_collection
modules += examples/quaternion
ifeq ($(ARCH),apollo4)
ifeq ($(AS_VERSION),R4.5.0)
modules += examples/vision
endif
endif
# ifneq ($(BLE_SUPPORTED),1)
# # Don't include it twice
# modules += examples/audio_codec
# endif
endif
else
modules += examples/$(EXAMPLE)
endif
endif
# The following variables are filled in by module.mk include files
#
# To create binaries. add axf and bin targets to 'examples'
# For code with a main(), add the object file for it to 'mains'
# For libraries that need to be built, add them to 'libraries'
# (note that this is automatically done by make-library)
# For pre-built libraries (usually part of extern) add to 'lib_prebuilt'
# Add all your source files to 'sources'
# Add any locally needed pre-processing defines to 'pp_defines'
# Add your local build dir to 'bindirs'
# Add any needed include paths to 'includes_api'
examples :=
mains :=
libraries :=
lib_prebuilt :=
sources :=
includes_api :=
pp_defines := $(DEFINES)
bindirs := $(BINDIR)
obs = $(call source-to-object,$(sources))
dependencies = $(subst .o,.d,$(obs))
objects = $(filter-out $(mains),$(call source-to-object,$(sources)))
CFLAGS += $(addprefix -D,$(pp_defines))
CFLAGS += $(addprefix -I ,$(includes_api))
.PHONY: all
all:
include $(addsuffix /module.mk,$(modules))
all: $(bindirs) $(libraries) $(examples) $(override_libraries) $(exampexample_librariesle) $(BINDIR)/board.svd
.SECONDARY:
.PHONY: libraries
libraries: $(libraries)
.PHONY: clean
clean:
ifeq ($(OS),Windows_NT)
$(Q) $(RM) -rf $(BINDIRROOT) $(JLINK_CF) $(NESTDIR)
else
$(Q) $(RM) -rf $(BINDIRROOT) $(JLINK_CF) $(NESTDIR)
endif
# lint: $(LINTSOURCES)
# $(LINT) $< -- $(LINTINCLUDES)
ifneq "$(MAKECMDGOALS)" "clean"
include $(dependencies)
endif
include make/nest-helper.mk
include make/ei-nest-helper.mk
# Compute stuff for doc creation
doc_sources = $(addprefix ../../,$(sources))
doc_sources += $(addprefix ../../,$(includes_api))
# Find the full path of $(TARGET) for deploy:
deploy_target = $(filter %$(TARGET).bin, $(examples))
$(bindirs):
$(Q) $(MKD) -p $@
$(BINDIR)/board.svd:
$(Q) @cp ./extern/AmbiqSuite/$(AS_VERSION)/pack/svd/$(PART).svd $(BINDIR)/board.svd
$(BINDIR)/%.o: %.cc
@echo " Compiling $(COMPILERNAME) $< to make $@"
$(Q) $(MKD) -p $(@D)
$(Q) $(CC) -c $(CFLAGS) $(CCFLAGS) $< -o $@
$(BINDIR)/%.o: %.cpp
@echo " Compiling $(COMPILERNAME) $< to make $@"
$(Q) $(MKD) -p $(@D)
$(Q) $(CC) -c $(CFLAGS) $(CCFLAGS) $< -o $@
$(BINDIR)/%.o: %.c
@echo " Compiling $(COMPILERNAME) $< to make $@"
$(Q) $(MKD) -p $(@D)
$(Q) $(CC) -c $(CFLAGS) $(CONLY_FLAGS) $< -o $@
$(BINDIR)/%.o: %.s
@echo " Assembling $(COMPILERNAME) $<"
$(Q) $(MKD) -p $(@D)
$(Q) $(CC) -c $(ASMFLAGS) $< -o $@
ifeq ($(TOOLCHAIN),arm)
%.bin: %.axf
@echo " Copying $(COMPILERNAME) $@..."
$(Q) $(MKD) -p $(@D)
$(Q) $(CP) $(CPFLAGS) $@ $<
$(Q) $(OD) $(ODFLAGS) $< --output $*.txt
else
%.bin: %.axf
@echo " Copying $(COMPILERNAME) $@..."
$(Q) $(MKD) -p $(@D)
$(Q) $(CP) $(CPFLAGS) $< $@
$(Q) $(OD) $(ODFLAGS) $< > $*.lst
# $(foreach OBJ,$(objects),$(shell echo "${OBJ}">>$*.sizeinput;))
# $(Q) $(SIZE) @$*.sizeinput $< > $*.size
endif
.PHONY: nest
nest: all
@echo " Building Nest without src/ at $(NESTDIR) based on $< ..."
$(Q) $(MKD) -p $(NESTDIR)
$(Q) $(MKD) -p $(NESTDIR)/src
$(Q) $(MKD) -p $(NESTDIR)/src/ns-core
$(Q) $(MKD) -p $(NESTDIR)/srcpreserved
$(Q) $(MKD) -p $(NESTDIR)/libs
$(Q) $(MKD) -p $(NESTDIR)/make
$(Q) $(MKD) -p $(NESTDIR)/pack/svd
@for target in $(nest_dirs); do \
"mkdir" -p $(NESTDIR)"/includes/"$$target ; \
cp -R $$target/. $(NESTDIR)"/includes/"$$target 2>/dev/null || true; \
done
@for target in $(nest_lib_dirs); do \
"mkdir" -p $(NESTDIR)"/"$$target ; \
done
@for file in $(nest_libs); do \
cp $(BINDIRROOT)/$$file $(NESTDIR)/libs/$$file ; \
done
@for file in $(nest_prebuilt_libs); do \
cp $$file $(NESTDIR)/libs/$$file ; \
done
@cp -R $(NESTDIR)/src $(NESTDIR)/srcpreserved/ 2>/dev/null || true
@cp -R neuralspot/ns-core/src/* $(NESTDIR)/src/ns-core
@cp $(LINKER_FILE) $(NESTDIR)/libs
@cp make/nest-makefile.mk $(NESTDIR)/Makefile.suggested
@cp $(BINDIR)/board.svd $(NESTDIR)/pack/svd
@echo "# Autogenerated file - created by NeuralSPOT make nest" > $(NESTDIR)/autogen_$(BOARD)_$(EVB)_$(TOOLCHAIN).mk
@echo "INCLUDES += $(includes_api)" >> $(NESTDIR)/autogen_$(BOARD)_$(EVB)_$(TOOLCHAIN).mk
@echo "libraries += $(nest_dest_libs)" >> $(NESTDIR)/autogen_$(BOARD)_$(EVB)_$(TOOLCHAIN).mk
@echo "override_libraries += $(nest_dest_override_libs)" >> $(NESTDIR)/autogen_$(BOARD)_$(EVB)_$(TOOLCHAIN).mk
@echo "local_app_name := $(NESTEGG)" >> $(NESTDIR)/autogen_$(BOARD)_$(EVB)_$(TOOLCHAIN).mk
.PHONY: nestcomponent
nestcomponent:
@echo " Building Nestcomponent only copying $(NESTCOMP)..."
@for target in $(nest_component_includes); do \
"mkdir" -p $(NESTDIR)"/includes/"$$target ; \
cp -R $$target/. $(NESTDIR)"/includes/"$$target 2>/dev/null || true; \
done
@for file in $(nest_component_libs); do \
cp $$file $(NESTDIR)"/libs/" ; \
done
.PHONY: nestall
nestall: nest
@echo " Building Nestall including src/ at $(NESTDIR) based on $< ..."
@cp -R $(NESTSOURCEDIR) $(NESTDIR)
@cp make/helpers.mk $(NESTDIR)/make
@cp make/neuralspot_config.mk $(NESTDIR)/make
@cp make/neuralspot_toolchain.mk $(NESTDIR)/make
@cp make/jlink.mk $(NESTDIR)/make
@cp make/nest-makefile.mk $(NESTDIR)/Makefile
.PHONY: einest
einest: all
@echo " Building EdgeImpulse Nest without src/ at $(NESTDIR) based on $< ..."
$(Q) $(MKD) -p $(NESTDIR)
$(Q) $(MKD) -p $(NESTDIR)/src
$(Q) $(MKD) -p $(NESTDIR)/src/ns-core
$(Q) $(MKD) -p $(NESTDIR)/srcpreserved
$(Q) $(MKD) -p $(NESTDIR)/libs
$(Q) $(MKD) -p $(NESTDIR)/make
$(Q) $(MKD) -p $(NESTDIR)/pack/svd
$(Q) @cp -R projects/edgeimpulse/src/ambiq $(NESTDIR)/src/ambiq-copy-me-into-porting-dir
@for target in $(ei_nest_dirs); do \
"mkdir" -p $(NESTDIR)"/includes/"$$target ; \
cp -R $$target/. $(NESTDIR)"/includes/"$$target 2>/dev/null || true; \
done
@for target in $(ei_nest_lib_dirs); do \
"mkdir" -p $(NESTDIR)"/"$$target ; \
done
@for file in $(ei_nest_libs); do \
cp $(BINDIRROOT)/$$file $(NESTDIR)/libs/$$file ; \
done
@for file in $(ei_nest_prebuilt_libs); do \
cp $$file $(NESTDIR)/libs/$$file ; \
done
@cp -R $(NESTDIR)/src $(NESTDIR)/srcpreserved/ 2>/dev/null || true
@cp -R neuralspot/ns-core/src/* $(NESTDIR)/src/ns-core
@cp $(LINKER_FILE) $(NESTDIR)/libs
@cp make/ei-nest-makefile.mk $(NESTDIR)/Makefile.suggested
@cp $(BINDIR)/board.svd $(NESTDIR)/pack/svd
@echo "# Autogenerated file - created by NeuralSPOT make nest" > $(NESTDIR)/autogen_$(BOARD)_$(EVB)_$(TOOLCHAIN).mk
@echo "INCLUDES += $(ei_includes_api)" >> $(NESTDIR)/autogen_$(BOARD)_$(EVB)_$(TOOLCHAIN).mk
@echo "libraries += $(ei_nest_dest_libs)" >> $(NESTDIR)/autogen_$(BOARD)_$(EVB)_$(TOOLCHAIN).mk
@echo "override_libraries += $(ei_nest_dest_override_libs)" >> $(NESTDIR)/autogen_$(BOARD)_$(EVB)_$(TOOLCHAIN).mk
@echo "local_app_name := $(NESTEGG)" >> $(NESTDIR)/autogen_$(BOARD)_$(EVB)_$(TOOLCHAIN).mk
.PHONY: einestall
einestall: einest
@echo " Building EdgeImpulse Nestall including src/ at $(NESTDIR) based on $< ..."
@cp -R $(NESTSOURCEDIR) $(NESTDIR)
@cp make/helpers.mk $(NESTDIR)/make
@cp make/neuralspot_config.mk $(NESTDIR)/make
@cp make/neuralspot_toolchain.mk $(NESTDIR)/make
@cp make/jlink.mk $(NESTDIR)/make
@cp make/ei-nest-makefile.mk $(NESTDIR)/Makefile
$(JLINK_CF):
@echo " Creating JLink command sequence input file... $(deploy_target)"
$(Q) echo "ExitOnError 1" > $@
$(Q) echo "Reset" >> $@
$(Q) echo "LoadFile $(deploy_target), $(JLINK_PF_ADDR)" >> $@
$(Q) echo "Exit" >> $@
$(JLINK_RESET_CF):
@echo " Creating JLink command reset file... $(deploy_target)"
$(Q) echo "ExitOnError 1" > $@
$(Q) echo "R1" >> $@
$(Q) echo "sleep 250" >> $@
$(Q) echo "R0" >> $@
$(Q) echo "sleep 250" >> $@
$(Q) echo "Exit" >> $@
.PHONY: reset
reset: $(JLINK_RESET_CF)
@echo " Reset EVB via Jlink..."
$(Q) $(JLINK) $(JLINK_RESET_CMD)
$(Q) $(RM) $(JLINK_RESET_CF)
.PHONY: deploy
deploy: $(JLINK_CF)
@echo " Deploying $< to device (ensure JLink USB connected and powered on)..."
- $(Q) $(JLINK) $(JLINK_CMD)
$(Q) $(RM) $(JLINK_CF)
.PHONY: view
view:
@echo " Printing SWO output (ensure JLink USB connected and powered on)..."
$(Q) $(JLINK_SWO) $(JLINK_SWO_CMD)
%.d: ;