forked from project-chip/connectedhomeip
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile-Standalone
487 lines (391 loc) · 13.6 KB
/
Makefile-Standalone
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
#
# 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