blob: 158cb95f7b94d5e28f5ba0dbd24e4510fa2723c3 [file] [log] [blame]
#
# Copyright (c) 2020 Project CHIP Authors
# Copyright (c) 2014-2017 Nest Labs, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Description:
# This file implements a glue makefile for building the CHIP SDK
# for standalone desktop or server build host systems.
#
# This is strictly a convenience makefile. Such systems can
# otherwise be built using the usual GNU autotools convention of:
#
# % ./configure
# % make
#
# Don't allow this top-level makefile's targets to be built in parallel.
.NOTPARALLEL:
COVERAGE ?= 0
DEBUG ?= 0
TIMESTAMP ?= 0
TUNNEL_FAILOVER ?= 0
USE_LWIP ?= 0
USE_NW ?= 0
NO_OPENSSL ?= 0
BLUEZ ?= 0
USE_FUZZING ?= 0
TESTS ?= 1
HOSTOS = $(shell uname -s |tr [:upper:] [:lower:])
ARCH = $(shell uname -m |tr [:upper:] [:lower:])
ECHO := @echo
MAKE := make
MKDIR_P := mkdir -p
LN_S := ln -s
RM_F := rm -f
INSTALL := /usr/bin/install
INSTALLFLAGS := -p
TopSourceDir := $(dir $(shell readlink $(firstword $(MAKEFILE_LIST))))
AbsTopSourceDir := $(dir $(realpath $(firstword $(MAKEFILE_LIST))))
BuildPath = build
TopBuildDir = $(BuildPath)
AbsTopBuildDir = $(CURDIR)/$(TopBuildDir)
ResultPath = output
TopResultDir = $(ResultPath)
AbsTopResultDir = $(CURDIR)/$(TopResultDir)
TargetTuple = $(shell ${AbsTopSourceDir}/third_party/nlbuild-autotools/repo/third_party/autoconf/config.guess | sed -e 's/[[:digit:].]*$$//g')
ProjectConfigDir ?= $(AbsTopSourceDir)/config/standalone
ifeq ($(ARCH),x86_64)
configure_OPTIONS = CPPFLAGS="-maes"
endif
# NOTE: Mac OS SDKs generated on OS X Sierra (or higher) seem to have trouble
# running on El Capitan (or earlier) due to issues with clock_gettime:
# declaring the interface in time.h but not making the symbol
# available in libSystem.dylib, resulting in a runtime crash. For
# now, suppress use of clock_getttime on OS X by overriding
# configure and asserting:
#
# ac_cv_func_clock_gettime=no
# ac_cv_have_decl_clock_gettime=no
#
# below.
#
ifeq ($(HOSTOS),darwin)
configure_OPTIONS += ac_cv_func_clock_gettime=no ac_cv_have_decl_clock_gettime=no
endif
# If the user has asserted USE_FUZZING enable fuzzing build
ifeq ($(USE_FUZZING),1)
configure_OPTIONS += --enable-fuzzing
endif
# If the user has asserted COVERAGE, alter the configuration options
# accordingly.
ifeq ($(COVERAGE),1)
# no point in enabling docs generation for a coverage build
configure_OPTIONS += --enable-coverage --enable-coverage-reports --disable-docs
# Happy checks are time consuming, but on average less processor intensive than
# compiling and running unit-tests.
# Bump the number of builds, it primarily has an effect on the make check
# phase of the build.
BuildJobs ?= $(shell echo $$(( `getconf _NPROCESSORS_ONLN` * 2 )) )
endif
# On properly configured 64-bit Linux machines, recognize the
# I686TARGET flag and build the 32-bit image.
ifeq ($(HOSTOS),linux)
ifeq ($(ARCH),x86_64)
ifeq ($(I686TARGET),1)
TargetTuple = i686-pc-linux-gnu
configure_OPTIONS += --build=$(TargetTuple) CFLAGS="-m32 -g -O2" CXXFLAGS="-m32 -g -O2" LDFLAGS="-m32 -L/usr/lib/i386-linux-gnu/"
endif
endif
endif
# If the user has asserted DEBUG, alter the configuration options
# accordingly.
ifeq ($(DEBUG),1)
configure_OPTIONS += --enable-debug --enable-optimization=no
else
configure_OPTIONS +=
endif
# Disable docs generation
ifeq ($(DOCS),0)
configure_OPTIONS += --disable-docs
else
configure_OPTIONS +=
endif
# If the user has asserted TIMESTAMP, alter the configuration options
# accordingly.
ifeq ($(TIMESTAMP),1)
configure_OPTIONS += --enable-stdio-logging-timestamps
else
configure_OPTIONS +=
endif
# If the user has used tunnel failover, alter the configuration options
# accordingly.
ifeq ($(TUNNEL_FAILOVER),1)
configure_OPTIONS += --enable-tunnel-failover
else
configure_OPTIONS +=
endif
# If the user has chipoble over bluez peripheral, alter the configuration options
# accordingly.
ifeq ($(BLUEZ),1)
configure_OPTIONS += --enable-experimental --enable-deprecated --enable-testing --enable-tools --disable-systemd --enable-debug
else
configure_OPTIONS += --with-bluez=no
endif
# Disable tests generation
ifeq ($(TESTS),0)
configure_OPTIONS += --disable-tests
else
configure_OPTIONS +=
endif
# Allow openssl installation selection
ifneq ($(OPENSSL),)
configure_OPTIONS += --with-openssl=$(OPENSSL)
endif
# If the user has asserted USE_LWIP, alter the configuration and
# target tuple to use LwIP rather than the expected BSD sockets.
ifeq ($(USE_LWIP),1)
configure_OPTIONS += --with-target-network=lwip --with-lwip=internal --disable-java
TargetTuple := $(TargetTuple)-lwip
endif
ifeq ($(USE_NW),1)
configure_OPTIONS += --with-target-network=Network.framework
TargetTuple := $(TargetTuple)-nw
endif
ifeq ($(LONG_TESTS),1)
configure_OPTIONS += --enable-long-tests=yes
endif
ifeq ($(ENABLE_CHIPOBLE_TEST),1)
configure_OPTIONS += --enable-chipoble-test=yes
endif
ifndef BuildJobs
BuildJobs := $(shell getconf _NPROCESSORS_ONLN)
endif
JOBSFLAG := -j$(BuildJobs)
#
# automake files
#
AMFILES = \
src/system/Makefile.am \
src/lib/Makefile.am \
src/inet/Makefile.am \
src/ble/Makefile.am \
src/lwip/Makefile.am \
src/Makefile.am \
third_party/Makefile.am \
Makefile.am \
configure.ac \
$(NULL)
#
# configure-arch <target>
#
# Configure the CHIP SDK for the specified target.
#
# target - The target to configure.
#
define configure-target
$(ECHO) " CONFIG $(1)..."
(cd $(BuildPath)/$(1) && $(AbsTopSourceDir)/configure -C \
INSTALL="$(INSTALL) $(INSTALLFLAGS)" \
--prefix=/ \
--exec-prefix=/$(1) \
--with-chip-project-includes=$(ProjectConfigDir) \
$(configure_OPTIONS))
endef # configure-target
#
# build-target <target>
#
# Build the CHIP SDK intermediate build products for the specified
# target.
#
# target - The target to build.
#
define build-target
$(ECHO) " BUILD $(1)"
$(MAKE) $(JOBSFLAG) -C $(BuildPath)/$(1) --no-print-directory \
all
endef # build-target
#
# check-target <target>
#
# Check (run unit tests) the CHIP SDK for the specified target.
#
# target - The target to check.
#
define check-target
$(ECHO) " CHECK $(1)"
$(MAKE) $(JOBSFLAG) -C $(BuildPath)/$(1) --no-print-directory \
check
endef # check-target
#
# distcheck-target <target>
#
# Check (run unit tests) OpenThread for the specified target.
#
# target - The target to distcheck.
#
define distcheck-target
$(ECHO) " DISTCHECK $(1)"
$(MAKE) $(JOBSFLAG) -C $(BuildPath)/$(1) --no-print-directory \
distcheck
endef # distcheck-target
#
# coverage-target <target>
#
# Generate code coverage from unit tests for the CHIP SDK for the
# specified target.
#
# target - The target to generate code coverage for.
#
define coverage-target
$(ECHO) " COVERAGE $(1)"
$(MAKE) $(JOBSFLAG) -C $(BuildPath)/$(1) --no-print-directory \
coverage
endef # coverage-target
#
# stage-target <target>
#
# Stage (install) the CHIP SDK final build products for the specified
# target.
#
# target - The target to stage.
#
define stage-target
$(ECHO) " STAGE $(1)"
$(MAKE) $(JOBSFLAG) -C $(BuildPath)/$(1) --no-print-directory \
DESTDIR=$(AbsTopResultDir) \
install
endef # stage-target
#
# pretty-target <target>
#
# Prettyify the CHIP SDK source code for the specified target.
#
# target - The target to prettify.
#
define pretty-target
$(ECHO) " PRETTY $(1)"
$(MAKE) $(JOBSFLAG) -C $(BuildPath)/$(1) --no-print-directory \
pretty
endef # pretty-target
#
# pretty-check-target <target>
#
# Pretty-check (lint) the CHIP SDK source code for the specified
# target.
#
# target - The target to pretty-check (lint).
#
define pretty-check-target
$(ECHO) " PRETTY $(1)"
$(MAKE) $(JOBSFLAG) -C $(BuildPath)/$(1) --no-print-directory \
pretty-check
endef # pretty-check-target
#
# TARGET_template <target>
#
# Define macros, targets and rules to configure, build, and stage the
# CHIP SDK for a single target.
#
# target - The target to instantiate the template for.
#
define TARGET_template
CONFIGURE_TARGETS += configure-$(1)
BUILD_TARGETS += do-build-$(1)
CHECK_TARGETS += check-$(1)
DISTCHECK_TARGETS += distcheck-$(1)
COVERAGE_TARGETS += coverage-$(1)
STAGE_TARGETS += stage-$(1)
PRETTY_TARGETS += pretty-$(1)
PRETTY_CHECK_TARGETS += pretty-check-$(1)
BUILD_DIRS += $(BuildPath)/$(1)
DIRECTORIES += $(BuildPath)/$(1)
configure-$(1): Makefile.in $(BuildPath)/$(1)/config.status
$(BuildPath)/$(1)/config.status: | $(BuildPath)/$(1)
$$(call configure-target,$(1))
do-build-$(1): configure-$(1)
do-build-$(1):
$$(call build-target,$(1))
check-$(1): do-build-$(1)
check-$(1):
$$(call check-target,$(1))
distcheck-$(1): do-build-$(1)
distcheck-$(1):
$$(call distcheck-target,$(1))
coverage-$(1): do-build-$(1)
coverage-$(1):
$$(call coverage-target,$(1))
stage-$(1): do-build-$(1)
stage-$(1): | $(TopResultDir)
$$(call stage-target,$(1))
pretty-$(1): configure-$(1)
$$(call pretty-target,$(1))
lint-$(1) pretty-check-$(1): configure-$(1)
$$(call pretty-check-target,$(1))
$(1): stage-$(1)
endef # TARGET_template
.PHONY : configure build check coverage stage pretty lint pretty-check clean ensure-sudo help
ensure-sudo:
$(ECHO) "Selected target will require sudo access."
@sudo echo "Sudo access granted"
.DEFAULT_GOAL := all
all: stage
# Instantiate an target-specific build template for the target.
$(eval $(call TARGET_template,$(TargetTuple)))
#
# Common / Finalization
#
Makefile.in: $(AMFILES)
$(ECHO) "BOOTSTRAP"
@./bootstrap
configure: $(CONFIGURE_TARGETS)
build: $(BUILD_TARGETS)
check: ensure-sudo $(CHECK_TARGETS)
distcheck: ensure-sudo $(DISTCHECK_TARGETS)
coverage: ensure-sudo $(COVERAGE_TARGETS)
stage: $(STAGE_TARGETS)
pretty: $(PRETTY_TARGETS)
lint pretty-check: $(PRETTY_CHECK_TARGETS)
DIRECTORIES = $(TopResultDir) $(TopResultDir)/$(TargetTuple)/lib $(BUILD_DIRS)
CLEAN_DIRS = $(TopResultDir) $(BUILD_DIRS)
all: stage
$(DIRECTORIES):
$(ECHO) " MKDIR $@"
@$(MKDIR_P) "$@"
clean:
$(ECHO) " CLEAN"
@$(RM_F) -r $(CLEAN_DIRS)
help:
@echo "$${HelpText}"
export HelpText
define HelpText
Simply type 'make -f $(firstword $(MAKEFILE_LIST))' to build CHIP for the following
target:
$(TargetTuple)
You may want or need to override the following make variables either on the
command line or in the environment:
DEBUG=[1|0] Enable/disable CHIP debug code and logging (default: '$(DEBUG)').
COVERAGE=[1|0] Enable/disable generation of code coverage information
(default: '$(COVERAGE)').
TIMESTAMP=[1|0] Enable/disable logging module timestamp output (default: '$(TIMESTAMP)').
USE_LWIP=[1|0] Build the standalone configuration against the LwIP
library rather than against sockets (default '$(USE_LWIP)').
BLUEZ=[1|0] Enable support for BLE peripheral using BlueZ bindings
OPENSSL=<dir> Use the prebuilt version of OpenSSL located in the given
directory. Note that the directory is expected to contain
include and lib subdirectories containing the necessary header
and libraries.
TUNNEL_FAILOVER=[1|0] Enable/disabled support for redundant VPN to the CHIP service
(default: '$(TUNNEL_FAILOVER)').
I686TARGET=[1|0] Enable/disable building a 32-bit target. Requires a properly
configured 64-bit Linux with multilib support (default: '$(I686TARGET)').
DOCS=[1|0] Enable/disable Doxygen-generated documentation (default: '$(DOCS)').
Note this flag only has an effect when Doxygen is
installed.
HAPPY=[1|0] When set to 0, skip the functional tests that require
Happy orchestration tool. When set to 1, pick the
default location to the Happy tool. When set to any
other value, the value is treated as the location of
the Happy tool.
TESTS=[1|0] Enable/disable tests (default: '$(TESTS)').
endef