1# 2# Copyright (c) 2016, The OpenThread Authors. 3# All rights reserved. 4# 5# Redistribution and use in source and binary forms, with or without 6# modification, are permitted provided that the following conditions are met: 7# 1. Redistributions of source code must retain the above copyright 8# notice, this list of conditions and the following disclaimer. 9# 2. Redistributions in binary form must reproduce the above copyright 10# notice, this list of conditions and the following disclaimer in the 11# documentation and/or other materials provided with the distribution. 12# 3. Neither the name of the copyright holder nor the 13# names of its contributors may be used to endorse or promote products 14# derived from this software without specific prior written permission. 15# 16# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 20# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26# POSSIBILITY OF SUCH DAMAGE. 27# 28 29# Don't allow this top-level makefile's targets to be built in parallel. 30 31.NOTPARALLEL: 32 33COVERAGE ?= 0 34DEBUG ?= 0 35 36# Enable most features by default to cover most code 37 38ANYCAST_LOCATOR ?= 1 39BORDER_AGENT ?= 1 40BORDER_ROUTER ?= 1 41COAP ?= 1 42COAP_BLOCK ?= 1 43COAP_OBSERVE ?= 1 44COAPS ?= 1 45COMMISSIONER ?= 1 46CHANNEL_MANAGER ?= 1 47CHANNEL_MONITOR ?= 1 48CHILD_SUPERVISION ?= 1 49DATASET_UPDATER ?= 1 50DHCP6_CLIENT ?= 1 51DHCP6_SERVER ?= 1 52DIAGNOSTIC ?= 1 53DNS_CLIENT ?= 1 54DNS_DSO ?= 1 55DNSSD_SERVER ?= 1 56ECDSA ?= 1 57HISTORY_TRACKER ?= 1 58IP6_FRAGM ?= 1 59JAM_DETECTION ?= 1 60JOINER ?= 1 61LEGACY ?= 1 62LINK_RAW ?= 1 63MAC_FILTER ?= 1 64MTD_NETDIAG ?= 1 65NEIGHBOR_DISCOVERY_AGENT ?= 1 66NETDATA_PUBLISHER ?= 1 67PING_SENDER ?= 1 68REFERENCE_DEVICE ?= 1 69SERVICE ?= 1 70SNTP_CLIENT ?= 1 71SRP_CLIENT ?= 1 72SRP_SERVER ?= 1 73UDP_FORWARD ?= 1 74 75COMMONCFLAGS := \ 76 -g \ 77 $(NULL) 78 79# If the user has asserted COVERAGE, alter the configuration options 80# accordingly. 81 82configure_OPTIONS = \ 83 --enable-cli \ 84 --enable-ftd \ 85 --enable-mtd \ 86 --enable-ncp \ 87 --enable-radio-only \ 88 --with-examples=simulation \ 89 $(NULL) 90 91# Platform specific switches 92 93ifneq ($(DEBUG),1) 94COMMONCFLAGS += \ 95 -O2 \ 96 $(NULL) 97endif 98 99ifeq ($(NCP_SPI),1) 100COMMONCFLAGS += -DOPENTHREAD_CONFIG_NCP_SPI_ENABLE=1 101else 102COMMONCFLAGS += -DOPENTHREAD_CONFIG_NCP_HDLC_ENABLE=1 103endif # NCP_SPI == 1 104 105ifeq ($(OTNS),1) 106VIRTUAL_TIME ?= 1 107endif 108 109ifeq ($(VIRTUAL_TIME),1) 110COMMONCFLAGS += -DOPENTHREAD_SIMULATION_VIRTUAL_TIME=1 111endif 112 113ifeq ($(VIRTUAL_TIME_UART),1) 114COMMONCFLAGS += -DOPENTHREAD_SIMULATION_VIRTUAL_TIME_UART=1 115endif 116 117ifneq ($(MAX_NETWORK_SIZE),) 118COMMONCFLAGS += -DOPENTHREAD_SIMULATION_MAX_NETWORK_SIZE=$(MAX_NETWORK_SIZE) 119endif 120 121include $(dir $(abspath $(lastword $(MAKEFILE_LIST))))/common-switches.mk 122 123TopSourceDir := $(dir $(shell readlink $(firstword $(MAKEFILE_LIST)))).. 124AbsTopSourceDir := $(dir $(realpath $(firstword $(MAKEFILE_LIST)))).. 125 126CONFIG_FILE = OPENTHREAD_PROJECT_CORE_CONFIG_FILE='\"openthread-core-simulation-config.h\"' 127CONFIG_FILE_PATH = $(AbsTopSourceDir)/examples/platforms/simulation/ 128COMMONCFLAGS += \ 129 -D$(CONFIG_FILE) \ 130 -I$(CONFIG_FILE_PATH) \ 131 132CPPFLAGS += \ 133 $(COMMONCFLAGS) \ 134 $(NULL) 135 136CFLAGS += \ 137 $(COMMONCFLAGS) \ 138 $(NULL) 139 140CXXFLAGS += \ 141 $(COMMONCFLAGS) \ 142 $(NULL) 143 144LDFLAGS += \ 145 $(COMMONCFLAGS) \ 146 $(NULL) 147 148ECHO := @echo 149INSTALL := /usr/bin/install 150INSTALLFLAGS := -p 151LN_S := ln -s 152MAKE := make 153MKDIR_P := mkdir -p 154RM_F := rm -f 155 156BuildJobs ?= 10 157BuildPath = build 158TopBuildDir = $(BuildPath) 159AbsTopBuildDir = $(PWD)/$(TopBuildDir) 160 161ResultPath = output 162TopResultDir = $(ResultPath) 163AbsTopResultDir = $(PWD)/$(TopResultDir) 164 165TargetTuple = simulation 166 167ifndef BuildJobs 168BuildJobs := $(shell getconf _NPROCESSORS_ONLN) 169endif 170JOBSFLAG := -j$(BuildJobs) 171 172# 173# configure-arch <target> 174# 175# Configure OpenThread for the specified target. 176# 177# target - The target to configure. 178# 179define configure-target 180$(ECHO) " CONFIG $(1)..." 181(cd $(BuildPath)/$(1) && $(AbsTopSourceDir)/configure \ 182INSTALL="$(INSTALL) $(INSTALLFLAGS)" \ 183CPPFLAGS="$(CPPFLAGS)" CFLAGS="$(CFLAGS)" CXXFLAGS="$(CXXFLAGS)" LDFLAGS="$(LDFLAGS)" \ 184--prefix=/ \ 185--exec-prefix=/$(1) \ 186$(configure_OPTIONS)) 187endef # configure-target 188 189# 190# build-target <target> 191# 192# Build the OpenThread intermediate build products for the specified 193# target. 194# 195# target - The target to build. 196# 197define build-target 198$(ECHO) " BUILD $(1)" 199$(MAKE) $(JOBSFLAG) -C $(BuildPath)/$(1) --no-print-directory \ 200all 201endef # build-target 202 203# 204# check-target <target> 205# 206# Check (run unit tests) OpenThread for the specified target. 207# 208# target - The target to check. 209# 210define check-target 211$(ECHO) " CHECK $(1)" 212$(MAKE) $(JOBSFLAG) -C $(BuildPath)/$(1) --no-print-directory \ 213check 214endef # check-target 215 216# 217# distcheck-target <target> 218# 219# Check (run unit tests) OpenThread for the specified target. 220# 221# target - The target to distcheck. 222# 223define distcheck-target 224$(ECHO) " DISTCHECK $(1)" 225$(MAKE) $(JOBSFLAG) -C $(BuildPath)/$(1) --no-print-directory \ 226distcheck 227endef # distcheck-target 228 229# 230# coverage-target <target> 231# 232# Generate code coverage from unit tests for OpenThread for the 233# specified target. 234# 235# target - The target to generate code coverage for. 236# 237define coverage-target 238$(ECHO) " COVERAGE $(1)" 239$(MAKE) $(JOBSFLAG) -C $(BuildPath)/$(1) --no-print-directory \ 240coverage 241endef # coverage-target 242 243# 244# stage-target <target> 245# 246# Stage (install) the OpenThread final build products for the specified 247# target. 248# 249# target - The target to stage. 250# 251define stage-target 252$(ECHO) " STAGE $(1)" 253$(MAKE) $(JOBSFLAG) -C $(BuildPath)/$(1) --no-print-directory \ 254DESTDIR=$(AbsTopResultDir) \ 255install 256endef # stage-target 257 258# 259# TARGET_template <target> 260# 261# Define macros, targets and rules to configure, build, and stage 262# OpenThread for a single target. 263# 264# target - The target to instantiate the template for. 265# 266define TARGET_template 267CONFIGURE_TARGETS += configure-$(1) 268BUILD_TARGETS += do-build-$(1) 269CHECK_TARGETS += check-$(1) 270DISTCHECK_TARGETS += distcheck-$(1) 271COVERAGE_TARGETS += coverage-$(1) 272STAGE_TARGETS += stage-$(1) 273BUILD_DIRS += $(BuildPath)/$(1) 274DIRECTORIES += $(BuildPath)/$(1) 275 276configure-$(1): $(BuildPath)/$(1)/config.status 277 278$(BuildPath)/$(1)/config.status: | $(BuildPath)/$(1) 279 $$(call configure-target,$(1)) 280 281do-build-$(1): configure-$(1) 282 283do-build-$(1): 284 +$$(call build-target,$(1)) 285 286check-$(1): do-build-$(1) 287 288check-$(1): 289 +$$(call check-target,$(1)) 290 291distcheck-$(1): do-build-$(1) 292 293distcheck-$(1): 294 +$$(call distcheck-target,$(1)) 295 296coverage-$(1): do-build-$(1) 297 298coverage-$(1): 299 +$$(call coverage-target,$(1)) 300 301stage-$(1): do-build-$(1) 302 303stage-$(1): | $(TopResultDir) 304 $$(call stage-target,$(1)) 305 306$(1): stage-$(1) 307endef # TARGET_template 308 309.DEFAULT_GOAL := all 310 311all: stage 312 313# Instantiate an target-specific build template for the target. 314 315$(eval $(call TARGET_template,$(TargetTuple))) 316 317# 318# Common / Finalization 319# 320 321configure: $(CONFIGURE_TARGETS) 322 323build: $(BUILD_TARGETS) 324 325check: $(CHECK_TARGETS) 326 327distcheck: $(DISTCHECK_TARGETS) 328 329coverage: $(COVERAGE_TARGETS) 330 331stage: $(STAGE_TARGETS) 332 333DIRECTORIES = $(TopResultDir) $(TopResultDir)/$(TargetTuple)/lib $(BUILD_DIRS) 334 335CLEAN_DIRS = $(TopResultDir) $(BUILD_DIRS) 336 337all: stage 338 339$(DIRECTORIES): 340 $(ECHO) " MKDIR $@" 341 @$(MKDIR_P) "$@" 342 343clean: 344 $(ECHO) " CLEAN" 345 @$(RM_F) -r $(CLEAN_DIRS) 346 347help: 348 $(ECHO) "Simply type 'make -f $(firstword $(MAKEFILE_LIST))' to build OpenThread for the following " 349 $(ECHO) "target:" 350 $(ECHO) "" 351 $(ECHO) " $(TargetTuple)" 352 $(ECHO) "" 353