-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
117 lines (100 loc) · 4.02 KB
/
Copy pathMakefile
File metadata and controls
117 lines (100 loc) · 4.02 KB
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
# Check if WASI_SDK_PATH is set
ifndef WASI_SDK_PATH
$(error WASI_SDK_PATH is not set. Please set it to the path of your WASI SDK installation)
endif
# Tool macros
CC = $(WASI_SDK_PATH)/bin/clang
CXX = $(WASI_SDK_PATH)/bin/clang++
# Settings
NAME = edge_impulse_wasi.wasm
BUILD_PATH = ./build
# Location of main.cpp (must use C++ compiler for main)
CXXSOURCES = src/main.cpp
# WASI specific flags
CFLAGS += --target=wasm32-wasi
CFLAGS += --sysroot=$(WASI_SDK_PATH)/share/wasi-sysroot
# Disable C++ exceptions to avoid runtime errors
CXXFLAGS += -fno-exceptions
# Search path for header files
CFLAGS += -I.
CFLAGS += -I$(WASI_SDK_PATH)/share/wasi-sysroot/include
# C and C++ Compiler flags
CFLAGS += -Wall # Include all warnings
CFLAGS += -g # Generate GDB debugger information
CFLAGS += -Wno-strict-aliasing # Disable warnings about strict aliasing
CFLAGS += -Os # Optimize for size
CFLAGS += -DNDEBUG # Disable assert() macro
CFLAGS += -DEI_CLASSIFIER_ENABLE_DETECTION_POSTPROCESS_OP # Add TFLite_Detection_PostProcess operation
# C++ only compiler flags
CXXFLAGS += -std=c++14 # Use C++14 standard
# Linker flags
LDFLAGS += -Wl,--no-entry -Wl,--export-all
LDFLAGS += -nostartfiles
LDFLAGS += -Wl,--allow-undefined
LDFLAGS += -lstdc++
LDFLAGS += -Wl,--export=run_model_inference
LDFLAGS += -Wl,--export=get_model_parameters_json
LDFLAGS += -Wl,--export=get_labels
# Include C source code for required libraries
CSOURCES += $(wildcard edge-impulse-sdk/CMSIS/DSP/Source/TransformFunctions/*.c) \
$(wildcard edge-impulse-sdk/CMSIS/DSP/Source/CommonTables/*.c) \
$(wildcard edge-impulse-sdk/CMSIS/DSP/Source/BasicMathFunctions/*.c) \
$(wildcard edge-impulse-sdk/CMSIS/DSP/Source/ComplexMathFunctions/*.c) \
$(wildcard edge-impulse-sdk/CMSIS/DSP/Source/FastMathFunctions/*.c) \
$(wildcard edge-impulse-sdk/CMSIS/DSP/Source/SupportFunctions/*.c) \
$(wildcard edge-impulse-sdk/CMSIS/DSP/Source/MatrixFunctions/*.c) \
$(wildcard edge-impulse-sdk/CMSIS/DSP/Source/StatisticsFunctions/*.c)
# Include C++ source code for required libraries
CXXSOURCES += $(wildcard tflite-model/*.cpp) \
$(wildcard edge-impulse-sdk/dsp/kissfft/*.cpp) \
$(wildcard edge-impulse-sdk/dsp/dct/*.cpp) \
$(wildcard edge-impulse-sdk/dsp/memory.cpp) \
$(wildcard edge-impulse-sdk/porting/wasi/*.cpp)
# Use LiteRT (previously Tensorflow Lite) for Microcontrollers (TFLM)
CFLAGS += -DTF_LITE_DISABLE_X86_NEON=1
CSOURCES += edge-impulse-sdk/tensorflow/lite/c/common.c
CCSOURCES += $(wildcard edge-impulse-sdk/tensorflow/lite/kernels/*.cc) \
$(wildcard edge-impulse-sdk/tensorflow/lite/kernels/internal/*.cc) \
$(wildcard edge-impulse-sdk/tensorflow/lite/micro/kernels/*.cc) \
$(wildcard edge-impulse-sdk/tensorflow/lite/micro/*.cc) \
$(wildcard edge-impulse-sdk/tensorflow/lite/micro/memory_planner/*.cc) \
$(wildcard edge-impulse-sdk/tensorflow/lite/core/api/*.cc)
# Generate names for the output object files (*.o)
COBJECTS := $(patsubst %.c,%.o,$(CSOURCES))
CXXOBJECTS := $(patsubst %.cpp,%.o,$(CXXSOURCES))
CCOBJECTS := $(patsubst %.cc,%.o,$(CCSOURCES))
# Default rule
.PHONY: all
all: app
# Compile library source code into object files
$(COBJECTS) : %.o : %.c
$(CXXOBJECTS) : %.o : %.cpp
$(CCOBJECTS) : %.o : %.cc
%.o: %.c
$(CC) $(CFLAGS) -c $^ -o $@
%.o: %.cc
$(CXX) $(CFLAGS) $(CXXFLAGS) -c $^ -o $@
%.o: %.cpp
$(CXX) $(CFLAGS) $(CXXFLAGS) -c $^ -o $@
# Build target (must use C++ compiler)
.PHONY: app
app: $(COBJECTS) $(CXXOBJECTS) $(CCOBJECTS)
ifeq ($(OS), Windows_NT)
if not exist build mkdir build
else
mkdir -p $(BUILD_PATH)
endif
$(CXX) $(COBJECTS) $(CXXOBJECTS) $(CCOBJECTS) -o $(BUILD_PATH)/$(NAME) $(LDFLAGS)
@echo "Build completed: $(BUILD_PATH)/$(NAME)"
# Remove compiled object files
.PHONY: clean
clean:
ifeq ($(OS), Windows_NT)
del /Q $(subst /,\,$(patsubst %.c,%.o,$(CSOURCES))) >nul 2>&1 || exit 0
del /Q $(subst /,\,$(patsubst %.cpp,%.o,$(CXXSOURCES))) >nul 2>&1 || exit 0
del /Q $(subst /,\,$(patsubst %.cc,%.o,$(CCSOURCES))) >nul 2>&1 || exit 0
else
rm -f $(COBJECTS)
rm -f $(CCOBJECTS)
rm -f $(CXXOBJECTS)
endif