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
|
#import "@preview/polylux:0.4.0": *
#import "@preview/metropolis-polylux:0.1.0" as metropolis
#show: metropolis.setup
#show: metropolis.setup.with(footer: [Firmware project with Meson build system])
#show raw: set text(ligatures: false, features: (calt: 0))
#slide[
#set page(header: none, footer: none, margin: 3em)
#text(size: 1.3em)[*Firmware project with Meson build system*]
Community Over Code Glasgow 2026
#metropolis.divider
#set text(size: .8em, weight: "light")
Karel Kočí
13.10.2026
]
#slide[
= The Point
#set text(size: 0.95em)
POSIX gives ability to run same programs on NuttX and Linux.
Advantages:
- Options when selecting libraries
- Easier and faster testing (including CI/CD)
- Possibility to test with tools such as Valgrind
Workflow:
- Develop on PC including libraries
- Unit testing on PC
- Sw/sw integration on PC
- Sw/hw integration on real hardware
We need a good way to build project for both targets (for NuttX flat build).
]
#metropolis.new-section[NuttX external]
#slide[
= Standard NuttX
```
.
├── nuttx
│ └── ...
└── apps
└── ...
```
\
```bash
cd nuttx
./tools/configure.sh rv-virt:nsh
make
```
]
#slide[
= External Applications and Libraries
```
├── nuttx
│ ├── external -> ../project-libs
│ └── ...
├── apps
│ ├── external -> ../project-apps
│ └── ...
├── project-libs
│ └── ...
└── project-apps
└── ...
```
#text(weight: "bold")[`configure-nuttx.sh`]
```bash
ln -sf ../project-libs nuttx/external
ln -sf ../project-apps apps/external
```
]
#slide[
= Apps Directory
#text(weight: "bold")[`project-apps/Make.defs`]
```make
include $(wildcard $(APPDIR)/external/*/Make.defs)
```
#text(weight: "bold")[`project-apps/Makefile`]
```make
MENUDESC = "Project Applications"
include $(APPDIR)/Directory.mk
```
]
#slide[
= A Project App
#text(weight: "bold")[`project-apps/project_hello/Make.defs`]
```make
CONFIGURED_APPS += $(APPDIR)/external/project_hello
```
#text(weight: "bold")[`project-apps/project_hello/Makefile`]
```make
include $(APPDIR)/Make.defs
PROGNAME = $(CONFIG_NUTTX_USBNSH_PROGNAME)
PRIORITY = $(CONFIG_NUTTX_USBNSH_PRIORITY)
STACKSIZE = $(CONFIG_NUTTX_USBNSH_STACKSIZE)
MODULE = $(CONFIG_NUTTX_USBNSH)
MAINSRC = project_hello_main.c
include $(APPDIR)/Application.mk
```
#text(weight: "bold")[`project-apps/project_hello/Kconfig`] ...
]
#slide[
= A Project App: In More Depth
#text(size: 0.9em)[
```make
all:: .built
context::
register::
$(call REGISTER,$(PROGNAME_$@),$(PRIORITY_$@),$(STACKSIZE_$@),$@_main)
.built: $(AROBJS)
$(call ARLOCK, $(call CONVERT_PATH,$(BIN)), $^)
CFLAGS += ${DEFINE_PREFIX}main=$(addsuffix _main,$(PROGSYM_$@))
```
]
]
#slide[
= External Board
```bash
mkdir board
cp -r nuttx/boards/risc-v/qemu-rv/rv-virt/{src,include,scripts} board/
```
#text(weight: "bold")[`board/defconfig`] (replace `CONFIG_ARCH_BOARD*`)
```Kconfig
...
CONFIG_ARCH_BOARD_CUSTOM=y
CONFIG_ARCH_BOARD_CUSTOM_DIR="../board"
CONFIG_ARCH_BOARD_CUSTOM_DIR_RELPATH=y
CONFIG_ARCH_BOARD_CUSTOM_NAME="TEMPLATE"
```
#text(weight: "bold")[`configure-nuttx.sh`]
```bash
...
cp -f board/defconfig nuttx/.config
make -C nuttx olddefconfig
```
]
#slide[
= Bonus Round: Config verification
```bash
while read -r line; do
[[ "$cnf" == CONFIG_* ]] || continue
if [[ "${line#*=}" == "n" ]]; then
if grep -q "^${line%=*}=(y|m)$" nuttx/.config; then
echo "Not correctly set: $line" >&2; exit 1
fi
else
if ! grep -qF "$line" nuttx/.config; then
echo "Not correctly set: $line" >&2; exit 1
fi
fi
done <"board/defconfig"
done
```
]
#metropolis.new-section[Meson]
#slide[
= Requirements for Build System
- Build libraries and applications
- No special rules in build system for NuttX
- Support for external projects with minimal NuttX boilerplate
]
#slide[
= Quick Overview
Leading build system for building libraries and executables for Linux.
\
#text(weight: "bold")[`meson.build`]
```python
project('tutorial', 'c')
libfoo = library('foo', files('foo.c'),
include_directories=include_directories('.'))
executable('demo', files('main.c'), dependencies: [libfoo],
install: true)
```
\
Outputs ninja or other build systems.
]
#slide[
= Compare with make and cmake
#text(size: 0.9em)[
#toolbox.side-by-side[
#text(weight: "bold")[Make]
- 🙂 Generic build system (language)
- 😕 Can be tweaked to build almost anything
- 😢 Good build systems are complex
- 😢 Build targets standardization old and obsolete
- 🫣 No standard way to set toolchain
- 😕 No standard way to manage build time dependencies
][
#text(weight: "bold")[CMake]
- 🙂 Generic build system (language)
- 😕 Can be tweaked to build almost anything
- 😊 Has build target standardization
- 😢 Build target standardization is optional
- 😊 Toolchain.cmake
- 😢 Alternative ways to manage toolchain
- 😊 FetchContent
]
]
]
#slide[
= While Meson...
- 😊 Can build only predefined types
- 😊 Can't be tweaked that much
- 🙃 Not a complete language
- 😊 crossfile.ini
- 😍 makes it hard to not use standard way
- 😊 subprojects with even cmake support
]
#metropolis.new-section[Meson Integration]
#slide[
= Two Ways
#toolbox.side-by-side[
#text(weight: "bold")[NuttX as project's library]
Use exported libraries and linker script from NuttX in any other build
system.
```bash
make -C nuttx export
```
][
#text(weight: "bold")[Project as app in NuttX]
NuttX build system deals with Firmware build.
App integration uses our project's build system and adds results to NuttX
linkage.
]
]
#slide[
= Phase 1: crossfile
#text(size: 0.8em)[
#text(weight: "bold")[`project-apps/meson-apps/Makefile`]
```make
crossfile.ini: .FORCE
./crossfile.sh '$(CC)' '$(AR)' '$(CFLAGS)'
```
#text(weight: "bold")[`project-apps/meson-apps/crossfile.sh`]
```bash
march="${3/*-march=/}"; march="${march/ */}"
flags_sanit() { sed -E "s#-Wshadow##;s#\"##g; s#-I #-I#g" <<<"$1" }
cat >crossfile.ini <<-EOF
[binaries]
c = '$1'
ar = '$2'
[built-in options]
c_args = [$(flags_sanit "$cflags" | sed -E "s#([^ ]+)#'\1'#g; s# +#, #g")]
c_link_args = ['-nostdlib', '-static', '-r']
[host_machine]
system = 'nuttx'
cpu_family = '${1%%-*}'
cpu = '${march}'
EOF
```
]
]
#slide[
= Phase 1.1: Toolchain.cmake
#text(weight: "bold")[`project-apps/meson-apps/crossfile.sh`]
```bash
cat >>crossfile.ini <<-EOF
[properties]
cmake_toolchain_file = '$(pwd)/Toolchain.cmake'
EOF
cat >Toolchain.cmake <<-EOF
add_compile_options($(flags_sanit "$cflags"))
add_link_options(-nostdlib -static -r)
EOF
```
]
#slide[
= Phase 2: context
#text(weight: "bold")[`project-apps/meson-apps/Makefile`]
```make
context:: build/build.ninja
build/build.ninja: crossfile.ini meson-setup.sh
./meson-setup.sh
```
#text(weight: "bold")[`project-apps/meson-apps/meson-setup.sh`]
```bash
meson setup --default-library static -Db_staticpic=false \
--backend ninja --cross-file crossfile.ini build ../..
```
]
#slide[
= Phase 3: build / build.ninja.mk
#text(size: 0.8em)[
#text(weight: "bold")[`project-apps/meson-apps/meson-setup.sh`]
```make
{
meson introspect --targets "build" |
jq -r '.[]
| select((.type == "static library" or .type == "executable") and .installed)
| .name, .filename[0], .type' |
while read -r name && read -r file && read -r type; do
target="${file#"$sdir/build/"}"
if [[ "$type" == "executable" ]]; then
echo "\$(eval \$(call EXECUTABLE,$target,$name,${name//-/_}_main))"
else
echo "\$(eval \$(call STATIC_LIBRARY,$target))"
fi
done
meson introspect --buildsystem-files build | jq -r '.[]' |
sed 's#^#build/build.ninja: #'
} >"build.ninja.mk"
```
]
]
#slide[
= Phase 3.1: built
#text(weight: "bold")[`project-apps/meson-apps/Makefile`]
```make
all:: .built
@
.built: build.ninja.mk $(BUILDS)
touch $@
```
]
#slide[
= Phase 3.2: build NINJA_TARGET
#text(weight: "bold")[`project-apps/meson-apps/Makefile`]
```make
define NINJA_TARGET
.NOTPARALLEL: build/$(1)
build/$(1): build/build.ninja .FORCE
flock build ninja $$(if $$(V),,--quiet) -C build $(1)
endef
```
]
#slide[
= Phase 3.3: build STATIC_LIBRARY
#text(weight: "bold")[`project-apps/meson-apps/Makefile`]
```make
define STATIC_LIBRARY
BUILDS += build/$(1).built
LIBRARIES += build/$(1)
$(call NINJA_TARGET,$(1))
build/$(1).built: build/$(1)
mkdir -p build/$(1).a
$$(UNAR) --output build/$(1).a build/$(1)
cd build/$(1).a && for f in *.o; do mv "$$$$f" "$(subst $(DELIM),.,$(1))_$$f"; done
$$(call ARLOCK, $$(call CONVERT_PATH,$$(BIN)), build/$(1).a/*)
$$(call DELDIR, build/$(1).a)
touch $$@
endef
```
]
#slide[
= Phase 3.4: libsyms
#text(weight: "bold")[`project-apps/meson-apps/Makefile`]
```make
libsyms: $(LIBRARIES)
$(NM) --quiet --just-symbols --defined-only $^ | sort -u > $@
```
]
#slide[
= Phase 3.5: register EXECUTABLE
#text(weight: "bold")[`project-apps/meson-apps/Makefile`]
```make
define EXECUTABLE
register:: $$(BUILTIN_REGISTRY)$$(DELIM)$(2).bdat
$$(BUILTIN_REGISTRY)$$(DELIM)$(2).bdat: build/build.ninja
$$(call REGISTER,$(2),$$(PRIORITY),$$(STACKSIZE),$(3))
endef
```
]
#slide[
= Phase 3.5: build EXECUTABLE
#text(weight: "bold")[`project-apps/meson-apps/Makefile`]
```make
define EXECUTABLE
BUILDS += build/$(1).built
$(call NINJA_TARGET,$(1))
build/$(1).built: build/$(1) libsyms
$$(NM) --quiet --just-symbols --defined-only build/$(1) \
| sort -u | comm -2 - libsyms >build/$(1).syms
$$(OBJCOPY) --redefine-sym main=$(3) \
--localize-symbols=build/$(1).syms \
--weaken-symbols=libsyms \
build/$(1) build/$(1).o
$$(call ARLOCK, $$(call CONVERT_PATH,$$(BIN)), build/$(1).o)
touch $$@
```
]
#slide[
#show: metropolis.focus
Demonstration
]
#slide[
= LTO
With LTO we can't modify symbols.
Workaround: add `-flinker-output=nolto-rel` to `c_link_args`
That removes LTO from linked objects objects (executables).
LTO not applied to calls from executables to libraries and nuttx.\
LTO is still applied to calls between libraries and from libraries to NuttX
]
#slide[
= Conclusion
Demonstrated possibilities:
- How to have project specific applications
- How to use off-tree board
- How to convince meson to build for NuttX
- How to merge meson built files to NuttX
All this without forking NuttX or Meson.
Actual implementation provides resiliency against parameters change compared
to the examples.
]
#slide[
#show: metropolis.focus
Thank you
Karel Kočí
#metropolis.divider
#text(size: 0.6em)[
https://gitlab.com/Cynerd/nuttx-meson-template/-/tree/master
https://gitlab.com/Cynerd/nixos-personal
https://git.cynerd.cz/presentations/tree/2026-communitycvercode
]
]
|