2e5d0bd0287fcc096fcc955b9345599ff36d6b28
[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 ### Default target
100 ###
101 all: install
102
103 ###
104 ### Command (public)
105 ###
106 configure: configure_internal
107
108 build: build_internal
109
110 install: install_all_internal
111
112 create-package: runtime_tar_internal
113
114 create-aclpack: acl_tar_internal
115
116 create-testsuite: test_suite_internal
117
118 create-covsuite: coverage_suite_internal
119
120 clean:
121         rm -rf $(WORKSPACE)
122
123 distclean:
124         rm -rf Product
125         rm -rf externals
126         rm -rf tests/nnapi/src/generated/
127
128 # create_package, create_acl_tar: to be removed
129 create_package: runtime_tar_internal
130 create_acl_tar: acl_tar_internal
131
132 ###
133 ### Command (internal)
134 ###
135 $(WORKSPACE):
136         mkdir -p $@
137
138 configure_internal: $(WORKSPACE)
139 ifneq ($(DEBIAN_BUILD),)
140         test -d externals || mkdir -p externals
141         find packaging/ -type f -name "*.tar.gz" | xargs -i tar xf {} -C externals
142 endif
143         NNFW_INSTALL_PREFIX=$(INSTALL_PATH) ./nnfw configure \
144                 -DCMAKE_BUILD_TYPE=$(BUILD_TYPE_LC) \
145                 -DNNFW_OVERLAY_DIR=$(OVERLAY_FOLDER) \
146                 -DEXTERNALS_BUILD_THREADS=$(NPROCS) \
147                 $(OPTIONS)
148
149 build_internal: configure_internal
150         ./nnfw build -j $(NPROCS)
151
152 install_internal: build_internal
153         ./nnfw install
154         rm -rf $(INSTALL_ALIAS)
155         ln -s $(INSTALL_PATH) $(INSTALL_ALIAS)
156
157 runtime_tar_internal: build_internal install_internal
158         tar -zcf $(WORKSPACE)/onert-package.tar.gz -C $(INSTALL_PATH) lib
159         tar -zcf $(WORKSPACE)/onert-devel-package.tar.gz -C $(INSTALL_PATH) include/nnfw
160         tar -zcf $(WORKSPACE)/onert-plugin-devel-package.tar.gz -C $(INSTALL_PATH) include/onert
161         tar -zcf $(WORKSPACE)/onert-test-package.tar.gz -C $(INSTALL_PATH) $(shell ls $(INSTALL_PATH) -I lib -I include)
162
163 acl_tar_internal: configure_internal
164         tar -zcf $(WORKSPACE)/onert-acl.tar.gz -C ${OVERLAY_FOLDER} lib/libarm_compute.so lib/libarm_compute_core.so lib/libarm_compute_graph.so
165
166 install_acl_internal:
167 # Workaround to install acl for test (ignore error when there is no file to copy)
168         cp $(OVERLAY_FOLDER)/lib/libarm_compute*.so $(INSTALL_ALIAS)/lib || true
169
170 install_all_internal: install_internal install_acl_internal
171
172 test_suite_internal: install_all_internal
173         @echo "packaging test suite"
174         @rm -rf $(INSTALL_PATH)/test-suite.tar.gz
175 # TODO Divide runtime package, external library package, and test suite
176         @tar -zcf test-suite.tar.gz tests/scripts infra Product/out --dereference
177         @mv test-suite.tar.gz $(INSTALL_PATH)/.
178
179 coverage_suite_internal: install_all_internal
180         @echo "packaging test-coverage suite"
181         @rm -rf $(INSTALL_PATH)/coverage-suite.tar.gz
182         @find Product -name "*.gcno" > include_lists.txt
183         @pwd | grep -o '/' | wc -l > tests/scripts/build_path_depth.txt
184         @tar -zcf coverage-suite.tar.gz tests/scripts infra Product/out --dereference -T include_lists.txt
185         @rm -rf include_lists.txt tests/scripts/build_path_depth.txt
186         @mv coverage-suite.tar.gz $(INSTALL_PATH)/.