2 # Copyright (c) 2020 Project CHIP Authors
3 # Copyright (c) 2018 Nest Labs, Inc.
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
10 # http://www.apache.org/licenses/LICENSE-2.0
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.
19 # Component makefile for building CHIP within the ESP32 ESP-IDF environment.
22 # ==================================================
24 # ==================================================
28 # CHIP source root directory
29 CHIP_ROOT ?= $(realpath $(COMPONENT_PATH)/../../../..)
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))
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))
37 COMPONENT_LIBRARIES :=
40 # ==================================================
41 # Compilation flags specific to building CHIP
42 # ==================================================
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
48 INCLUDES := $(OUTPUT_DIR)/src/include \
49 $(OUTPUT_DIR)/src/include/platform/ESP32 \
50 $(filter-out $(IDF_PATH)/%, $(COMPONENT_INCLUDES))
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))
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)
65 # ==================================================
66 # Configuration for the CHIP ESF-IDF Component
67 # ==================================================
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
82 # Linker flags to be included when building other components that use CHIP.
83 COMPONENT_ADD_LDFLAGS = -L$(OUTPUT_DIR)/lib/ \
86 ifdef CONFIG_ENABLE_PW_RPC
87 COMPONENT_ADD_LDFLAGS += -lPwRpc
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
95 # Tell the ESP-IDF build system that the CHIP component defines its own build
97 COMPONENT_OWNBUILDTARGET = 1
98 COMPONENT_OWNCLEANTARGET = 1
101 # ==================================================
103 # ==================================================
110 fix_cflags = $(filter-out -DHAVE_CONFIG_H,\
112 $(filter-out IDF_VER%,\
113 $(1) -D$(filter IDF_VER%,$(1))\
115 CHIP_CFLAGS = $(call fix_cflags,$(CFLAGS) $(CPPFLAGS))
116 CHIP_CXXFLAGS = $(call fix_cflags,$(CXXFLAGS) $(CPPFLAGS))
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
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 ;\
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
144 echo "CHIP built and installed..."
145 cp -a ${OUTPUT_DIR}/lib/libCHIP.a ${OUTPUT_DIR}/libchip.a
148 echo "RM $(OUTPUT_DIR)"