1commit a881a5b110d2f23a11924604bff64ab3c2755bc6
2Author: Brandon Maier <brandon.maier@gmail.com>
3Date: Thu Mar 6 20:30:47 2025 -0600
4
5 meson: support building libfdt without static library
6
7 Some packaging systems like NixOS don't support compiling static
8 libraries. However libfdt's meson.build uses `both_library()` which
9 forces the build to always compile shared and static libraries. Removing
10 `both_library()` will make packaging easier.
11
12 libfdt uses `both_libraries()` to support the 'static-build' option.
13 But we do not need the 'static-build' option as Meson can natively
14 build static using
15
16 > meson setup builddir/ -Dc_link_args='-static' --prefer-static --default-library=static
17
18 So drop 'static-build' and then replace `both_libraries()` with
19 `library()`.
20
21 Signed-off-by: Brandon Maier <brandon.maier@gmail.com>
22 Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
23
24diff --git a/libfdt/meson.build b/libfdt/meson.build
25index bf8343f..c2f4bd6 100644
26--- a/libfdt/meson.build
27+++ b/libfdt/meson.build
28@@ -26,7 +26,7 @@ else
29 endif
30
31 link_args += version_script
32-libfdt = both_libraries(
33+libfdt = library(
34 'fdt', sources,
35 version: meson.project_version(),
36 link_args: link_args,
37@@ -34,17 +34,11 @@ libfdt = both_libraries(
38 install: true,
39 )
40
41-if static_build
42- link_with = libfdt.get_static_lib()
43-else
44- link_with = libfdt.get_shared_lib()
45-endif
46-
47 libfdt_inc = include_directories('.')
48
49 libfdt_dep = declare_dependency(
50 include_directories: libfdt_inc,
51- link_with: link_with,
52+ link_with: libfdt,
53 )
54
55 install_headers(
56diff --git a/meson.build b/meson.build
57index 310699f..603ffaa 100644
58--- a/meson.build
59+++ b/meson.build
60@@ -1,7 +1,7 @@
61 project('dtc', 'c',
62 version: files('VERSION.txt'),
63 license: ['GPL2+', 'BSD-2'],
64- default_options: 'werror=true',
65+ default_options: ['werror=true', 'default_library=both'],
66 meson_version: '>=0.57.0'
67 )
68
69@@ -27,16 +27,8 @@ add_project_arguments(
70 language: 'c'
71 )
72
73-if get_option('static-build')
74- static_build = true
75- extra_link_args = ['-static']
76-else
77- static_build = false
78- extra_link_args = []
79-endif
80-
81 yamltree = 'yamltree.c'
82-yaml = dependency('yaml-0.1', version: '>=0.2.3', required: get_option('yaml'), static: static_build)
83+yaml = dependency('yaml-0.1', version: '>=0.2.3', required: get_option('yaml'))
84 if not yaml.found()
85 add_project_arguments('-DNO_YAML', language: 'c')
86 yamltree = []
87@@ -92,7 +84,6 @@ if get_option('tools')
88 ],
89 dependencies: util_dep,
90 install: true,
91- link_args: extra_link_args,
92 )
93 endif
94
95@@ -113,11 +104,10 @@ if get_option('tools')
96 ],
97 dependencies: [util_dep, yaml],
98 install: true,
99- link_args: extra_link_args,
100 )
101
102 foreach e: ['fdtdump', 'fdtget', 'fdtput', 'fdtoverlay']
103- dtc_tools += executable(e, files(e + '.c'), dependencies: util_dep, install: true, link_args: extra_link_args)
104+ dtc_tools += executable(e, files(e + '.c'), dependencies: util_dep, install: true)
105 endforeach
106
107 install_data(
108diff --git a/meson_options.txt b/meson_options.txt
109index 36f391a..62b31b3 100644
110--- a/meson_options.txt
111+++ b/meson_options.txt
112@@ -8,7 +8,5 @@ option('valgrind', type: 'feature', value: 'auto',
113 description: 'Valgrind support')
114 option('python', type: 'feature', value: 'auto',
115 description: 'Build pylibfdt Python library')
116-option('static-build', type: 'boolean', value: false,
117- description: 'Build static binaries')
118 option('tests', type: 'boolean', value: true,
119 description: 'Build tests')
120diff --git a/tests/meson.build b/tests/meson.build
121index 9cf6e3d..baed174 100644
122--- a/tests/meson.build
123+++ b/tests/meson.build
124@@ -96,22 +96,20 @@ tests += [
125 'truncated_string',
126 ]
127
128+test_deps = [testutil_dep, util_dep, libfdt_dep]
129+
130 dl = cc.find_library('dl', required: false)
131-if dl.found() and not static_build
132+if dl.found()
133 tests += [
134 'asm_tree_dump',
135 'value-labels',
136 ]
137-endif
138-
139-test_deps = [testutil_dep, util_dep, libfdt_dep]
140-if not static_build
141 test_deps += [dl]
142 endif
143
144 tests_exe = []
145 foreach t: tests
146- tests_exe += executable(t, files(t + '.c'), dependencies: test_deps, link_args: extra_link_args)
147+ tests_exe += executable(t, files(t + '.c'), dependencies: test_deps)
148 endforeach
149
150 run_tests = find_program('run_tests.sh')