Repository navigation
Expand file tree
/
Copy pathmakefile
More file actions
738 lines (694 loc) · 40.2 KB
/
Copy pathmakefile
File metadata and controls
738 lines (694 loc) · 40.2 KB
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
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
#
# FILE makefile
#
# AUTHOR Ken Zangelin
#
# Copyright 2026 Seamware
# SPDX-License-Identifier: Apache-2.0
#
# Convenience wrapper around CMake.
#
PREFIX = /usr/local
BUILD_RELEASE = BUILD_RELEASE
BUILD_DEBUG = BUILD_DEBUG
BUILD_COVERAGE = BUILD_COVERAGE
#
# Functional-test coverage is measured PER CURRENT-STATE DB, because the two DB
# plugins take different paths through the broker and each leaves the other's
# plugin sources unexecuted. `make coverage` runs mongoc, `make coverage DB=corDB`
# runs corDB, and each writes its own report - comparing a corDB run against a
# mongoc one is comparing two different measurements.
#
COV_DB ?= $(if $(DB),$(DB),mongoc)
COV_DIR = coverage-$(COV_DB)
COV_REPORT = $(COV_DIR)/index.html
COV_STATUS = $(COV_DIR)/suite-status
COV_OTHER_DB = $(if $(filter mongoc,$(COV_DB)),corDB,mongoc)
COV_PLUGIN_DIR = $(BUILD_COVERAGE)/plugins
COV_ETSI_DIR = coverage-etsi
COV_LIBS = corRest corNgsild corJsonld
# The sibling repos live NEXT TO this one - the CMake references and every lib
# include path resolve as ../<name>, so the layout is part of the build
# contract. Derive the parent from this makefile's own location rather than
# assuming a fixed path: that is what lets a checkout anywhere, CI included,
# build itself. All three stay overridable.
SIBLING_DIR ?= $(abspath $(dir $(lastword $(MAKEFILE_LIST)))..)
CORTEST ?= $(SIBLING_DIR)/corLibs/bin/corTest
# gcovr lives in the ETSI test-suite venv (gcov-15-aware). Override if needed.
GCOVR ?= $(SIBLING_DIR)/ngsi-ld-test-suite/.venv/bin/gcovr
ifndef CPU_COUNT
CPU_COUNT := $(shell nproc)
endif
PLUGIN_DIR = /opt/seamware/plugins
ETC_DIR = /opt/seamware/etc
# contextSourceExtras (§ 5.2.40) — default opaque JSON config rendered on
# /info/sourceIdentity. Regenerated on every build with current version, git
# SHA and build timestamp; override at runtime via --contextSourceExtras.
# Read from the header the broker itself compiles in - two hand-maintained
# copies had already drifted (the binary said 0.3, this said 0.2.0, and the
# 0.2.0 is what /info/sourceIdentity was publishing).
CORAINE_VERSION = $(shell sed -n 's/^#define CORAINE_VERSION "\(.*\)"/\1/p' src/app/coraine/coraineVersion.h)
CORAINE_GIT_SHA = $(shell git rev-parse --short HEAD 2>/dev/null || echo unknown)
CORAINE_BUILD_AT = $(shell date -u +%Y-%m-%dT%H:%M:%SZ)
all: release
# Sibling-repo libs we link against. `make di` here recurses into each and
# runs their own `make di`, which is a no-op when nothing changed and a
# rebuild+install when something did. Without this, editing a lib's source
# leaves the broker linking against a stale .a (silent — link succeeds
# against last-installed copy).
#
# Dependency order, not alphabetical: corNgsild links -lcorRest and -lcorJsonld,
# so both have to exist before it is built. This used to work only because a
# previous build had left their artefacts behind - on a genuinely clean tree
# corNgsild failed to link.
#
# corDB is a plugin repo, not a lib the broker links: built here so its plugins (installed into
# $(PLUGIN_DIR)) are always the flavour of the broker beside them. It keeps each flavour's .so apart.
#
# EVERY library the broker links is here, the foundation ones too. Each builds per flavour
# (obj/debug, obj/release) and stages the one just built to its repo root, where the broker's
# CMakeLists links it - so `make release` links release archives throughout and `make di` puts the
# debug ones back. corBridge and corPlugin have no flavours (one build, no debug-only code).
# corHttp ($(HTTP_LIB)) when it is linked - the built-in server, a bridge's port - after corAlloc and corBase, which its test
# links, and before corRest, which links it.
#
FOUNDATION_LIBS = corBase corLog corAlloc corArgs corHash corTree corJson corProm
SIBLING_LIBS = $(FOUNDATION_LIBS) $(HTTP_LIB) corBridge corPlugin corRest corJsonld corNgsild $(CORDB_LIB)
#
# COR_HTTP_SERVER - mhd | builtin | both. Passed DOWN to the libs, not only to cmake.
#
# The HTTP server lives in corRest, which builds with plain make and knows
# nothing about the broker's cmake options - so setting it on the cmake side
# alone would produce a broker that links (or does not link) libmicrohttpd
# against a corRest compiled the other way. One variable, both builds, and
# corRest's own makefile rejects a value it does not recognise.
#
# corRest's $(OBJDIR)/.flags catches the change: switching this alters the
# compile line and nothing else, which no timestamp can see.
#
COR_HTTP_SERVER ?= mhd
#
# COR_WITH_ICU - 0 | 1. ICU root collation for orderBy on strings (§ 7.6.2.1).
#
# OFF by default: ON links libicu, which is three shared libraries and 39.2 MiB
# (libicudata alone is 31.6 MiB, nine times the whole broker) for one sort order.
#
# ONE variable for what are two flags underneath - corNgsild's COR_WITH_ICU
# selects the CODE PATH, coraine's cmake COR_FEATURE_ICU_COLLATION adds the ICU
# LIBS to the broker link - because setting one without the other is the failure
# this drives out: a lib compiled for the ASCII path inside a broker that links
# ICU, or a lib calling ucol_strcollUTF8 in a broker that does not. Neither
# combination announces itself; the second does not even fail to link, because
# the lib's own .so pulled ICU in.
#
# Same spelling as corNgsild's own variable, so `make COR_WITH_ICU=1` does the
# right thing whether it is run here or there.
#
COR_WITH_ICU ?= 0
ifeq ($(COR_WITH_ICU),1)
CMAKE_ICU = -DCOR_FEATURE_ICU_COLLATION=ON
else
CMAKE_ICU = -DCOR_FEATURE_ICU_COLLATION=OFF
endif
#
# COR_WITH_COR_PROTOCOL - 1 | 0. cor://, the binary NGSI-LD protocol: --corPort, and forwarding to a
# cor:// registration. ONE variable for two flags, as COR_WITH_ICU: corRest's COR_WITH_COR_PROTOCOL leaves
# its cor:// server and client out of the lib, the broker's COR_FEATURE_COR_PROTOCOL leaves out what calls
# them. The libs are whole-archived, so the broker's switch alone would remove the option and keep the
# code.
#
COR_WITH_COR_PROTOCOL ?= 1
ifeq ($(COR_WITH_COR_PROTOCOL),1)
CMAKE_COR = -DCOR_FEATURE_COR_PROTOCOL=ON
else
CMAKE_COR = -DCOR_FEATURE_COR_PROTOCOL=OFF
endif
#
# COR_WITH_GEOQ - 1 | 0. Geo-queries: GEOS, and what matches a geometry. ONE variable for two flags, as
# COR_WITH_COR_PROTOCOL: corDB compiles the broker's shared/geoMatch.c and links libgeos_c itself, so the
# broker's COR_FEATURE_GEOQ alone would leave GEOS in corDB.so.
#
COR_WITH_GEOQ ?= 1
ifeq ($(COR_WITH_GEOQ),1)
CMAKE_GEOQ = -DCOR_FEATURE_GEOQ=ON
else ifeq ($(COR_WITH_GEOQ),0)
CMAKE_GEOQ = -DCOR_FEATURE_GEOQ=OFF
else
$(error COR_WITH_GEOQ is 1 or 0, not '$(COR_WITH_GEOQ)')
endif
#
# COR_WITH_TROE_CORDB - 1 | 0. corDB's own temporal history (--troe corDB). ONE variable for two flags, as
# COR_WITH_GEOQ: corDB's makefile leaves its TRoE part out of corDB.so, the broker's COR_FEATURE_TROE_CORDB
# leaves --troe corDB out of what it says it has.
#
COR_WITH_TROE_CORDB ?= 1
ifeq ($(COR_WITH_TROE_CORDB),1)
CMAKE_TROE_CORDB = -DCOR_FEATURE_TROE_CORDB=ON
else ifeq ($(COR_WITH_TROE_CORDB),0)
CMAKE_TROE_CORDB = -DCOR_FEATURE_TROE_CORDB=OFF
else
$(error COR_WITH_TROE_CORDB is 1 or 0, not '$(COR_WITH_TROE_CORDB)')
endif
#
# COR_WITH_CORDB - 1 | 0. The corDB current-state store (--database corDB, and ramDB - corDB in RAM only).
# ONE variable for two flags, as COR_WITH_TROE_CORDB: corDB is a repo of its own, built here or not at all
# (CORDB_LIB in SIBLING_LIBS and PGO_LIBS), and the broker's COR_FEATURE_CORDB says whether it has it -
# without, it refuses --database corDB and ramDB whatever corDB.so is in the plugin directory. Off turns
# TROE_CORDB off too (CMakeLists.txt), and `make pgo` refuses it: its training runs corDB.
#
COR_WITH_CORDB ?= 1
ifeq ($(COR_WITH_CORDB),1)
CMAKE_CORDB = -DCOR_FEATURE_CORDB=ON
CORDB_LIB = corDB
else ifeq ($(COR_WITH_CORDB),0)
CMAKE_CORDB = -DCOR_FEATURE_CORDB=OFF
CORDB_LIB =
else
$(error COR_WITH_CORDB is 1 or 0, not '$(COR_WITH_CORDB)')
endif
#
# COR_OPTIMIZE - speed | size. What the broker's defaults spend RAM on (CMakeLists.txt, doc/building-details.md):
# speed (the default) for throughput, size for small hardware at low request rates. The broker's own cmake
# option for now - nothing in the libs differs yet.
#
COR_OPTIMIZE ?= speed
ifneq ($(words $(filter $(COR_OPTIMIZE),speed size)),1)
$(error COR_OPTIMIZE is speed or size, not '$(COR_OPTIMIZE)')
endif
CMAKE_OPTIMIZE = -DCOR_OPTIMIZE=$(COR_OPTIMIZE)
#
# corHttp only exists in the link when the build carries it as a server (builtin, both), or a bridge's port is in the build
# (COR_FEATURE_BRIDGE_HTTP_LISTEN, on unless CMAKE_FEATURES turns it off). SIBLING_LIBS above places it.
#
ifneq ($(filter builtin both,$(COR_HTTP_SERVER)),)
HTTP_LIB = corHttp
else ifeq ($(findstring COR_FEATURE_BRIDGE_HTTP_LISTEN=OFF,$(CMAKE_FEATURES)),)
HTTP_LIB = corHttp
endif
#
# libs - the sibling libs as DEBUG builds (BUILD=debug: -DCOR_T_ON, -DDEBUG where a lib has it), for
# `make debug` / `make di`. BUILD is passed rather than left to each lib's default, so a BUILD in the
# environment cannot pick the flavour.
#
libs:
@for lib in $(SIBLING_LIBS); do \
$(MAKE) -C $(SIBLING_DIR)/$$lib COR_HTTP_SERVER=$(COR_HTTP_SERVER) COR_WITH_ICU=$(COR_WITH_ICU) COR_WITH_COR_PROTOCOL=$(COR_WITH_COR_PROTOCOL) COR_WITH_GEOQ=$(COR_WITH_GEOQ) COR_WITH_TROE_CORDB=$(COR_WITH_TROE_CORDB) CORAINE=$(CURDIR) BUILD=debug di || exit 1; \
done
#
# libs-release - the sibling libs as RELEASE builds, for `make release` / `make i`
#
# A debug lib linked into a release broker carries its traces (COR_T_ON) and its DEBUG-only code
# (corNgsild's ldTermId: a full lookup + a stale check on every call). `release` checks the result -
# see no_debug_code below.
#
libs-release:
@for lib in $(SIBLING_LIBS); do \
$(MAKE) -C $(SIBLING_DIR)/$$lib COR_HTTP_SERVER=$(COR_HTTP_SERVER) COR_WITH_ICU=$(COR_WITH_ICU) COR_WITH_COR_PROTOCOL=$(COR_WITH_COR_PROTOCOL) COR_WITH_GEOQ=$(COR_WITH_GEOQ) COR_WITH_TROE_CORDB=$(COR_WITH_TROE_CORDB) CORAINE=$(CURDIR) BUILD=release install || exit 1; \
done
#
# The way OUT of a coverage build - and it has to be a separate target.
#
# `libs` above is each lib's own incremental `make di`, and a change of COMPILER
# FLAGS is invisible to that: after `make coverage` the objects are instrumented
# and NEWER than their sources, so `make libs` rebuilds precisely nothing. What
# you get is not a warning but two silent wrongs - corNgsild stays instrumented
# inside a build that calls itself ordinary (`--coverage -O0`, so also a build
# nobody should measure performance on), and corRest fails outright, because its
# own test binary is linked without -lgcov and every object now wants
# __gcov_init. The coverage targets say to run this one, not `libs`.
#
libs-rebuild:
@for lib in $(SIBLING_LIBS); do \
$(MAKE) -C $(SIBLING_DIR)/$$lib clean >/dev/null || exit 1; \
$(MAKE) -C $(SIBLING_DIR)/$$lib COR_HTTP_SERVER=$(COR_HTTP_SERVER) COR_WITH_ICU=$(COR_WITH_ICU) COR_WITH_COR_PROTOCOL=$(COR_WITH_COR_PROTOCOL) COR_WITH_GEOQ=$(COR_WITH_GEOQ) COR_WITH_TROE_CORDB=$(COR_WITH_TROE_CORDB) CORAINE=$(CURDIR) BUILD=debug di || exit 1; \
done
#
# no_debug_code <files> - fail a RELEASE build that carries debug code
#
# Every object compiled with COR_T_ON (a debug build: corLog.h, corBase/corLibLog.h) holds the
# string "COR_T_ON:traces-compiled-in". A release broker, its plugins and corDB's plugins must hold
# none: one found means a library was linked - or a plugin built - in its debug flavour. A grep over
# a few MiB, after the link.
#
define no_debug_code
@bad=$$(LC_ALL=C grep -l -a -F 'COR_T_ON:traces-compiled-in' $(1) 2>/dev/null); \
if [ -n "$$bad" ]; then \
echo "ERROR: this RELEASE build carries debug code (compiled with COR_T_ON):"; \
for f in $$bad; do echo " $$f"; done; \
echo "A library or plugin in it was built as debug. The libraries: $(MAKE) libs-release"; \
exit 1; \
fi
endef
# What a release build in <build-dir> consists of: the broker, its plugins, corDB's release plugins
RELEASE_FILES = $(1)/src/app/coraine/coraine $$(find $(1)/src/plugins $(if $(CORDB_LIB),$(SIBLING_DIR)/corDB/obj/release) -name '*.so' 2>/dev/null)
#
# src/app/coraine/coraineStack.h - the resolved commit of every library linked in.
#
# GENERATED, never committed. The broker is largely library code, the cor* repos
# track main, so coraine's own sha
# answers only part of "what is this build". stackManifest.sh resolves the rest;
# this turns it into something getVersion can render.
#
# Regenerated on every build rather than cached: it is one `git rev-parse` per
# sibling, and a stale answer here is worse than no answer.
#
src/app/coraine/coraineStack.h: FORCE
@{ echo '// GENERATED by the makefile from stackManifest.sh - do not edit, do not commit.'; echo '#ifndef CORAINE_STACK_H_'; echo '#define CORAINE_STACK_H_'; echo ''; echo 'static const char* const coraineStack[][2] ='; echo '{'; COR_HTTP_SERVER=$(COR_HTTP_SERVER) COR_HTTP_LINKED=$(if $(HTTP_LIB),1,0) ./stackManifest.sh | while read -r lib sha; do printf ' { "%s", "%s" },\n' "$$lib" "$$sha"; done; echo ' { NULL, NULL }'; echo '};'; echo ''; echo '#endif // CORAINE_STACK_H_'; } > $@
#
# CMAKE_FEATURES - feature switches for a reduced build. E.g.
#
# make di CMAKE_FEATURES=-DCOR_FEATURE_REGISTRATIONS=OFF BUILD_DEBUG=BUILD_DEBUG_MINIMAL
#
# CMake CACHES what it is given, so a switch stays in effect for that build
# DIRECTORY until it is passed again with the other value - which is why the
# example above also moves the build dir: it keeps the ordinary BUILD_DEBUG a
# full build instead of quietly turning it into a reduced one that then installs
# over /usr/local/bin/coraine.
#
CMAKE_FEATURES ?=
ifneq ($(findstring COR_FEATURE_ICU_COLLATION,$(CMAKE_FEATURES)),)
$(error ICU_COLLATION goes in COR_WITH_ICU=0|1, not CMAKE_FEATURES: it selects corNgsild's code path as well as the broker's link)
endif
ifneq ($(findstring COR_FEATURE_COR_PROTOCOL,$(CMAKE_FEATURES)),)
$(error COR_PROTOCOL goes in COR_WITH_COR_PROTOCOL=0|1, not CMAKE_FEATURES: it selects what corRest is built with as well as the broker's switch)
endif
ifneq ($(findstring COR_FEATURE_GEOQ,$(CMAKE_FEATURES)),)
$(error GEOQ goes in COR_WITH_GEOQ=0|1, not CMAKE_FEATURES: corDB compiles the geo matcher and links GEOS as well as the broker)
endif
ifneq ($(findstring COR_FEATURE_TROE_CORDB,$(CMAKE_FEATURES)),)
$(error TROE_CORDB goes in COR_WITH_TROE_CORDB=0|1, not CMAKE_FEATURES: corDB's makefile leaves its history out as well as the broker)
endif
ifneq ($(findstring COR_FEATURE_CORDB,$(CMAKE_FEATURES)),)
$(error CORDB goes in COR_WITH_CORDB=0|1, not CMAKE_FEATURES: corDB is built by this makefile or not at all, as well as the broker's switch)
endif
#
# src/app/coraine/coraineBuild.h - what produced this binary.
#
# GENERATED, never committed - the sibling of coraineStack.h above, and split
# from it because they answer different questions: the stack says WHAT IS LINKED
# IN, this says WHERE THIS BINARY CAME FROM. Both are regenerated on every build
# rather than cached, for the same reason: a stale answer here is worse than no
# answer, and it is two shell commands.
#
# The build TYPE and the compiler are not here - only cmake knows those, and it
# passes them as -D (see CMakeLists.txt). Each fact comes from whoever actually
# knows it.
#
src/app/coraine/coraineBuild.h: FORCE
@{ echo '// GENERATED by the makefile - do not edit, do not commit.'; \
echo '#ifndef CORAINE_BUILD_H_'; \
echo '#define CORAINE_BUILD_H_'; \
echo ''; \
echo '#define CORAINE_GIT_SHA "$(CORAINE_GIT_SHA)"'; \
echo '#define CORAINE_BUILT_AT "$(CORAINE_BUILD_AT)"'; \
echo ''; \
echo '#endif // CORAINE_BUILD_H_'; \
} > $@
release: libs-release etc/contextSourceExtras.json src/app/coraine/coraineStack.h src/app/coraine/coraineBuild.h
cmake -B $(BUILD_RELEASE) -DCMAKE_BUILD_TYPE=Release -DCOR_HTTP_SERVER=$(COR_HTTP_SERVER) $(CMAKE_ICU) $(CMAKE_COR) $(CMAKE_GEOQ) $(CMAKE_TROE_CORDB) $(CMAKE_CORDB) $(CMAKE_OPTIMIZE) $(CMAKE_FEATURES)
cmake --build $(BUILD_RELEASE) -j$(CPU_COUNT)
$(call no_debug_code,$(call RELEASE_FILES,$(BUILD_RELEASE)))
#
# pgo - a profile-guided RELEASE build in BUILD_PGO (doc/performance.md, "Profile-guided")
#
# 1. every library and the broker built with -fprofile-generate (atomic counters: the broker is
# multi-threaded); 2. test/perf/pgoTrain.sh runs it through the measured work - perfRun's request
# shapes, a write that notifies, the three-broker chain in all three modes; 3. all of it rebuilt with
# -fprofile-use, in the SAME object paths (the profile files are named after them).
# Every library stages the archive it built last at its repo root, here the profile-guided release
# one, so they are rebuilt as debug at the end: a `make di` after this must not link them.
# Against the same source without it: +1-10 % per core, +4-15 % on the chain (doc/performance.md).
#
PGO_LIBS = corBase corAlloc corHash corLog corArgs corTree corJson corProm corHttp corRest corJsonld corNgsild $(CORDB_LIB)
PGO_PROFILE = $(CURDIR)/BUILD_PGO_PROFILE
PGO_GEN = -fprofile-generate=$(PGO_PROFILE) -fprofile-update=atomic
PGO_USE = -fprofile-use=$(PGO_PROFILE) -fprofile-partial-training -fprofile-correction -Wno-missing-profile
# PGO_RESTORE_DEBUG=0 where nothing builds debug after it (the Docker image, CI) - saves the rebuild
PGO_RESTORE_DEBUG ?= 1
# PGO_TRAIN - what the instrumented broker is trained on: perfRun's shapes and more (pgoTrain.sh), or a
# workload of your own (`make tune`)
PGO_TRAIN ?= test/perf/pgoTrain.sh
#
# tune - the broker built for YOUR workload (doc/extreme-performance.md): `make tune WORKLOAD=<file.json>`
#
# 1. `make pgo`, trained on the workload (test/perf/tune/tuneTrain.sh) instead of pgoTrain.sh's shapes;
# 2. the knobs measured on it with that build - --dbLockPrefer reads|writes x the allocator (glibc's,
# jemalloc, tcmalloc where installed) - test/perf/tune/tuneMeasure.sh;
# 3. tune-result.json: every combination, the best, and how to run it. `make install_pgo` installs the build.
#
WORKLOAD ?=
tune:
@[ -n "$(WORKLOAD)" ] && [ -f "$(WORKLOAD)" ] || { echo "make tune WORKLOAD=<workload.json> - doc/extreme-performance.md"; exit 1; }
python3 test/perf/tune/tuneGen.py $(WORKLOAD) $(CURDIR)/BUILD_TUNE_GEN > /dev/null
TUNE_WORKLOAD=$(abspath $(WORKLOAD)) $(MAKE) pgo PGO_TRAIN=test/perf/tune/tuneTrain.sh
test/perf/tune/tuneMeasure.sh $(WORKLOAD) BUILD_PGO/src/app/coraine/coraine BUILD_PGO/src/plugins > tune-result.json
@python3 -c "import json; r=json.load(open('tune-result.json')); b=r['best']; print('tune: best', b['brokerOptions'], ' '.join('%s=%s' % kv for kv in b['env'].items()), '-', b['rps'], 'requests/s,', b['vsDefault'], 'against the out-of-the-box settings - tune-result.json')"
pgo: etc/contextSourceExtras.json src/app/coraine/coraineStack.h src/app/coraine/coraineBuild.h
@[ "$(COR_WITH_CORDB)" = 1 ] || { echo "make pgo: COR_WITH_CORDB=0 - the training (test/perf/pgoTrain.sh) runs the broker on corDB"; exit 1; }
rm -rf $(PGO_PROFILE) BUILD_PGO
@for lib in $(PGO_LIBS); do \
$(MAKE) -B -C $(SIBLING_DIR)/$$lib BUILD=release COR_HTTP_SERVER=$(COR_HTTP_SERVER) COR_WITH_ICU=$(COR_WITH_ICU) COR_WITH_COR_PROTOCOL=$(COR_WITH_COR_PROTOCOL) COR_WITH_GEOQ=$(COR_WITH_GEOQ) COR_WITH_TROE_CORDB=$(COR_WITH_TROE_CORDB) CORAINE=$(CURDIR) CC="gcc $(PGO_GEN)" install > /dev/null || exit 1; \
done
cmake -B BUILD_PGO -DCMAKE_BUILD_TYPE=Release -DCOR_HTTP_SERVER=$(COR_HTTP_SERVER) $(CMAKE_ICU) $(CMAKE_COR) $(CMAKE_GEOQ) $(CMAKE_TROE_CORDB) $(CMAKE_CORDB) $(CMAKE_OPTIMIZE) $(CMAKE_FEATURES) \
-DCOR_C_FLAGS_RELEASE="-O2 -g $(PGO_GEN)" -DCMAKE_EXE_LINKER_FLAGS="-fprofile-generate" -DCMAKE_SHARED_LINKER_FLAGS="-fprofile-generate"
cmake --build BUILD_PGO -j$(CPU_COUNT)
$(PGO_TRAIN) BUILD_PGO/src/app/coraine/coraine BUILD_PGO/src/plugins
@for lib in $(PGO_LIBS); do \
$(MAKE) -B -C $(SIBLING_DIR)/$$lib BUILD=release COR_HTTP_SERVER=$(COR_HTTP_SERVER) COR_WITH_ICU=$(COR_WITH_ICU) COR_WITH_COR_PROTOCOL=$(COR_WITH_COR_PROTOCOL) COR_WITH_GEOQ=$(COR_WITH_GEOQ) COR_WITH_TROE_CORDB=$(COR_WITH_TROE_CORDB) CORAINE=$(CURDIR) CC="gcc $(PGO_USE)" install > /dev/null || exit 1; \
done
cmake -B BUILD_PGO -DCMAKE_BUILD_TYPE=Release -DCOR_HTTP_SERVER=$(COR_HTTP_SERVER) $(CMAKE_ICU) $(CMAKE_COR) $(CMAKE_GEOQ) $(CMAKE_TROE_CORDB) $(CMAKE_CORDB) $(CMAKE_OPTIMIZE) $(CMAKE_FEATURES) \
-DCOR_C_FLAGS_RELEASE="-O2 -g $(PGO_USE)" -DCMAKE_EXE_LINKER_FLAGS="" -DCMAKE_SHARED_LINKER_FLAGS=""
cmake --build BUILD_PGO -j$(CPU_COUNT) --clean-first
$(call no_debug_code,$(call RELEASE_FILES,BUILD_PGO))
@if [ "$(PGO_RESTORE_DEBUG)" = 1 ]; then for lib in $(PGO_LIBS); do \
$(MAKE) -B -C $(SIBLING_DIR)/$$lib BUILD=debug COR_HTTP_SERVER=$(COR_HTTP_SERVER) COR_WITH_ICU=$(COR_WITH_ICU) COR_WITH_COR_PROTOCOL=$(COR_WITH_COR_PROTOCOL) COR_WITH_GEOQ=$(COR_WITH_GEOQ) COR_WITH_TROE_CORDB=$(COR_WITH_TROE_CORDB) CORAINE=$(CURDIR) di > /dev/null || exit 1; \
done; fi
@echo "pgo: BUILD_PGO/src/app/coraine/coraine - profile-guided (make install_pgo installs it)"
debug: libs etc/contextSourceExtras.json src/app/coraine/coraineStack.h src/app/coraine/coraineBuild.h
cmake -B $(BUILD_DEBUG) -DCMAKE_BUILD_TYPE=Debug -DCOR_HTTP_SERVER=$(COR_HTTP_SERVER) $(CMAKE_ICU) $(CMAKE_COR) $(CMAKE_GEOQ) $(CMAKE_TROE_CORDB) $(CMAKE_CORDB) $(CMAKE_OPTIMIZE) $(CMAKE_FEATURES)
cmake --build $(BUILD_DEBUG) -j$(CPU_COUNT)
clean:
rm -rf $(BUILD_RELEASE) $(BUILD_DEBUG) $(BUILD_COVERAGE) BUILD_PGO BUILD_PGO_PROFILE BUILD_TUNE_GEN coverage coverage-* $(COV_ETSI_DIR)
#
# The file is DATA, not source - nothing includes it and nothing compiles from
# it. The broker reads it at startup and renders it verbatim on
# /info/sourceIdentity (§ 5.2.40), so its content is a claim about the build
# that is running: version, commit, build time.
#
# Which is why it is regenerated unconditionally (FORCE) and is NOT in git. It
# used to be both committed and dependent on makefile+coraineVersion.h, so a
# fresh clone shipped whatever sha happened to be committed and `make` had no
# reason to correct it - the broker then announced a commit that was not the one
# serving the request.
#
FORCE:
etc/contextSourceExtras.json: FORCE
@mkdir -p etc
@printf '{\n "version": "%s",\n "gitSha": "%s",\n "buildAt": "%s"\n}\n' \
"$(CORAINE_VERSION)" "$(CORAINE_GIT_SHA)" "$(CORAINE_BUILD_AT)" > $@
#
# installFile <file> <path> - a NEW file at <path>: copied beside it, then renamed over it.
#
# Never `cp` onto an installed file: cp rewrites the existing file in place - the same inode - and a
# running broker has its plugins mapped (dlopen). Their code then changes under it, and the broker
# dies of SIGSEGV or SIGILL within seconds, in whichever thread next runs plugin code (corPeriodic,
# once a second, or the shutdown). Onto the running binary itself cp fails outright (Text file busy).
# A rename leaves a running broker its old files; its next start loads the new ones.
# test/install/installUnderRunningBroker.sh checks it.
#
installFile = cp -p $(1) $(dir $(2)).$(notdir $(2)).new && mv -f $(dir $(2)).$(notdir $(2)).new $(2)
# install_from <build-dir> — copy broker + plugins + etc out of a build tree
define install_from
mkdir -p $(PREFIX)/bin $(PLUGIN_DIR)/db/currentState $(PLUGIN_DIR)/troe/temporal $(PLUGIN_DIR)/api $(PLUGIN_DIR)/bridge $(PLUGIN_DIR)/transport $(PLUGIN_DIR)/auth $(ETC_DIR)
$(call installFile,$(1)/src/app/coraine/coraine,$(PREFIX)/bin/coraine)
if [ -f $(1)/src/app/coraineImport/coraine-import ]; then $(call installFile,$(1)/src/app/coraineImport/coraine-import,$(PREFIX)/bin/coraine-import); fi # COR_FEATURE_MIGRATE
if [ -f $(1)/src/plugins/currentState/mongoc/mongoc.so ]; then $(call installFile,$(1)/src/plugins/currentState/mongoc/mongoc.so,$(PLUGIN_DIR)/db/currentState/mongoc.so); fi # COR_FEATURE_MONGOC
$(call installFile,$(1)/src/plugins/temporal/none/none.so,$(PLUGIN_DIR)/troe/temporal/none.so)
if [ -f $(1)/src/plugins/temporal/timescale/timescale.so ]; then $(call installFile,$(1)/src/plugins/temporal/timescale/timescale.so,$(PLUGIN_DIR)/troe/temporal/timescale.so); fi # COR_FEATURE_TROE_TIMESCALE
if [ -f $(1)/src/plugins/api/admin/admin.so ]; then $(call installFile,$(1)/src/plugins/api/admin/admin.so,$(PLUGIN_DIR)/api/admin.so); fi # COR_FEATURE_ADMIN_API
$(call installFile,$(1)/src/plugins/bridge/loopback/loopback.so,$(PLUGIN_DIR)/bridge/loopback.so)
if [ -f $(1)/src/plugins/transport/ws/ws.so ]; then $(call installFile,$(1)/src/plugins/transport/ws/ws.so,$(PLUGIN_DIR)/transport/ws.so); fi # COR_FEATURE_TRANSPORTS
if [ -f $(1)/src/plugins/auth/fdsc/fdsc.so ]; then $(call installFile,$(1)/src/plugins/auth/fdsc/fdsc.so,$(PLUGIN_DIR)/auth/fdsc.so); fi # COR_FEATURE_AUTH
if [ -f $(1)/src/plugins/auth/oidc/oidc.so ]; then $(call installFile,$(1)/src/plugins/auth/oidc/oidc.so,$(PLUGIN_DIR)/auth/oidc.so); fi # COR_FEATURE_AUTH_OIDC
$(call installFile,etc/contextSourceExtras.json,$(ETC_DIR)/contextSourceExtras.json)
endef
install: etc/contextSourceExtras.json
$(call install_from,$(BUILD_RELEASE))
install_debug: etc/contextSourceExtras.json
$(call install_from,$(BUILD_DEBUG))
#
# corDB is a plugin, not an archive linked into BUILD_PGO: its .so goes in from its own obj/release,
# with the same make line as the PGO-use pass above (same flags, so nothing rebuilds). Without it,
# PGO_RESTORE_DEBUG=1 leaves the DEBUG corDB.so installed next to a profile-guided broker.
#
install_pgo: etc/contextSourceExtras.json
$(call install_from,BUILD_PGO)
$(MAKE) -C $(SIBLING_DIR)/corDB BUILD=release COR_HTTP_SERVER=$(COR_HTTP_SERVER) COR_WITH_ICU=$(COR_WITH_ICU) COR_WITH_COR_PROTOCOL=$(COR_WITH_COR_PROTOCOL) COR_WITH_GEOQ=$(COR_WITH_GEOQ) COR_WITH_TROE_CORDB=$(COR_WITH_TROE_CORDB) CORAINE=$(CURDIR) CC="gcc $(PGO_USE)" install > /dev/null
test:
$(CORTEST)
coverage: src/app/coraine/coraineStack.h src/app/coraine/coraineBuild.h
#
# The coverage tree is built from scratch, deliberately. gcov counters live in
# .gcno/.gcda files next to the objects, and nothing removes the ones belonging to
# a source that was renamed or deleted - gcovr then reports those vanished files as
# entirely unexecuted. That is not hypothetical: after corRamDB became corDB, a
# stale tree added ~700 phantom uncovered lines and moved the mongoc figure from
# 80.7% to 77.5%. A wrong coverage number is worse than none, and the rebuild is a
# couple of minutes against a twenty-minute suite.
#
rm -rf $(BUILD_COVERAGE)
#
# Drop any previous verdict FIRST, before anything that can fail. A stale
# suite-status from an earlier run would otherwise outlive a build that never
# reached the suite, and the published page would report last week's verdict
# as this run's.
#
@rm -f $(COV_STATUS)
#
# The libs are PART OF THE BROKER, so they belong in its coverage figure.
#
# corRest, corNgsild and corJsonld are static .a whole-archived into the binary -
# corNgsild alone is 31k lines, most of the NGSI-LD rules - and they are built by
# `make libs` with ordinary flags. Linked like that they carry no counters at all,
# so they were not reported as UNCOVERED, they were absent: neither numerator nor
# denominator. The published figure said "coraine/src" while looking like it said
# "the broker", and roughly half the C was outside it.
#
# So instrument them here, exactly as coverage-etsi has always done. They flush
# through the broker's own gcov runtime (whole-archived, no per-.so coverage link).
#
# The .gcno wipe is not redundant with `clean`: the libs' clean target removes
# objects, deps, .so and .a but NOT .gcno, and gcovr counts a .gcno whose source
# is gone as an entirely unexecuted file. Stale ones really do survive - a July
# coverage-etsi run left its .gcno sitting in corNgsild for seven weeks.
#
#
# EXTRA_CFLAGS, never DFLAGS. DFLAGS is a plain variable in each lib's makefile,
# so setting it on the command line REPLACES the lib's own defaults rather than
# adding to them - and a `DFLAGS +=` inside the makefile is then ignored too,
# because += never appends to a command-line variable. corNgsild's defaults are
# `-DANSI` plus `-DCOR_WITH_ICU`, so the DFLAGS route compiled it with the
# ASCII-approximation collation path while the broker went on linking libicu:
# every coverage run measured a build nobody ships, with the ICU lines absent
# from the report and the #else branch counted in their place.
#
@echo ">>> Instrumenting the libs ($(COV_LIBS)) - they are linked into the broker"
@for d in $(COV_LIBS); do \
find $(SIBLING_DIR)/$$d -name '*.gcno' -delete; \
$(MAKE) -C $(SIBLING_DIR)/$$d clean >/dev/null && \
$(MAKE) -C $(SIBLING_DIR)/$$d COR_WITH_ICU=$(COR_WITH_ICU) COR_WITH_COR_PROTOCOL=$(COR_WITH_COR_PROTOCOL) COR_WITH_GEOQ=$(COR_WITH_GEOQ) COR_WITH_TROE_CORDB=$(COR_WITH_TROE_CORDB) CORAINE=$(CURDIR) BUILD=coverage EXTRA_CFLAGS="--coverage -O0 -Wno-error" lib$$d.a >/dev/null || exit 1; \
done
@rm -rf $(SIBLING_DIR)/corDB/obj/coverage
$(MAKE) -C $(SIBLING_DIR)/corDB BUILD=coverage >/dev/null
cmake -B $(BUILD_COVERAGE) -DCMAKE_BUILD_TYPE=Coverage -DCOR_HTTP_SERVER=$(COR_HTTP_SERVER) $(CMAKE_ICU) $(CMAKE_COR) $(CMAKE_GEOQ) $(CMAKE_TROE_CORDB) $(CMAKE_CORDB) $(CMAKE_OPTIMIZE)
cmake --build $(BUILD_COVERAGE) -j$(CPU_COUNT)
#
# Stage the instrumented plugins in the INSTALLED layout. The harness composes
# $COR_PLUGIN_DIR/db/currentState/<name>.so, so without this it loads whatever
# sits in /opt/seamware - an ordinary build with no counters - and every plugin
# source then reports as unexecuted while the run appears to have covered it.
#
@mkdir -p $(COV_PLUGIN_DIR)/db/currentState $(COV_PLUGIN_DIR)/troe/temporal $(COV_PLUGIN_DIR)/api $(COV_PLUGIN_DIR)/bridge $(COV_PLUGIN_DIR)/transport $(COV_PLUGIN_DIR)/auth
@cp -p $(BUILD_COVERAGE)/src/plugins/currentState/*/*.so $(COV_PLUGIN_DIR)/db/currentState/
@cp -p $(BUILD_COVERAGE)/src/plugins/temporal/*/*.so $(COV_PLUGIN_DIR)/troe/temporal/
#
# corDB's plugins as its `make install` lays them out: corDB.so (--troe corDB is its own troeRegister,
# no plugin of its own) and ramDB.so as current-state stores, the RAM ring troe/ramDB.so as --troe ramDB.
#
@cp -p $(SIBLING_DIR)/corDB/obj/coverage/corDB.so $(COV_PLUGIN_DIR)/db/currentState/
@cp -p $(SIBLING_DIR)/corDB/obj/coverage/ramDB.so $(COV_PLUGIN_DIR)/db/currentState/
@cp -p $(SIBLING_DIR)/corDB/obj/coverage/troe/ramDB.so $(COV_PLUGIN_DIR)/troe/temporal/
@cp -p $(BUILD_COVERAGE)/src/plugins/api/*/*.so $(COV_PLUGIN_DIR)/api/
@cp -p $(BUILD_COVERAGE)/src/plugins/bridge/*/*.so $(COV_PLUGIN_DIR)/bridge/
@cp -p $(BUILD_COVERAGE)/src/plugins/transport/*/*.so $(COV_PLUGIN_DIR)/transport/
@if [ -f $(BUILD_COVERAGE)/src/plugins/auth/fdsc/fdsc.so ]; then cp -p $(BUILD_COVERAGE)/src/plugins/auth/fdsc/fdsc.so $(COV_PLUGIN_DIR)/auth/; fi # COR_FEATURE_AUTH - without it every auth test's broker fails to start
@if [ -f $(BUILD_COVERAGE)/src/plugins/auth/oidc/oidc.so ]; then cp -p $(BUILD_COVERAGE)/src/plugins/auth/oidc/oidc.so $(COV_PLUGIN_DIR)/auth/; fi # COR_FEATURE_AUTH_OIDC
#
# The bridges from their own repositories (mqtt.so, modbus.so, dds.so) are not built here: staged
# as installed, without counters - their code is not coraine's and not in this report. Without
# them a test's --bridges mqtt names a plugin this directory does not have, the broker does not
# start, and every bridge and MQTT-notification test fails in its INIT.
#
@for p in $(PLUGIN_DIR)/bridge/*.so; do \
[ -e $(COV_PLUGIN_DIR)/bridge/$$(basename $$p) ] || cp -p $$p $(COV_PLUGIN_DIR)/bridge/; \
done
@find $(BUILD_COVERAGE) $(addprefix $(SIBLING_DIR)/,$(COV_LIBS)) $(SIBLING_DIR)/corDB/obj/coverage -name '*.gcda' -delete
#
# COR_PLUGIN_DIR is how the HARNESS spells a plugin path (--database ...).
# SEAMWARE_PLUGIN_DIR is how the BROKER resolves a short name a test passes
# itself - `coraineStart --apiPlugins admin`. Without the second one the broker
# loads the installed admin.so, which carries no counters, and the whole admin
# plugin reads as 0% in a run whose tests exercise it.
#
#
# The suite's exit status is RECORDED, not discarded.
#
# It used to end in `|| true`, for a good reason - the report is this target's
# output, and a red test must not cost you the report. But swallowing the status
# outright meant a red suite was indistinguishable from a green one, and that is
# not theoretical: `usage.test` and `csource-reg-proactive-loop` failed in EVERY
# coverage run from 82775bc until 2026-08-26 and the job reported success each
# time. Nobody looks at a green job.
#
# So the status goes to a file, the report is built regardless, and the target
# fails at the END - after the report exists. The workflow's later steps run with
# `if: always()`, so the artifact and the Pages publish still happen; what changes
# is that the job goes red and the site says why.
#
@mkdir -p $(COV_DIR)
COR_BROKER=$(CURDIR)/$(BUILD_COVERAGE)/src/app/coraine/coraine \
COR_PLUGIN_DIR=$(CURDIR)/$(COV_PLUGIN_DIR) \
SEAMWARE_PLUGIN_DIR=$(CURDIR)/$(COV_PLUGIN_DIR) \
$(CORTEST) -db $(COV_DB); echo $$? > $(COV_STATUS)
#
# The DB plugin that is NOT under test is excluded from the report. A corDB run
# cannot execute a line of mongoc.so and vice versa, so counting the other one
# as unexecuted measures the choice of DB rather than the state of the suite.
#
#
# --gcov-ignore-parse-errors: gcov occasionally reports a NEGATIVE hit count for
# a line in a threaded binary (GCC bug 68080), and gcovr treats that as fatal -
# a ten-minute run then ends with no report at all. coverage-etsi already passes
# this for the same reason.
#
# It needs gcovr >= 8.3 to do anything at all. In 8.2 the option is read only by
# the TEXT .gcov parser, while gcovr asks gcov for JSON by default - so the flag
# sat here inert until the nightly of 2026-08-25 died with it on the command line.
# The floor is pinned in corLibs/docker/Dockerfile.ci-nightly, which explains it.
#
# Do not remove the flag on the grounds that CMAKE_C_FLAGS_COVERAGE now carries
# -fprofile-update=atomic, and do not remove that on the grounds of this flag.
# They cover different halves: atomic counters stop the negative counts being
# PRODUCED, and on gcovr >= 8.3 a negative count without this flag does not fail -
# it drops the whole file from the report and exits 0, which is a silently short
# coverage figure.
#
#
# The root moves up to the sibling dir so the libs can be in the report at all,
# and the -f filters then say what "the broker" consists of: this repo's src plus
# the three libs archived into it. Everything else next door - corTest, corPlugin,
# other checkouts - stays out.
#
# ⚠️ This makes the percentage NOT comparable with anything recorded before
# 2026-09-01: the denominator roughly doubles. A drop against the old numbers is
# the measurement widening, not the suite regressing.
#
$(GCOVR) --root $(SIBLING_DIR) \
--gcov-ignore-parse-errors=negative_hits.warn_once_per_file \
-f '$(CURDIR)/src/' \
$(foreach d,$(COV_LIBS),-f '$(SIBLING_DIR)/$(d)/') \
$(if $(filter corDB,$(COV_DB)),-f '$(SIBLING_DIR)/corDB/') \
-e '.*/plugins/currentState/$(COV_OTHER_DB)/.*' \
--html-details $(COV_REPORT) --html-title "coraine coverage ($(COV_DB))" \
--print-summary \
$(BUILD_COVERAGE) $(addprefix $(SIBLING_DIR)/,$(COV_LIBS)) $(if $(filter corDB,$(COV_DB)),$(SIBLING_DIR)/corDB/obj/coverage)
@echo ""
@echo "Coverage report ($(COV_DB)): file://$(CURDIR)/$(COV_REPORT)"
@echo ""
@echo "NOTE: $(COV_LIBS) are left INSTRUMENTED (--coverage -O0)."
@echo " Run 'make libs-rebuild' before an ordinary build or a perf measurement."
@echo " Not 'make libs' - that is incremental and would rebuild nothing."
#
# Now, and only now, the suite's verdict. The report exists either way.
#
@status=$$(cat $(COV_STATUS)); \
if [ "$$status" != "0" ]; then \
echo ""; \
echo "*** The $(COV_DB) suite FAILED (corTest exited $$status)."; \
echo "*** The report above is real, but it measures a suite that is not passing."; \
exit $$status; \
fi
# Full ETSI-suite coverage: instrument the broker + NGSI-LD libs (corRest
# corNgsild corJsonld) + mongoc/timescale plugins, run the ETSI TP suite via
# etsiRun, then build an HTML report. The libs are static .a whole-archived
# into the broker, so they flush via the broker's gcov runtime (no per-.so
# coverage link needed); the plugin .so get --coverage from the Coverage build
# type (CMAKE_SHARED_LINKER_FLAGS).
coverage-etsi:
@echo ">>> [1/6] Instrumenting NGSI-LD libs ($(COV_LIBS))..."
@for d in $(COV_LIBS); do \
find ../$$d -name '*.gcno' -delete; \
$(MAKE) -C ../$$d clean >/dev/null && \
$(MAKE) -C ../$$d EXTRA_CFLAGS="--coverage -O0 -Wno-error" lib$$d.a || exit 1; \
done
@echo ">>> [2/6] Building broker + plugins (Coverage)..."
cmake -B $(BUILD_COVERAGE) -DCMAKE_BUILD_TYPE=Coverage
cmake --build $(BUILD_COVERAGE) -j$(CPU_COUNT)
@echo ">>> [3/6] Installing instrumented broker + plugins (etsiRun loads the installed ones)..."
$(MAKE) install_from_coverage
@echo ">>> [4/6] Wiping stale .gcda counters across build + lib trees..."
@find $(BUILD_COVERAGE) $(addprefix ../,$(COV_LIBS)) -name '*.gcda' -delete
@echo ">>> [5/6] Running the ETSI TP suite (etsiRun cor)..."
@etsiRun cor || true
@echo ">>> Stopping broker so gcov flushes .gcda (onSignal -> exit(0))..."
@if [ -f /tmp/etsi-coraine.pid ]; then \
P=$$(cat /tmp/etsi-coraine.pid); \
kill "$$P" 2>/dev/null || true; \
for i in 1 2 3 4 5 6 7 8 9 10; do kill -0 "$$P" 2>/dev/null && sleep 1 || break; done; \
fi
@echo ">>> [6/6] Generating coverage report..."
@mkdir -p $(COV_ETSI_DIR)
@$(GCOVR) --root $(SIBLING_DIR) --gcov-executable gcov \
--gcov-ignore-parse-errors=negative_hits.warn_once_per_file \
-f '$(CURDIR)/src/lib/' -f '$(CURDIR)/src/app/' \
-f '$(CURDIR)/src/plugins/currentState/mongoc/' \
-f '$(CURDIR)/src/plugins/temporal/timescale/' \
-f '$(CURDIR)/src/plugins/shared/' \
-f '$(SIBLING_DIR)/corRest/' -f '$(SIBLING_DIR)/corNgsild/' -f '$(SIBLING_DIR)/corJsonld/' \
--html-details $(COV_ETSI_DIR)/index.html --html-title "coraine ETSI Coverage" \
$(BUILD_COVERAGE) $(addprefix $(SIBLING_DIR)/,$(COV_LIBS))
@echo ""
@echo "ETSI coverage report: file://$(CURDIR)/$(COV_ETSI_DIR)/index.html"
@echo ""
@echo "NOTE: $(COV_LIBS) are left INSTRUMENTED (--coverage -O0)."
@echo " Run 'make libs-rebuild' before an ordinary build or a perf measurement."
@echo " Not 'make libs' - that is incremental and would rebuild nothing."
install_from_coverage: etc/contextSourceExtras.json
$(call install_from,$(BUILD_COVERAGE))
i: release install
di: debug install_debug
ci: clean release install
cdi: clean debug install_debug
#
# docker - build the image from the working tree, tagged coraine:local
#
# TWO steps, and the second fails without the first: the Dockerfile does NOT
# clone the Cor-Libs - vendor-libs.sh exports each one's committed HEAD into
# docker/vendor/, and the build aborts with "run ./docker/vendor-libs.sh first"
# if that directory is not there. Easy to forget, and the reason this target
# exists rather than a documented command.
#
# ⚠️ vendor-libs.sh stages each Cor-Lib's COMMITTED state, so uncommitted work
# next door is NOT in the image - which is the right default for something
# reproducible, but worth knowing when a change seems not to have taken.
#
# GIT_SHA / BUILD_AT are passed in because .git is not in the build context;
# they are what the broker reports on /info/sourceIdentity, so a `docker`
# build with them unset would ship an image that cannot say what it is.
#
DOCKER_TAG ?= coraine:local
# DOCKER_BUILD - release, or debug: traces compiled in (docker/README.md)
DOCKER_BUILD ?= release
#
# CI_IMAGE is where the eProsima DDS stack comes from - the CI image builds it
# once, every few months, and the broker image copies it out of /opt/dds rather
# than spending eight minutes compiling it again.
#
# EMPTY by default, so the pin is not restated here: docker/Dockerfile's own
# ARG is the one place that names a CI image, and a second copy in this file is
# how the two would come to disagree. Set it to build against another one:
#
# make docker CI_IMAGE=coraine-ci:local
#
CI_IMAGE ?=
docker:
@./docker/vendor-libs.sh
@docker build -f docker/Dockerfile \
--build-arg BUILD=$(DOCKER_BUILD) \
--build-arg GIT_SHA=$$(git rev-parse --short HEAD) \
--build-arg BUILD_AT=$$(date -u +%Y-%m-%dT%H:%M:%SZ) \
$(if $(CI_IMAGE),--build-arg CI_IMAGE=$(CI_IMAGE),) \
-t $(DOCKER_TAG) .
@echo "Built $(DOCKER_TAG) from $$(git rev-parse --short HEAD)"
@git diff --quiet || echo "WARNING: uncommitted changes are NOT in the image (vendor-libs stages committed state)"
.PHONY: pgo install_pgo all release debug clean install install_debug install_from_coverage test coverage coverage-etsi i di ci cdi libs libs-rebuild docker