meson: add option to build debugcc as a dynamically linked binary

debugcc is currently linked statically using -static and -static-libgcc.
This can cause issues for distributions that prefer dynamically linked
binaries (e.g. larger binaries and duplicated runtime code which could
otherwise be shared).

Add a Meson boolean option `dynamic-linking` which when enabled removes
the explicit static link flags so that debugcc is built as a dynamically
linked binary using the default toolchain behaviour. The default for this
option is false so that existing builds continue to get a statically
linked binary unless they opt in to dynamic linking.

Signed-off-by: Christopher Obbard <christopher.obbard@linaro.org>
This commit is contained in:
Christopher Obbard
2025-11-24 22:28:12 +00:00
parent a01ea9eeb9
commit 73b135d125
2 changed files with 11 additions and 1 deletions

View File

@@ -59,7 +59,12 @@ debugcc_srcs += configure_file(
output: 'platforms.c',
configuration: platforms)
debugcc_link_args = []
if not get_option('dynamic-linking')
debugcc_link_args += ['-static', '-static-libgcc']
endif
executable('debugcc',
debugcc_srcs,
link_args: ['-static','-static-libgcc'],
link_args: debugcc_link_args,
install: true)

5
meson_options.txt Normal file
View File

@@ -0,0 +1,5 @@
option('dynamic-linking',
type: 'boolean',
value: false,
description: 'Build debugcc as a dynamically linked binary instead of static',
)