-
Notifications
You must be signed in to change notification settings - Fork 157
/
Makefile.template
234 lines (194 loc) · 7.28 KB
/
Makefile.template
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
#!/usr/bin/make -f
HOST_ARCH?=$(shell uname -m)
TARGET_ARCH?=$(shell uname -m)
BUILD_TYPE?=Debug
CROSS_BUILD?=0
HOST_OS?=linux
TARGET_OS?=linux
COVERAGE_BUILD?=0
OPTIONS?=
OPTIONS_NNCC?=
INSTALL_OPTIONS?=
# make TARGET and TYPE to lowercase
HOST_ARCH_LC=$(shell echo $(HOST_ARCH) | tr A-Z a-z)
TARGET_ARCH_LC=$(shell echo $(TARGET_ARCH) | tr A-Z a-z)
BUILD_TYPE_LC=$(shell echo $(BUILD_TYPE) | tr A-Z a-z)
# we need base name 'arm` for all arm arch
TARGET_ARCH_BASE=$(TARGET_ARCH_LC)
ifneq (,$(findstring arm64,$(TARGET_ARCH_BASE)))
TARGET_ARCH_LC=aarch64
else ifneq (,$(findstring arm,$(TARGET_ARCH_BASE)))
TARGET_ARCH_LC=armv7l
else ifneq (,$(findstring aarch64,$(TARGET_ARCH_BASE)))
TARGET_ARCH_LC=aarch64
endif
ifneq (,$(findstring android,$(TARGET_OS)))
# Android only allow aarch64 target-arch
TARGET_ARCH_LC=aarch64
endif
# Set CROSS_BUILD=1 when ROOTFS_DIR is given, and TARGET_ARCH is different to HOST_ARCH.
ifneq ($(ROOTFS_DIR),)
ifneq ($(TARGET_ARCH_LC),$(HOST_ARCH_LC))
CROSS_BUILD=$(if $(wildcard $(ROOTFS_DIR)),1,0)
endif
endif
# the toolchain file, only for cross build
ifeq ($(CROSS_BUILD),1)
TOOLCHAIN_FILE=cmake/buildtool/cross/toolchain_$(TARGET_ARCH_LC)-$(TARGET_OS).cmake
OPTIONS+= -DCMAKE_TOOLCHAIN_FILE=$(TOOLCHAIN_FILE)
OPTIONS_NNCC+= -DCMAKE_TOOLCHAIN_FILE=$(TOOLCHAIN_FILE)
endif
ifneq ($(filter create-covsuite,$(MAKECMDGOALS)),)
OPTIONS+= -DENABLE_COVERAGE=ON
else
ifeq ($(COVERAGE_BUILD),1)
OPTIONS+= -DENABLE_COVERAGE=ON
else
OPTIONS+= -DENABLE_COVERAGE=OFF
endif
endif
ifneq ($(EXTERNAL_VOLUME),)
OPTIONS+= -DNNAS_EXTERNALS_DIR=$(EXTERNAL_VOLUME)
OPTIONS_NNCC+= -DNNAS_EXTERNALS_DIR=$(EXTERNAL_VOLUME)
endif
ifeq ($(TARGET_OS),android)
OPTIONS+= -DNDK_DIR=$(NDK_DIR)
OPTIONS_NNCC+= -DNDK_DIR=$(NDK_DIR)
endif
ifneq ($(ANDROID_BUILD_TOOLS_DIR),)
OPTIONS+= -DANDROID_BUILD_TOOLS_DIR=$(ANDROID_BUILD_TOOLS_DIR)
endif
ifneq ($(ANDROID_SDK_DIR),)
OPTIONS+= -DANDROID_SDK_DIR=$(ANDROID_SDK_DIR)
endif
ifneq ($(TFLITE_MODEL_PATH),)
OPTIONS+= -DTFLITE_MODEL_PATH=$(TFLITE_MODEL_PATH)
endif
ifeq ($(HOST_OS),linux)
NPROCS?=$(shell grep -c ^processor /proc/cpuinfo)
else
NPROCS?=1
endif
ifeq ($(BUILD_TYPE_LC),release)
INSTALL_OPTIONS+= --strip
endif
WORKHOME=$(CURDIR)/Product
WORKFOLDER=$(TARGET_ARCH_LC)-$(TARGET_OS).$(BUILD_TYPE_LC)
WORKSPACE=$(WORKHOME)/$(WORKFOLDER)
BUILDTOOL_WORKSPACE=$(WORKHOME)/buildtool
INSTALL_PATH?=$(WORKSPACE)/out
OVERLAY_FOLDER?=$(WORKSPACE)/overlay
INSTALL_ALIAS=$(WORKHOME)/out
BUILDTOOL_PATH?=$(BUILDTOOL_WORKSPACE)/out
TIMESTAMP_CONFIGURE=$(WORKSPACE)/CONFIGURE
TIMESTAMP_BUILD=$(WORKSPACE)/BUILD
TIMESTAMP_INSTALL=$(WORKSPACE)/INSTALL
###
### Common environment variable
###
export NNFW_WORKSPACE=$(WORKSPACE)
###
### Common environment variable for compiler module
###
NNCC_FOLDER=Product/$(WORKFOLDER)/nncc
export NNCC_WORKSPACE=$(NNCC_FOLDER)
###
### Default target
###
all: prepare-buildtool prepare-nncc configure build install
###
### Command (build step)
###
prepare-buildtool: prepare_buildtool_internal
prepare-nncc: prepare_nncc_internal
configure: configure_internal
build: build_internal
install: install_all_internal
###
### Command (public)
###
# Don't install arm compute
create-package: prepare-buildtool prepare-nncc configure build install_except_acl runtime_tar_internal
create-aclpack: configure acl_tar_internal
create-testsuite: all test_suite_internal
create-covsuite: all coverage_suite_internal
clean:
rm -rf $(WORKSPACE)
distclean:
rm -rf Product
rm -rf externals
rm -rf tests/nnapi/src/generated/
###
### Command (internal)
###
$(WORKSPACE):
mkdir -p $@
prepare_buildtool_internal: $(WORKSPACE)
cmake -S infra/buildtool -B $(BUILDTOOL_WORKSPACE)/obj -DBUILDTOOL_PATH=$(BUILDTOOL_PATH)
cmake --build $(BUILDTOOL_WORKSPACE)/obj/ -j$(NPROCS)
prepare_nncc_internal: $(WORKSPACE)
ifeq (,$(findstring android,$(TARGET_OS)))
EXTERNAL_FLATC=$(BUILDTOOL_PATH)/bin/flatc ./nncc configure -DBUILD_GTEST=OFF -DENABLE_TEST=OFF -DEXTERNALS_BUILD_THREADS=$(NPROCS) -DCMAKE_BUILD_TYPE=$(BUILD_TYPE) \
-DCMAKE_INSTALL_PREFIX=$(OVERLAY_FOLDER) \
-DBUILD_WHITELIST="luci;foder;pepper-csv2vec;loco;locop;logo;logo-core;mio-circle08;luci-compute;oops;hermes;hermes-std;angkor;pp;pepper-strcast;pepper-str" \
$(OPTIONS_NNCC)
./nncc build -j$(NPROCS)
cmake --install $(NNCC_FOLDER) $(INSTALL_OPTIONS)
# install angkor TensorIndex and oops InternalExn header (TODO: Remove this)
@mkdir -p ${OVERLAY_FOLDER}/include/nncc/core/ADT/tensor
@mkdir -p ${OVERLAY_FOLDER}/include/oops
@mkdir -p ${OVERLAY_FOLDER}/include/luci/IR
@mkdir -p ${OVERLAY_FOLDER}/include/mio/circle
@cp compiler/angkor/include/nncc/core/ADT/tensor/Index.h ${OVERLAY_FOLDER}/include/nncc/core/ADT/tensor
@cp compiler/oops/include/oops/InternalExn.h ${OVERLAY_FOLDER}/include/oops
@cp compiler/luci/lang/include/luci/IR/CircleNodes.lst ${OVERLAY_FOLDER}/include/luci/IR
@cp ${NNCC_WORKSPACE}/compiler/mio-circle08/gen/mio/circle/schema_generated.h ${OVERLAY_FOLDER}/include/mio/circle
@cp -r ${NNCC_WORKSPACE}/overlay/include/flatbuffers ${OVERLAY_FOLDER}/include
@echo "Done prepare-nncc"
endif
configure_internal: $(WORKSPACE)
ifneq ($(DEBIAN_BUILD),)
test -d externals || mkdir -p externals
find packaging/ -type f -name "*.tar.gz" | xargs -i tar xf {} -C externals
endif
./nnfw configure \
-DCMAKE_BUILD_TYPE=$(BUILD_TYPE_LC) \
-DNNFW_OVERLAY_DIR=$(OVERLAY_FOLDER) \
-DEXTERNALS_BUILD_THREADS=$(NPROCS) \
$(OPTIONS)
build_internal:
./nnfw build -j $(NPROCS)
install_internal:
./nnfw install --prefix $(INSTALL_PATH) $(INSTALL_OPTIONS)
rm -rf $(INSTALL_ALIAS)
ln -s $(INSTALL_PATH) $(INSTALL_ALIAS)
runtime_tar_internal:
tar -zcf $(WORKSPACE)/onert-package.tar.gz -C $(INSTALL_PATH) lib
tar -zcf $(WORKSPACE)/onert-devel-package.tar.gz -C $(INSTALL_PATH) include/nnfw
tar -zcf $(WORKSPACE)/onert-plugin-devel-package.tar.gz -C $(INSTALL_PATH) include/onert
tar -zcf $(WORKSPACE)/onert-test-package.tar.gz -C $(INSTALL_PATH) $(shell ls $(INSTALL_PATH) -I lib -I include)
acl_tar_internal:
tar -zcf $(WORKSPACE)/onert-acl.tar.gz -C ${OVERLAY_FOLDER} lib/libarm_compute.so lib/libarm_compute_graph.so
install_acl_internal:
# Workaround to install acl for test (ignore error when there is no file to copy)
@cp $(OVERLAY_FOLDER)/lib/libarm_compute*.so $(INSTALL_ALIAS)/lib 2>/dev/null || true
install_luci_internal:
@mkdir -p $(INSTALL_ALIAS)/lib/nnfw/odc
@cp $(OVERLAY_FOLDER)/lib/libluci*.so $(INSTALL_ALIAS)/lib/nnfw/odc 2>/dev/null || true
@cp $(OVERLAY_FOLDER)/lib/libloco*.so $(INSTALL_ALIAS)/lib/nnfw/odc 2>/dev/null || true
install_except_acl: install_internal install_luci_internal
install_all_internal: install_except_acl install_acl_internal
test_suite_internal: install_all_internal
@echo "packaging test suite"
@rm -rf $(INSTALL_PATH)/test-suite.tar.gz
# TODO Divide runtime package, external library package, and test suite
@tar -zcf test-suite.tar.gz tests/scripts infra Product/out --dereference
@mv test-suite.tar.gz $(INSTALL_PATH)/.
coverage_suite_internal: install_all_internal
@echo "packaging test-coverage suite"
@rm -rf $(INSTALL_PATH)/coverage-suite.tar.gz
@find Product -name "*.gcno" > include_lists.txt
@pwd | grep -o '/' | wc -l > tests/scripts/build_path_depth.txt
@tar -zcf coverage-suite.tar.gz tests/scripts infra Product/out --dereference -T include_lists.txt
@rm -rf include_lists.txt tests/scripts/build_path_depth.txt
@mv coverage-suite.tar.gz $(INSTALL_PATH)/.