Change script for apply upstream code
[platform/upstream/connectedhomeip.git] / config / k32w / k32w061-chip.mk
1 #
2 #   Copyright (c) 2020 Project CHIP Authors
3 #
4 #   Licensed under the Apache License, Version 2.0 (the "License");
5 #   you may not use this file except in compliance with the License.
6 #   You may obtain a copy of the License at
7 #
8 #       http://www.apache.org/licenses/LICENSE-2.0
9 #
10 #   Unless required by applicable law or agreed to in writing, software
11 #   distributed under the License is distributed on an "AS IS" BASIS,
12 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 #   See the License for the specific language governing permissions and
14 #   limitations under the License.
15 #
16
17 #
18 #   @file
19 #         Component makefile for incorporating CHIP into a k32w061
20 #         application.
21 #
22 #   This makefile is intended to work in conjunction with the k32w061-app.mk
23 #   makefile to build the CHIP example applications on NXP platforms.
24 #   k32w061 applications should include this file in their top level Makefile
25 #   after including k32w061-app.mk.  E.g.:
26 #
27 #       PROJECT_ROOT = $(realpath .)
28 #
29 #       BUILD_SUPPORT_DIR = $(PROJECT_ROOT)/third_party/connectedhomeip/config/k32w
30 #
31 #       include $(BUILD_SUPPORT_DIR)/k32w061-app.mk
32 #       include $(BUILD_SUPPORT_DIR)/k32w061-chip.mk
33 #
34 #       PROJECT_ROOT := $(realpath .)
35 #
36 #       APP := chip-k32w061-bringup
37 #
38 #       SRCS = \
39 #           $(PROJECT_ROOT)/main.cpp \
40 #           ...
41 #
42 #       $(call GenerateBuildRules)
43 #
44 # ==================================================
45 # General settings
46 # ==================================================
47
48 # Location of CHIP source tree
49 CHIP_ROOT ?= $(PROJECT_ROOT)/third_party/connectedhomeip
50
51 # Archtecture for which CHIP will be built.
52 CHIP_HOST_ARCH := armv7-unknown-linux-gnu
53
54 # Directory into which the CHIP build system will place its output.
55 CHIP_OUTPUT_DIR = $(OUTPUT_DIR)/chip
56
57 # An optional file containing application-specific configuration overrides.
58 CHIP_PROJECT_CONFIG = $(wildcard $(PROJECT_ROOT)/include/CHIPProjectConfig.h)
59
60 # Architcture on which CHIP is being built.
61 CHIP_BUILD_ARCH = $(shell $(CHIP_ROOT)/third_party/nlbuild-autotools/repo/third_party/autoconf/config.guess | sed -e 's/[[:digit:].]*$$//g')
62
63 # ==================================================
64 # Compilation flags specific to building CHIP
65 # ==================================================
66
67 CHIP_DEFINES +=                                                                                                                    \
68     MBEDTLS_CONFIG_FILE=\<$(CHIP_ROOT)/third_party/openthread/repo/third_party/mbedtls/mbedtls-config.h\>                          \
69     MBEDTLS_USER_CONFIG_FILE=\<$(CHIP_ROOT)/third_party/openthread/repo/examples/platforms/k32w/k32w061/k32w061-mbedtls-config.h\> \
70     MBEDTLS_THREADING_C=1                                                                                                          \
71     MBEDTLS_THREADING_ALT=1                                                                                                        \
72     MBEDTLS_X509_CSR_WRITE_C                                                                                                       \
73     MBEDTLS_X509_CREATE_C                                                                                                          \
74     MBEDTLS_PK_WRITE_C                                                                                                             \
75     MBEDTLS_OID_C                                                                                                                  \
76     MBEDTLS_PEM_WRITE_C                                                                                                            \
77     MBEDTLS_BASE64_C                                                                                                               \
78     MBEDTLS_SSL_COOKIE_C                                                                                                           \
79     MBEDTLS_HKDF_C                                                                                                                 \
80     MBEDTLS_SSL_SRV_C                                                                                                              \
81     MBEDTLS_ERROR_C
82
83 CHIP_DEFINE_FLAGS = $(foreach def,$(CHIP_DEFINES),-D$(def))
84 CHIP_CPPFLAGS = $(STD_CFLAGS) $(CFLAGS) $(DEBUG_FLAGS) $(OPT_FLAGS) $(DEFINE_FLAGS) $(CHIP_DEFINE_FLAGS) $(INC_FLAGS)
85 CHIP_CXXFLAGS = $(STD_CXXFLAGS) $(CXXFLAGS)
86
87 # ==================================================
88 # CHIP configuration options
89 # ==================================================
90
91 CHIP_CONFIGURE_OPTIONS = \
92     -C AR="$(AR)" AS="$(AS)" CC="$(CCACHE) $(CC)" CXX="$(CCACHE) $(CXX)"                                                               \
93     LD="$(LD)" OBJCOPY="$(OBJCOPY)" RANLIB="$(RANLIB)" INSTALL="$(INSTALL) $(INSTALLFLAGS)"                                            \
94     CPPFLAGS="$(CHIP_CPPFLAGS) -imacros $(CHIP_ROOT)/third_party/openthread/repo/examples/platforms/k32w/k32w061/k32w061-sdk-config.h" \
95     CXXFLAGS="$(CHIP_CXXFLAGS)"                                                                                                        \
96     --prefix=$(CHIP_OUTPUT_DIR)                                                                                                        \
97     --exec-prefix=$(CHIP_OUTPUT_DIR)                                                                                                   \
98     --host=$(CHIP_HOST_ARCH)                                                                                                           \
99     --build=$(CHIP_BUILD_ARCH)                                                                                                         \
100     --with-target-style=embedded                                                                                                       \
101     --with-device-layer=k32w                                                                                                           \
102     --with-network-layer=all                                                                                                           \
103     --with-target-network=lwip                                                                                                         \
104     --with-lwip=internal                                                                                                               \
105     --with-lwip-target=k32w                                                                                                            \
106     --with-inet-endpoint="tcp udp"                                                                                                     \
107     --with-openssl=no                                                                                                                  \
108     --with-openthread=internal                                                                                                         \
109     --with-logging-style=external                                                                                                      \
110     --with-chip-project-includes=$(CHIP_PROJECT_CONFIG)                                                                                \
111     --with-chip-system-project-includes=$(CHIP_PROJECT_CONFIG)                                                                         \
112     --with-chip-inet-project-includes=$(CHIP_PROJECT_CONFIG)                                                                           \
113     --with-chip-ble-project-includes=$(CHIP_PROJECT_CONFIG)                                                                            \
114     --with-chip-warm-project-includes=$(CHIP_PROJECT_CONFIG)                                                                           \
115     --with-chip-device-project-includes=$(CHIP_PROJECT_CONFIG)                                                                         \
116     --disable-ipv4                                                                                                                     \
117     --disable-tests                                                                                                                    \
118     --disable-tools                                                                                                                    \
119     --disable-docs                                                                                                                     \
120     --disable-java                                                                                                                     \
121     --disable-device-manager                                                                                                           \
122     --with-crypto=mbedtls
123
124 # Enable / disable optimization.
125 ifeq ($(OPT),1)
126 CHIP_CONFIGURE_OPTIONS += --enable-optimization=yes
127 else
128 CHIP_CONFIGURE_OPTIONS += --enable-optimization=no
129 endif
130
131 ifeq ($(DEBUG),1)
132 CHIP_CONFIGURE_OPTIONS += --enable-debug
133 endif
134 # ==================================================
135 # Adjustments to standard build settings to
136 #   incorporate CHIP
137 # ==================================================
138
139 # Add CHIP-specific paths to the standard include directories.
140 STD_INC_DIRS +=                                                                                      \
141     $(CHIP_OUTPUT_DIR)/include                                                                       \
142     $(CHIP_OUTPUT_DIR)/src/include                                                                   \
143     $(CHIP_OUTPUT_DIR)/third_party/openthread/include                                                \
144     $(CHIP_ROOT)/third_party/lwip/repo/lwip/src/include                                              \
145     $(CHIP_ROOT)/third_party/openthread/repo/third_party/nxp/K32W061DK6/middleware/mbedtls/port/ksdk \
146     $(CHIP_ROOT)/src/lwip                                                                            \
147     $(CHIP_ROOT)/src/lwip/k32w                                                                       \
148     $(CHIP_ROOT)/src/lwip/freertos                                                                   \
149     $(K32W061_SDK_ROOT)/CMSIS/Include                                                                \
150     $(K32W061_SDK_ROOT)/devices/K32W061                                                              \
151     $(K32W061_SDK_ROOT)/devices/K32W061/drivers                                                      \
152     $(K32W061_SDK_ROOT)/devices/K32W061/utilities                                                    \
153     $(K32W061_SDK_ROOT)/devices/K32W061/utilities/debug_console                                      \
154     $(K32W061_SDK_ROOT)/devices/K32W061/utilities/str                                                \
155     $(K32W061_SDK_ROOT)/middleware/wireless/framework/Common                                         \
156     $(K32W061_SDK_ROOT)/middleware/wireless/framework/Lists                                          \
157     $(K32W061_SDK_ROOT)/middleware/wireless/framework/PDM/Include                                    \
158     $(K32W061_SDK_ROOT)/middleware/wireless/framework/MemManager/Interface                           \
159     $(CHIP_ROOT)/third_party/openthread/repo/examples/platforms
160
161 # Add the location of CHIP libraries to application link action.
162 STD_LDFLAGS += -L$(CHIP_OUTPUT_DIR)/lib
163
164 # Add CHIP libraries to standard libraries list.
165 STD_LIBS +=       \
166     -lDeviceLayer \
167     -lCHIP        \
168     -lInetLayer   \
169     -lSystemLayer \
170     -llwip        \
171     -lmbedtls
172
173 # Add the appropriate CHIP target as a prerequisite to all application
174 # compilation targets to ensure that CHIP gets built and its header
175 # files installed prior to compiling any dependent source files.
176 STD_COMPILE_PREREQUISITES += install-chip
177
178 # Add the CHIP libraries as prerequisites for linking the application.
179 STD_LINK_PREREQUISITES +=                   \
180     $(CHIP_OUTPUT_DIR)/lib/libDeviceLayer.a \
181     $(CHIP_OUTPUT_DIR)/lib/libCHIP.a        \
182     $(CHIP_OUTPUT_DIR)/lib/libInetLayer.a   \
183     $(CHIP_OUTPUT_DIR)/lib/libSystemLayer.a \
184     $(CHIP_OUTPUT_DIR)/lib/liblwip.a        \
185     $(CHIP_OUTPUT_DIR)/lib/libmbedtls.a
186
187 # ==================================================
188 # Late-bound build rules for CHIP
189 # ==================================================
190
191 # Add CHIPBuildRules to the list of late-bound build rules that
192 # will be evaluated when GenerateBuildRules is called.
193 LATE_BOUND_RULES += CHIPBuildRules
194
195 # Rules for configuring, building and installing CHIP.
196 define CHIPBuildRules
197
198 .PHONY : config-chip .check-config-chip build-chip install-chip clean-chip
199
200 .check-config-chip : | $(CHIP_OUTPUT_DIR)
201         $(NO_ECHO)echo $(CHIP_ROOT)/configure $(CHIP_CONFIGURE_OPTIONS) > $(CHIP_OUTPUT_DIR)/config.args.tmp; \
202         (test -r $(CHIP_OUTPUT_DIR)/config.args && cmp -s $(CHIP_OUTPUT_DIR)/config.args.tmp $(CHIP_OUTPUT_DIR)/config.args) || \
203             mv $(CHIP_OUTPUT_DIR)/config.args.tmp $(CHIP_OUTPUT_DIR)/config.args; \
204          rm -f $(CHIP_OUTPUT_DIR)/config.args.tmp;
205
206 $(CHIP_OUTPUT_DIR)/config.args : .check-config-chip
207         @: # Null action required to work around make's crazy timestamp caching behavior.
208
209 $(CHIP_ROOT)/configure : $(CHIP_ROOT)/configure.ac
210         @echo "$(HDR_PREFIX)BOOTSTRAP CHIP..."
211         $(NO_ECHO)(cd $(CHIP_ROOT) && ./bootstrap)
212
213 $(CHIP_OUTPUT_DIR)/config.status : $(CHIP_ROOT)/configure $(CHIP_OUTPUT_DIR)/config.args
214         @echo "$(HDR_PREFIX)CONFIGURE CHIP..."
215         $(NO_ECHO)(cd $(CHIP_OUTPUT_DIR) && $(CHIP_ROOT)/configure $(CHIP_CONFIGURE_OPTIONS))
216
217 config-chip : $(CHIP_OUTPUT_DIR)/config.status | $(OPENTHREAD_PREREQUISITE)
218
219 build-chip : config-chip
220         @echo "$(HDR_PREFIX)BUILD CHIP..."
221         $(NO_ECHO)MAKEFLAGS= make -C $(CHIP_OUTPUT_DIR) --no-print-directory all V=$(VERBOSE)
222
223 install-chip : | build-chip
224         @echo "$(HDR_PREFIX)INSTALL CHIP..."
225         $(NO_ECHO)MAKEFLAGS= make -C $(CHIP_OUTPUT_DIR) --no-print-directory install V=$(VERBOSE)
226
227 clean-chip:
228         @echo "$(HDR_PREFIX)RM $(CHIP_OUTPUT_DIR)"
229         $(NO_ECHO)rm -rf $(CHIP_OUTPUT_DIR)
230
231 $(CHIP_OUTPUT_DIR) :
232         @echo "$(HDR_PREFIX)MKDIR $$@"
233         $(NO_ECHO)mkdir -p "$$@"
234
235 endef
236 # ==================================================
237 # CHIP-specific help definitions
238 # ==================================================
239
240 define TargetHelp +=
241
242
243   config-chip          Run the CHIP configure script.
244
245   build-chip           Build the CHIP libraries.
246
247   install-chip         Install CHIP libraries and headers in
248                         build output directory for use by application.
249
250   clean-chip           Clean all build outputs produced by the CHIP
251                         build process.
252 endef