Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / config / esp32 / components / chip / component.mk
1 #
2 #    Copyright (c) 2020 Project CHIP Authors
3 #    Copyright (c) 2018 Nest Labs, Inc.
4 #    All rights reserved.
5 #
6 #    Licensed under the Apache License, Version 2.0 (the "License");
7 #    you may not use this file except in compliance with the License.
8 #    You may obtain a copy of the License at
9 #
10 #        http://www.apache.org/licenses/LICENSE-2.0
11 #
12 #    Unless required by applicable law or agreed to in writing, software
13 #    distributed under the License is distributed on an "AS IS" BASIS,
14 #    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 #    See the License for the specific language governing permissions and
16 #    limitations under the License.
17 #
18 #    Description:
19 #      Component makefile for building CHIP within the ESP32 ESP-IDF environment.
20 #
21
22 # ==================================================
23 # General settings
24 # ==================================================
25
26 SHELL = /bin/bash
27
28 # CHIP source root directory
29 CHIP_ROOT              ?= $(realpath $(COMPONENT_PATH)/../../../..)
30
31 # Directory into which the CHIP build system will place its output.
32 OUTPUT_DIR                                      := $(BUILD_DIR_BASE)/chip
33 REL_OUTPUT_DIR              := $(shell perl -e 'use File::Spec; use Cwd; print File::Spec->abs2rel(Cwd::realpath($$ARGV[0]), Cwd::realpath($$ARGV[1])) . "\n"' $(OUTPUT_DIR) $(COMPONENT_PATH))
34
35 REL_CHIP_ROOT               := $(shell perl -e 'use File::Spec; use Cwd; print File::Spec->abs2rel(Cwd::realpath($$ARGV[0]), Cwd::realpath($$ARGV[1])) . "\n"' $(CHIP_ROOT) $(COMPONENT_PATH))
36
37 COMPONENT_LIBRARIES         :=
38
39
40 # ==================================================
41 # Compilation flags specific to building CHIP
42 # ==================================================
43
44 # Include directories to be searched when building CHIP.  Make sure
45 # that anything starting with $(IDF_PATH) ends up being included with
46 # -isystem, not -I, so warnings in those headers don't cause the build
47 # to fail.
48 INCLUDES                    := $(OUTPUT_DIR)/src/include \
49                                $(OUTPUT_DIR)/src/include/platform/ESP32 \
50                                $(filter-out $(IDF_PATH)/%, $(COMPONENT_INCLUDES))
51
52 SYSTEM_INCLUDES             := $(IDF_PATH)/components/lwip/lwip/src/include \
53                                $(IDF_PATH)/components/freertos/include/freertos/ \
54                                $(IDF_PATH)/components/mbedtls/mbedtls/include \
55                                $(filter $(IDF_PATH)/%, $(COMPONENT_INCLUDES))
56
57
58 # Compiler flags for building CHIP
59 ALL_INCLUDES                := $(addprefix -I,$(INCLUDES)) $(addprefix -isystem,$(SYSTEM_INCLUDES))
60 CFLAGS                      += $(ALL_INCLUDES)
61 CPPFLAGS                    += $(ALL_INCLUDES)
62 CXXFLAGS                    += $(ALL_INCLUDES)
63
64
65 # ==================================================
66 # Configuration for the CHIP ESF-IDF Component
67 # ==================================================
68
69 # Header directories to be included when building other components that use CHIP.
70 # Note that these must be relative to the component source directory.
71 # TODO Boot the CHIP_ROOT includedirs
72 COMPONENT_ADD_INCLUDEDIRS        = project-config \
73                                $(REL_OUTPUT_DIR)/include \
74                                $(REL_CHIP_ROOT)/src/include/platform/ESP32 \
75                                $(REL_CHIP_ROOT)/src/include/ \
76                                $(REL_CHIP_ROOT)/src/lib \
77                                $(REL_CHIP_ROOT)/src/ \
78                                $(REL_CHIP_ROOT)/src/system \
79                                $(IDF_PATH)/components/mbedtls/mbedtls/include \
80                                $(REL_CHIP_ROOT)/src/app
81
82 # Linker flags to be included when building other components that use CHIP.
83 COMPONENT_ADD_LDFLAGS        = -L$(OUTPUT_DIR)/lib/ \
84                                -lCHIP
85
86 ifdef CONFIG_ENABLE_PW_RPC
87 COMPONENT_ADD_LDFLAGS        += -lPwRpc
88 endif
89
90 COMPONENT_ADD_INCLUDEDIRS +=   $(REL_OUTPUT_DIR)/src/include \
91                                $(REL_CHIP_ROOT)/third_party/nlassert/repo/include \
92                                $(REL_OUTPUT_DIR)/gen/third_party/connectedhomeip/src/app/include \
93                                $(REL_OUTPUT_DIR)/gen/include
94
95 # Tell the ESP-IDF build system that the CHIP component defines its own build
96 # and clean targets.
97 COMPONENT_OWNBUILDTARGET         = 1
98 COMPONENT_OWNCLEANTARGET         = 1
99
100
101 # ==================================================
102 # Build Rules
103 # ==================================================
104
105 $(OUTPUT_DIR) :
106         echo "MKDIR $@"
107         @mkdir -p "$@"
108
109
110 fix_cflags = $(filter-out -DHAVE_CONFIG_H,\
111                 $(filter-out -D,\
112                   $(filter-out IDF_VER%,\
113                       $(1) -D$(filter IDF_VER%,$(1))\
114                )))
115 CHIP_CFLAGS = $(call fix_cflags,$(CFLAGS) $(CPPFLAGS))
116 CHIP_CXXFLAGS = $(call fix_cflags,$(CXXFLAGS) $(CPPFLAGS))
117
118 install-chip : $(OUTPUT_DIR)
119         echo "INSTALL CHIP..."
120         echo                                   > $(OUTPUT_DIR)/args.gn
121         echo "import(\"//args.gni\")"          >> $(OUTPUT_DIR)/args.gn
122         echo target_cflags_c  = [$(foreach word,$(CHIP_CFLAGS),\"$(word)\",)] | sed -e 's/=\"/=\\"/g;s/\"\"/\\"\"/g;'  >> $(OUTPUT_DIR)/args.gn
123         echo target_cflags_cc = [$(foreach word,$(CHIP_CXXFLAGS),\"$(word)\",)] | sed -e 's/=\"/=\\"/g;s/\"\"/\\"\"/g;'   >> $(OUTPUT_DIR)/args.gn
124         echo esp32_ar = \"$(AR)\"                >> $(OUTPUT_DIR)/args.gn
125         echo esp32_cc = \"$(CC)\"                >> $(OUTPUT_DIR)/args.gn
126         echo esp32_cxx = \"$(CXX)\"              >> $(OUTPUT_DIR)/args.gn
127         echo esp32_cpu = \"esp32\"               >> $(OUTPUT_DIR)/args.gn
128 ifeq ($(is_debug),false)
129         @echo "is_debug = false" >> $(OUTPUT_DIR)/args.gn
130 endif
131         if [[ "$(CONFIG_ENABLE_PW_RPC)" = "y" ]]; then                        \
132           echo "chip_build_pw_rpc_lib = true" >> $(OUTPUT_DIR)/args.gn       ;\
133           echo "pw_log_BACKEND = \"//third_party/connectedhomeip/third_party/pigweed/repo/pw_log_basic\"" >> $(OUTPUT_DIR)/args.gn     ;\
134           echo "pw_assert_BACKEND = \"//third_party/connectedhomeip/third_party/pigweed/repo/pw_assert_log\"" >> $(OUTPUT_DIR)/args.gn ;\
135           echo "pw_sys_io_BACKEND = \"//third_party/connectedhomeip/examples/platform/esp32/pw_sys_io:pw_sys_io_esp32\"" >> $(OUTPUT_DIR)/args.gn      ;\
136           echo "dir_pw_third_party_nanopb = \"//third_party/connectedhomeip/third_party/nanopb/repo\"" >>$(OUTPUT_DIR)/args.gn         ;\
137         fi
138         echo "Written file $(OUTPUT_DIR)/args.gn"
139         cd $(CHIP_ROOT) && PW_ENVSETUP_QUIET=1 . scripts/activate.sh && cd $(COMPONENT_PATH) && gn gen --check --fail-on-unused-args $(OUTPUT_DIR)
140         cd $(COMPONENT_PATH); ninja $(subst 1,-v,$(filter 1,$(V))) -C $(OUTPUT_DIR) esp32
141
142
143 build : install-chip
144         echo "CHIP built and installed..."
145         cp -a ${OUTPUT_DIR}/lib/libCHIP.a ${OUTPUT_DIR}/libchip.a
146
147 clean:
148         echo "RM $(OUTPUT_DIR)"
149         rm -rf $(OUTPUT_DIR)