|
| 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 | +# CHIP source root directory |
| 27 | +CHIP_ROOT ?= $(realpath $(COMPONENT_PATH)/../../../..) |
| 28 | + |
| 29 | +# Archtecture for which CHIP will be built. |
| 30 | +HOST_ARCH := xtensa-unknown-linux-gnu |
| 31 | + |
| 32 | +# Directory into which the CHIP build system will place its output. |
| 33 | +OUTPUT_DIR := $(BUILD_DIR_BASE)/chip |
| 34 | +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 | + |
| 36 | +# Directory containing esp32-specific CHIP project configuration files. |
| 37 | +PROJECT_CONFIG_DIR := $(CHIP_ROOT)/build/config/esp32 |
| 38 | + |
| 39 | +# Architcture on which CHIP is being built. |
| 40 | +BUILD_ARCH := $(shell $(CHIP_ROOT)/third_party/nlbuild-autotools/repo/third_party/autoconf/config.guess | sed -e 's/[[:digit:].]*$$//g') |
| 41 | + |
| 42 | +# Directory containing the esp32-specific LwIP component sources. |
| 43 | +LWIP_COMPONENT_DIR ?= $(PROJECT_PATH)/components/lwip |
| 44 | + |
| 45 | + |
| 46 | +# ================================================== |
| 47 | +# Compilation flags specific to building CHIP |
| 48 | +# ================================================== |
| 49 | + |
| 50 | +# Include directories to be searched when building CHIP. |
| 51 | +INCLUDES := $(OUTPUT_DIR)/src/include \ |
| 52 | + $(OUTPUT_DIR)/src/include/CHIP/DeviceLayer/ESP32 \ |
| 53 | + $(CHIP_ROOT)/src/adaptations/device-layer/trait-support \ |
| 54 | + $(COMPONENT_INCLUDES) |
| 55 | + |
| 56 | +# Compiler flags for building CHIP |
| 57 | +CFLAGS += $(addprefix -I,$(INCLUDES)) |
| 58 | +CPPFLAGS += $(addprefix -I,$(INCLUDES)) |
| 59 | +CXXFLAGS += $(addprefix -I,$(INCLUDES)) |
| 60 | + |
| 61 | +INSTALL := /usr/bin/install |
| 62 | +INSTALLFLAGS := -C -v |
| 63 | + |
| 64 | + |
| 65 | +# ================================================== |
| 66 | +# Utility Functions |
| 67 | +# ================================================== |
| 68 | + |
| 69 | +QuoteChar = " |
| 70 | + |
| 71 | +DoubleQuoteStr = $(QuoteChar)$(subst $(QuoteChar),\$(QuoteChar),$(subst \,\\,$(1)))$(QuoteChar) |
| 72 | + |
| 73 | + |
| 74 | +# ================================================== |
| 75 | +# CHIP configuration options |
| 76 | +# ================================================== |
| 77 | + |
| 78 | +# ESP-IDF's project.mk fails to define RANLIB appropriately, so we define it here. |
| 79 | +RANLIB := $(call dequote,$(CONFIG_TOOLPREFIX))ranlib |
| 80 | + |
| 81 | +CONFIGURE_OPTIONS := AR="$(AR)" CC="$(CC)" CXX="$(CXX)" LD="$(LD)" OBJCOPY="$(OBJCOPY)" RANLIB="$(RANLIB)" \ |
| 82 | + INSTALL="$(INSTALL) $(INSTALLFLAGS)" \ |
| 83 | + CFLAGS=$(call DoubleQuoteStr, $(CFLAGS)) \ |
| 84 | + CPPFLAGS=$(call DoubleQuoteStr, $(CPPFLAGS)) \ |
| 85 | + CXXFLAGS=$(call DoubleQuoteStr, $(CXXFLAGS)) \ |
| 86 | + --prefix=$(OUTPUT_DIR) \ |
| 87 | + --exec-prefix=$(OUTPUT_DIR) \ |
| 88 | + --host=$(HOST_ARCH) \ |
| 89 | + --build=$(BUILD_ARCH) \ |
| 90 | + --with-device-layer=esp32 \ |
| 91 | + --with-network-layer=all \ |
| 92 | + --with-target-network=lwip \ |
| 93 | + --with-lwip=$(LWIP_COMPONENT_DIR) \ |
| 94 | + --with-inet-endpoint="tcp udp tun dns" \ |
| 95 | + --with-openssl=no \ |
| 96 | + --with-logging-style=external \ |
| 97 | + --with-chip-project-includes= \ |
| 98 | + --with-chip-system-project-includes= \ |
| 99 | + --with-chip-inet-project-includes= \ |
| 100 | + --with-chip-ble-project-includes= \ |
| 101 | + --with-chip-warm-project-includes= \ |
| 102 | + --disable-tests \ |
| 103 | + --disable-tools \ |
| 104 | + --disable-docs \ |
| 105 | + --disable-java \ |
| 106 | + --disable-device-manager |
| 107 | + |
| 108 | +# Enable debug and disable optimization if ESP-IDF Optimization Level is set to Debug. |
| 109 | +ifeq ($(CONFIG_OPTIMIZATION_LEVEL_DEBUG),y) |
| 110 | +CONFIGURE_OPTIONS += --enable-debug --enable-optimization=no |
| 111 | +else |
| 112 | +CONFIGURE_OPTIONS += --enable-optimization=yes |
| 113 | +endif |
| 114 | + |
| 115 | + |
| 116 | +# ================================================== |
| 117 | +# Configuration for the CHIP ESF-IDF Component |
| 118 | +# ================================================== |
| 119 | + |
| 120 | +# Header directories to be included when building other components that use CHIP. |
| 121 | +# Note that these must be relative to the component source directory. |
| 122 | +COMPONENT_ADD_INCLUDEDIRS = project-config \ |
| 123 | + $(REL_OUTPUT_DIR)/include |
| 124 | + |
| 125 | +# Linker flags to be included when building other components that use CHIP. |
| 126 | +COMPONENT_ADD_LDFLAGS = -L$(OUTPUT_DIR)/lib \ |
| 127 | + -lCHIP \ |
| 128 | + -lInetLayer \ |
| 129 | + -lmincrypt \ |
| 130 | + -lnlfaultinjection \ |
| 131 | + -lSystemLayer \ |
| 132 | + -luECC \ |
| 133 | + -lWarm \ |
| 134 | + -lDeviceLayer |
| 135 | + |
| 136 | +# Tell the ESP-IDF build system that the CHIP component defines its own build |
| 137 | +# and clean targets. |
| 138 | +COMPONENT_OWNBUILDTARGET = 1 |
| 139 | +COMPONENT_OWNCLEANTARGET = 1 |
| 140 | + |
| 141 | + |
| 142 | +# ================================================== |
| 143 | +# Build Rules |
| 144 | +# ================================================== |
| 145 | + |
| 146 | +.PHONY : check-config-args-updated |
| 147 | +check-config-args-updated : | $(OUTPUT_DIR) |
| 148 | + echo $(CHIP_ROOT)/configure $(CONFIGURE_OPTIONS) > $(OUTPUT_DIR)/config.args.tmp; \ |
| 149 | + (test -r $(OUTPUT_DIR)/config.args && cmp -s $(OUTPUT_DIR)/config.args.tmp $(OUTPUT_DIR)/config.args) || \ |
| 150 | + mv $(OUTPUT_DIR)/config.args.tmp $(OUTPUT_DIR)/config.args; \ |
| 151 | + rm -f $(OUTPUT_DIR)/config.args.tmp; |
| 152 | + |
| 153 | +$(OUTPUT_DIR)/config.args : check-config-args-updated |
| 154 | + @: # Null action required to work around make's crazy timestamp caching behavior. |
| 155 | + |
| 156 | +$(CHIP_ROOT)/configure : $(CHIP_ROOT)/configure.ac |
| 157 | + echo "BOOTSTRAP CHIP..." |
| 158 | + (cd $(CHIP_ROOT) && ./bootstrap) |
| 159 | + |
| 160 | +$(OUTPUT_DIR)/config.status : $(CHIP_ROOT)/configure $(OUTPUT_DIR)/config.args |
| 161 | + echo "CONFIGURE CHIP..." |
| 162 | + (cd $(OUTPUT_DIR) && $(CHIP_ROOT)/configure $(CONFIGURE_OPTIONS)) |
| 163 | + |
| 164 | +configure-chip : $(OUTPUT_DIR)/config.status |
| 165 | + |
| 166 | +$(OUTPUT_DIR) : |
| 167 | + echo "MKDIR $@" |
| 168 | + @mkdir -p "$@" |
| 169 | + |
| 170 | +build-chip : configure-chip |
| 171 | + echo "BUILD CHIP..." |
| 172 | + MAKEFLAGS= make -C $(OUTPUT_DIR) --no-print-directory all |
| 173 | + |
| 174 | +install-chip : | build-chip |
| 175 | + echo "INSTALL CHIP..." |
| 176 | + MAKEFLAGS= make -C $(OUTPUT_DIR) --no-print-directory install |
| 177 | + |
| 178 | +build : build-chip install-chip |
| 179 | + |
| 180 | +clean: |
| 181 | + echo "RM $(OUTPUT_DIR)" |
| 182 | + rm -rf $(OUTPUT_DIR) |
0 commit comments