Imported Upstream version 1.25.0
[platform/core/ml/nnfw.git] / Makefile.template
1 #!/usr/bin/make -f
2
3 HOST_ARCH?=$(shell uname -m)
4 TARGET_ARCH?=$(shell uname -m)
5 BUILD_TYPE?=Debug
6 CROSS_BUILD?=0
7 HOST_OS?=linux
8 TARGET_OS?=linux
9 COVERAGE_BUILD?=0
10 OPTIONS?=
11
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)))
21         TARGET_ARCH_LC=armv7l
22 else ifneq (,$(findstring aarch64,$(TARGET_ARCH_BASE)))
23         TARGET_ARCH_LC=aarch64
24 endif
25 ifneq (,$(findstring android,$(TARGET_OS)))
26         # Android only allow aarch64 target-arch
27         TARGET_ARCH_LC=aarch64
28 endif
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)
33 endif
34 endif
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)
39 endif
40
41 ifneq ($(filter create-covsuite,$(MAKECMDGOALS)),)
42         OPTIONS+= -DENABLE_COVERAGE=ON
43 else
44         ifeq ($(COVERAGE_BUILD),1)
45                 OPTIONS+= -DENABLE_COVERAGE=ON
46         else
47                 OPTIONS+= -DENABLE_COVERAGE=OFF
48         endif
49 endif
50
51 ifneq ($(EXTERNAL_VOLUME),)
52         OPTIONS+= -DNNAS_EXTERNALS_DIR=$(EXTERNAL_VOLUME)
53 endif
54
55 ifeq ($(TARGET_OS),android)
56         OPTIONS+= -DNDK_DIR=$(NDK_DIR)
57 endif
58
59 ifneq ($(ANDROID_BUILD_TOOLS_DIR),)
60   OPTIONS+= -DANDROID_BUILD_TOOLS_DIR=$(ANDROID_BUILD_TOOLS_DIR)
61 endif
62
63 ifneq ($(ANDROID_SDK_DIR),)
64   OPTIONS+= -DANDROID_SDK_DIR=$(ANDROID_SDK_DIR)
65 endif
66
67 ifneq ($(TFLITE_MODEL_PATH),)
68   OPTIONS+= -DTFLITE_MODEL_PATH=$(TFLITE_MODEL_PATH)
69 endif
70
71 ifneq ($(ANDROID_BOOST_ROOT),)
72   OPTIONS+= -DANDROID_BOOST_ROOT=$(ANDROID_BOOST_ROOT)
73 endif
74
75 ifeq ($(HOST_OS),linux)
76         NPROCS?=$(shell grep -c ^processor /proc/cpuinfo)
77 else
78         NPROCS?=1
79 endif
80
81 WORKHOME=$(CURDIR)/Product
82 WORKFOLDER=$(TARGET_ARCH_LC)-$(TARGET_OS).$(BUILD_TYPE_LC)
83 WORKSPACE=$(WORKHOME)/$(WORKFOLDER)
84
85 INSTALL_PATH?=$(WORKSPACE)/out
86 OVERLAY_FOLDER?=$(WORKSPACE)/overlay
87 INSTALL_ALIAS=$(WORKHOME)/out
88
89 TIMESTAMP_CONFIGURE=$(WORKSPACE)/CONFIGURE
90 TIMESTAMP_BUILD=$(WORKSPACE)/BUILD
91 TIMESTAMP_INSTALL=$(WORKSPACE)/INSTALL
92
93 ###
94 ### Common environment variable
95 ###
96 export NNFW_WORKSPACE=$(WORKSPACE)
97
98 ###
99 ### Common environment variable for compiler module
100 ###
101 NNCC_FOLDER=Product/$(WORKFOLDER)/nncc
102 export NNCC_WORKSPACE=$(NNCC_FOLDER)
103
104 ###
105 ### Default target
106 ###
107 all: install
108
109 ###
110 ### Command (public)
111 ###
112 prepare-nncc: prepare_nncc_internal
113
114 configure: configure_internal
115
116 build: build_internal
117
118 install: install_all_internal
119
120 create-package: runtime_tar_internal
121
122 create-aclpack: acl_tar_internal
123
124 create-testsuite: test_suite_internal
125
126 create-covsuite: coverage_suite_internal
127
128 clean:
129         rm -rf $(WORKSPACE)
130
131 distclean:
132         rm -rf Product
133         rm -rf externals
134         rm -rf tests/nnapi/src/generated/
135
136 # create_package, create_acl_tar: to be removed
137 create_package: runtime_tar_internal
138 create_acl_tar: acl_tar_internal
139
140 ###
141 ### Command (internal)
142 ###
143 $(WORKSPACE):
144         mkdir -p $@
145
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
158 endif
159         @echo "Done prepare-nncc"
160
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
165 endif
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) \
170                 $(OPTIONS)
171
172 build_internal: configure_internal
173         ./nnfw build -j $(NPROCS)
174
175 install_internal: build_internal
176         ./nnfw install
177         rm -rf $(INSTALL_ALIAS)
178         ln -s $(INSTALL_PATH) $(INSTALL_ALIAS)
179
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)
185
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
188
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
192
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
197
198 install_all_internal: install_internal install_acl_internal install_luci_internal
199
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)/.
206
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)/.