1 HOST_ARCH?=$(shell uname -p)
2 TARGET_ARCH?=$(shell uname -p)
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 # arm64 as target-arch comes from Android
20 TARGET_ARCH_BASE=arm64
21 # For now Android is the only option for arm64
23 else ifneq (,$(findstring arm,$(TARGET_ARCH_BASE)))
25 else ifneq (,$(findstring aarch64,$(TARGET_ARCH_BASE)))
26 # aarch64 as target-arch comes from all except for Android
27 TARGET_ARCH_BASE=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 ifeq ($(COVERAGE_BUILD),1)
42 OPTIONS+= -DENABLE_COVERAGE=ON
44 OPTIONS+= -DENABLE_COVERAGE=OFF
47 ifeq ($(BENCHMARK_ACL_BUILD),1)
48 OPTIONS+= -DBUILD_BENCHMARK_ACL=1
51 ifneq ($(EXT_ACL_FOLDER),)
52 OPTIONS+= -DBUILD_ARMCOMPUTE=OFF
53 OPTIONS+= -DARMCompute_EXTDIR=$(EXT_ACL_FOLDER)
56 ifneq ($(EXTERNAL_VOLUME),)
57 OPTIONS+= -DNNAS_EXTERNALS_DIR=$(EXTERNAL_VOLUME)
60 ifeq ($(TARGET_OS),android)
61 OPTIONS+= -DNDK_DIR=$(NDK_DIR)
64 ifneq ($(ANDROID_BUILD_TOOLS_DIR),)
65 OPTIONS+= -DANDROID_BUILD_TOOLS_DIR=$(ANDROID_BUILD_TOOLS_DIR)
68 ifneq ($(ANDROID_SDK_DIR),)
69 OPTIONS+= -DANDROID_SDK_DIR=$(ANDROID_SDK_DIR)
72 ifneq ($(TFLITE_MODEL_PATH),)
73 OPTIONS+= -DTFLITE_MODEL_PATH=$(TFLITE_MODEL_PATH)
76 ifneq ($(ANDROID_BOOST_ROOT),)
77 OPTIONS+= -DANDROID_BOOST_ROOT=$(ANDROID_BOOST_ROOT)
80 ifeq ($(PARALLEL_BUILD),1)
81 # Get number of processors (linux only for now)
82 ifeq ($(HOST_OS),linux)
83 NPROCS?=$(shell grep -c ^processor /proc/cpuinfo)
88 WORKHOME=$(CURDIR)/Product
89 WORKFOLDER=$(TARGET_ARCH_LC)-$(TARGET_OS).$(BUILD_TYPE_LC)
90 WORKSPACE=$(WORKHOME)/$(WORKFOLDER)
92 BUILD_FOLDER=$(WORKSPACE)/obj
93 INSTALL_PATH?=$(WORKSPACE)/out
94 OVERLAY_FOLDER?=$(WORKSPACE)/overlay
95 BUILD_ALIAS=$(WORKHOME)/obj
96 INSTALL_ALIAS=$(WORKHOME)/out
98 TIMESTAMP_CONFIGURE=$(WORKSPACE)/CONFIGURE
99 TIMESTAMP_BUILD=$(WORKSPACE)/BUILD
100 TIMESTAMP_INSTALL=$(WORKSPACE)/INSTALL
107 configure: configure_internal
109 build: build_internal
111 install: $(TIMESTAMP_INSTALL)
113 create_tar: runtime_tar_internal
120 rm -rf externals/*.stamp
121 rm -rf tests/nnapi/src/generated/
124 ### Command (internal)
127 NNFW_WORKSPACE="$(WORKSPACE)" NNFW_INSTALL_PREFIX=$(INSTALL_PATH) ./nnfw configure \
128 -DCMAKE_BUILD_TYPE=$(BUILD_TYPE_LC) -DTARGET_ARCH=$(TARGET_ARCH_LC) \
129 -DHOST_OS=$(HOST_OS) \
130 -DTARGET_OS=$(TARGET_OS) \
131 -DNNFW_OVERLAY_DIR=$(OVERLAY_FOLDER) \
133 touch $(TIMESTAMP_CONFIGURE)
135 build_internal: $(BUILD_FOLDER)
136 NNFW_WORKSPACE="$(WORKSPACE)" NPROCS="$(NPROCS)" PARALLEL_BUILD="1" ./nnfw build
137 rm -rf $(BUILD_ALIAS)
138 ln -s $(BUILD_FOLDER) $(BUILD_ALIAS)
139 touch $(TIMESTAMP_BUILD)
142 NNFW_WORKSPACE="$(WORKSPACE)" ./nnfw install
143 rm -rf $(INSTALL_ALIAS)
144 ln -s $(INSTALL_PATH) $(INSTALL_ALIAS)
145 touch $(TIMESTAMP_INSTALL)
147 runtime_tar_internal: $(TIMESTAMP_BUILD) install_internal
148 tar -zcf nnfw-package.tar.gz -C $(INSTALL_PATH) lib include
149 mv nnfw-package.tar.gz $(INSTALL_PATH)/.
151 install_internal_acl:
152 # Workaround to install acl for test (ignore error when there is no file to copy)
153 cp $(OVERLAY_FOLDER)/lib/* $(INSTALL_ALIAS)/lib || true
155 build_test_suite: install_internal install_internal_acl
156 @echo "packaging test suite"
157 @rm -rf $(INSTALL_PATH)/test-suite.tar.gz
158 # TODO Divide runtime package, external library package, and test suite
159 @tar -zcf test-suite.tar.gz tests/scripts tests/framework infra Product/out --dereference
160 @mv test-suite.tar.gz $(INSTALL_PATH)/.
162 build_coverage_suite: install_internal install_internal_acl
163 @echo "packaging test-coverage suite"
164 @rm -rf $(INSTALL_PATH)/coverage-suite.tar.gz
165 @find Product -name "*.gcno" > include_lists.txt
166 @pwd | grep -o '/' | wc -l > tests/scripts/build_path_depth.txt
167 @tar -zcf coverage-suite.tar.gz tests/scripts tests/framework infra Product/out --dereference -T include_lists.txt
168 @rm -rf include_lists.txt tests/scripts/build_path_depth.txt
169 @mv coverage-suite.tar.gz $(INSTALL_PATH)/.
177 $(BUILD_FOLDER): $(WORKSPACE) configure_internal
179 $(TIMESTAMP_CONFIGURE): configure_internal
181 $(TIMESTAMP_BUILD): $(TIMESTAMP_CONFIGURE) build_internal
183 $(TIMESTAMP_INSTALL): $(TIMESTAMP_BUILD) install_internal install_internal_acl