3 HOST_ARCH?=$(shell uname -m)
4 TARGET_ARCH?=$(shell uname -m)
12 # make TARGET and TYPE to lowercase
13 HOST_ARCH_LC=$(shell echo $(HOST_ARCH) | tr A-Z a-z)
14 TARGET_ARCH_LC=$(shell echo $(TARGET_ARCH) | tr A-Z a-z)
15 BUILD_TYPE_LC=$(shell echo $(BUILD_TYPE) | tr A-Z a-z)
16 # we need base name 'arm` for all arm arch
17 TARGET_ARCH_BASE=$(TARGET_ARCH_LC)
18 ifneq (,$(findstring arm64,$(TARGET_ARCH_BASE)))
19 TARGET_ARCH_LC=aarch64
20 else ifneq (,$(findstring arm,$(TARGET_ARCH_BASE)))
22 else ifneq (,$(findstring aarch64,$(TARGET_ARCH_BASE)))
23 TARGET_ARCH_LC=aarch64
25 ifneq (,$(findstring android,$(TARGET_OS)))
26 # Android only allow aarch64 target-arch
27 TARGET_ARCH_LC=aarch64
29 # Set CROSS_BUILD=1 when ROOTFS_DIR is given, and TARGET_ARCH is different to HOST_ARCH.
30 ifneq ($(ROOTFS_DIR),)
31 ifneq ($(TARGET_ARCH_LC),$(HOST_ARCH_LC))
32 CROSS_BUILD=$(if $(wildcard $(ROOTFS_DIR)),1,0)
35 # the toolchain file, only for cross build
36 ifeq ($(CROSS_BUILD),1)
37 TOOLCHAIN_FILE=cmake/buildtool/cross/toolchain_$(TARGET_ARCH_LC)-$(TARGET_OS).cmake
38 OPTIONS+= -DCMAKE_TOOLCHAIN_FILE=$(TOOLCHAIN_FILE)
41 ifneq ($(filter create-covsuite,$(MAKECMDGOALS)),)
42 OPTIONS+= -DENABLE_COVERAGE=ON
44 ifeq ($(COVERAGE_BUILD),1)
45 OPTIONS+= -DENABLE_COVERAGE=ON
47 OPTIONS+= -DENABLE_COVERAGE=OFF
51 ifneq ($(EXTERNAL_VOLUME),)
52 OPTIONS+= -DNNAS_EXTERNALS_DIR=$(EXTERNAL_VOLUME)
55 ifeq ($(TARGET_OS),android)
56 OPTIONS+= -DNDK_DIR=$(NDK_DIR)
59 ifneq ($(ANDROID_BUILD_TOOLS_DIR),)
60 OPTIONS+= -DANDROID_BUILD_TOOLS_DIR=$(ANDROID_BUILD_TOOLS_DIR)
63 ifneq ($(ANDROID_SDK_DIR),)
64 OPTIONS+= -DANDROID_SDK_DIR=$(ANDROID_SDK_DIR)
67 ifneq ($(TFLITE_MODEL_PATH),)
68 OPTIONS+= -DTFLITE_MODEL_PATH=$(TFLITE_MODEL_PATH)
71 ifneq ($(ANDROID_BOOST_ROOT),)
72 OPTIONS+= -DANDROID_BOOST_ROOT=$(ANDROID_BOOST_ROOT)
75 ifeq ($(HOST_OS),linux)
76 NPROCS?=$(shell grep -c ^processor /proc/cpuinfo)
81 WORKHOME=$(CURDIR)/Product
82 WORKFOLDER=$(TARGET_ARCH_LC)-$(TARGET_OS).$(BUILD_TYPE_LC)
83 WORKSPACE=$(WORKHOME)/$(WORKFOLDER)
85 INSTALL_PATH?=$(WORKSPACE)/out
86 OVERLAY_FOLDER?=$(WORKSPACE)/overlay
87 INSTALL_ALIAS=$(WORKHOME)/out
89 TIMESTAMP_CONFIGURE=$(WORKSPACE)/CONFIGURE
90 TIMESTAMP_BUILD=$(WORKSPACE)/BUILD
91 TIMESTAMP_INSTALL=$(WORKSPACE)/INSTALL
94 ### Common environment variable
96 export NNFW_WORKSPACE=$(WORKSPACE)
99 ### Common environment variable for compiler module
101 NNCC_FOLDER=Product/$(WORKFOLDER)/nncc
102 export NNCC_WORKSPACE=$(NNCC_FOLDER)
112 prepare-nncc: prepare_nncc_internal
114 configure: configure_internal
116 build: build_internal
118 install: install_all_internal
120 create-package: runtime_tar_internal
122 create-aclpack: acl_tar_internal
124 create-testsuite: test_suite_internal
126 create-covsuite: coverage_suite_internal
134 rm -rf tests/nnapi/src/generated/
136 # create_package, create_acl_tar: to be removed
137 create_package: runtime_tar_internal
138 create_acl_tar: acl_tar_internal
141 ### Command (internal)
146 prepare_nncc_internal: $(WORKSPACE)
147 ifneq ($(CROSS_BUILD),1)
148 ./nncc configure -DBUILD_GTEST=OFF -DENABLE_TEST=OFF -DEXTERNALS_BUILD_THREADS=$(NPROCS) -DCMAKE_BUILD_TYPE=$(BUILD_TYPE) \
149 -DCMAKE_INSTALL_PREFIX=$(OVERLAY_FOLDER) \
150 -DBUILD_WHITELIST="luci;foder;pepper-csv2vec;loco;locop;logo;logo-core;mio-circle06;luci-compute;oops;hermes;hermes-std;angkor;pp;pepper-strcast;pepper-str"
151 ./nncc build -j$(NPROCS)
152 cmake --install $(NNCC_FOLDER)
153 # install angkor TensorIndex and oops InternalExn header (TODO: Remove this)
154 @mkdir -p ${OVERLAY_FOLDER}/include/nncc/core/ADT/tensor
155 @mkdir -p ${OVERLAY_FOLDER}/include/oops
156 @cp compiler/angkor/include/nncc/core/ADT/tensor/Index.h ${OVERLAY_FOLDER}/include/nncc/core/ADT/tensor
157 @cp compiler/oops/include/oops/InternalExn.h ${OVERLAY_FOLDER}/include/oops
159 @echo "Done prepare-nncc"
161 configure_internal: $(WORKSPACE)
162 ifneq ($(DEBIAN_BUILD),)
163 test -d externals || mkdir -p externals
164 find packaging/ -type f -name "*.tar.gz" | xargs -i tar xf {} -C externals
166 NNFW_INSTALL_PREFIX=$(INSTALL_PATH) ./nnfw configure \
167 -DCMAKE_BUILD_TYPE=$(BUILD_TYPE_LC) \
168 -DNNFW_OVERLAY_DIR=$(OVERLAY_FOLDER) \
169 -DEXTERNALS_BUILD_THREADS=$(NPROCS) \
172 build_internal: configure_internal
173 ./nnfw build -j $(NPROCS)
175 install_internal: build_internal
177 rm -rf $(INSTALL_ALIAS)
178 ln -s $(INSTALL_PATH) $(INSTALL_ALIAS)
180 runtime_tar_internal: build_internal install_internal
181 tar -zcf $(WORKSPACE)/onert-package.tar.gz -C $(INSTALL_PATH) lib
182 tar -zcf $(WORKSPACE)/onert-devel-package.tar.gz -C $(INSTALL_PATH) include/nnfw
183 tar -zcf $(WORKSPACE)/onert-plugin-devel-package.tar.gz -C $(INSTALL_PATH) include/onert
184 tar -zcf $(WORKSPACE)/onert-test-package.tar.gz -C $(INSTALL_PATH) $(shell ls $(INSTALL_PATH) -I lib -I include)
186 acl_tar_internal: configure_internal
187 tar -zcf $(WORKSPACE)/onert-acl.tar.gz -C ${OVERLAY_FOLDER} lib/libarm_compute.so lib/libarm_compute_core.so lib/libarm_compute_graph.so
189 install_acl_internal:
190 # Workaround to install acl for test (ignore error when there is no file to copy)
191 @cp $(OVERLAY_FOLDER)/lib/libarm_compute*.so $(INSTALL_ALIAS)/lib 2>/dev/null || true
193 install_luci_internal:
194 @mkdir -p $(INSTALL_ALIAS)/lib/nnfw/odc
195 @cp $(OVERLAY_FOLDER)/lib/libluci*.so $(INSTALL_ALIAS)/lib/nnfw/odc 2>/dev/null || true
196 @cp $(OVERLAY_FOLDER)/lib/libloco*.so $(INSTALL_ALIAS)/lib/nnfw/odc 2>/dev/null || true
198 install_all_internal: install_internal install_acl_internal install_luci_internal
200 test_suite_internal: install_all_internal
201 @echo "packaging test suite"
202 @rm -rf $(INSTALL_PATH)/test-suite.tar.gz
203 # TODO Divide runtime package, external library package, and test suite
204 @tar -zcf test-suite.tar.gz tests/scripts infra Product/out --dereference
205 @mv test-suite.tar.gz $(INSTALL_PATH)/.
207 coverage_suite_internal: install_all_internal
208 @echo "packaging test-coverage suite"
209 @rm -rf $(INSTALL_PATH)/coverage-suite.tar.gz
210 @find Product -name "*.gcno" > include_lists.txt
211 @pwd | grep -o '/' | wc -l > tests/scripts/build_path_depth.txt
212 @tar -zcf coverage-suite.tar.gz tests/scripts infra Product/out --dereference -T include_lists.txt
213 @rm -rf include_lists.txt tests/scripts/build_path_depth.txt
214 @mv coverage-suite.tar.gz $(INSTALL_PATH)/.