]>
Commit | Line | Data |
---|---|---|
1 | # SPDX-License-Identifier: LGPL-2.1-or-later | |
2 | ||
3 | # Project. | |
4 | project( | |
5 | 'lxcfs', | |
6 | 'c', | |
7 | version: '5.0.0', | |
8 | license: 'LGPLv2+', | |
9 | default_options: [ | |
10 | 'b_colorout=always', | |
11 | 'b_asneeded=true', | |
12 | 'b_pie=true', | |
13 | 'c_std=gnu11', | |
14 | 'warning_level=2', | |
15 | ], | |
16 | meson_version: '>= 0.50') | |
17 | ||
18 | cc = meson.get_compiler('c') | |
19 | ||
20 | # Templater. | |
21 | if run_command( | |
22 | 'python3', '-c', 'import jinja2', | |
23 | check: false).returncode() != 0 | |
24 | error('python3 jinja2 missing') | |
25 | endif | |
26 | ||
27 | meson_build_sh = find_program('tools/meson-build.sh') | |
28 | meson_render_jinja2 = find_program('tools/meson-render-jinja2.py') | |
29 | ||
30 | # Configuration options. | |
31 | conf = configuration_data() | |
32 | conf.set_quoted('PROJECT', meson.project_name()) | |
33 | conf.set_quoted('PROJECT_URL', 'https://linuxcontainers.org/lxcfs/') | |
34 | conf.set_quoted('PROJECT_VERSION', meson.project_version()) | |
35 | conf.set_quoted('PACKAGE_VERSION', meson.project_version()) | |
36 | conf.set('_GNU_SOURCE', true) | |
37 | conf.set('_FILE_OFFSET_BITS', 64) | |
38 | conf.set('__STDC_FORMAT_MACROS', true) | |
39 | ||
40 | project_source_root = meson.current_source_dir() | |
41 | project_build_root = meson.current_build_dir() | |
42 | ||
43 | # Path handling. | |
44 | prefixdir = get_option('prefix') | |
45 | bindir = join_paths(prefixdir, get_option('bindir')) | |
46 | libdir = join_paths(prefixdir, get_option('libdir')) | |
47 | lxcfsdir = join_paths(libdir, 'lxcfs') | |
48 | sysconfdir = join_paths(prefixdir, get_option('sysconfdir')) | |
49 | runtimepath = join_paths(prefixdir, get_option('runtime-path')) | |
50 | localstatedir = join_paths('/', get_option('localstatedir')) | |
51 | datadir = join_paths(prefixdir, get_option('datadir')) | |
52 | ||
53 | lxcfssharedir = join_paths(datadir, 'lxcfs') | |
54 | lxcconfdir = join_paths(datadir, 'lxc/config/common.conf.d') | |
55 | lxcmandir = join_paths(datadir, 'man') | |
56 | ||
57 | conf.set_quoted('BINDIR', bindir) | |
58 | conf.set_quoted('LIBDIR', libdir) | |
59 | conf.set_quoted('LOCALSTATEDIR', localstatedir) | |
60 | conf.set_quoted('RUNTIME_PATH', runtimepath) | |
61 | conf.set_quoted('SYSCONFDIR', sysconfdir) | |
62 | ||
63 | conf.set_quoted('LXCCONFDIR', lxcconfdir) | |
64 | conf.set_quoted('LXCFS_BUILD_ROOT', project_build_root) | |
65 | conf.set_quoted('LXCFSSHAREDIR', lxcfssharedir) | |
66 | conf.set_quoted('LXCFS_SOURCE_ROOT', project_source_root) | |
67 | conf.set_quoted('LXCFSTARGETDIR', join_paths(localstatedir, 'lib/lxcfs')) | |
68 | ||
69 | # Custom configuration. | |
70 | init_script = get_option('init-script') | |
71 | want_tests = get_option('tests') | |
72 | want_docs = get_option('docs') | |
73 | ||
74 | # Build flags. | |
75 | possible_cc_flags = [ | |
76 | '-Wvla', | |
77 | '-Wimplicit-fallthrough=5', | |
78 | '-Wcast-align', | |
79 | '-Wstrict-prototypes', | |
80 | '-fno-strict-aliasing', | |
81 | '-fstack-clash-protection', | |
82 | '-fstack-protector-strong', | |
83 | '--param=ssp-buffer-size=4', | |
84 | '--mcet -fcf-protection', | |
85 | '-Werror=implicit-function-declaration', | |
86 | '-Wlogical-op', | |
87 | '-Wmissing-include-dirs', | |
88 | '-Wold-style-definition', | |
89 | '-Winit-self', | |
90 | '-Wunused-but-set-variable', | |
91 | '-Wno-unused-parameter', | |
92 | '-Wfloat-equal', | |
93 | '-Wsuggest-attribute=noreturn', | |
94 | '-Werror=return-type', | |
95 | '-Werror=incompatible-pointer-types', | |
96 | '-Wformat=2', | |
97 | '-Wshadow', | |
98 | '-Wendif-labels', | |
99 | '-Werror=overflow', | |
100 | '-fdiagnostics-show-option', | |
101 | '-Werror=shift-count-overflow', | |
102 | '-Werror=shift-overflow=2', | |
103 | '-Wdate-time', | |
104 | '-Wnested-externs', | |
105 | '-fasynchronous-unwind-tables', | |
106 | '-fexceptions', | |
107 | '-Warray-bounds', | |
108 | '-Wrestrict', | |
109 | '-Wreturn-local-addr', | |
110 | '-fsanitize=cfi', | |
111 | '-Wstringop-overflow', | |
112 | ] | |
113 | ||
114 | possible_link_flags = [ | |
115 | '-Wl,--gc-sections', | |
116 | '-Wl,-z,relro', | |
117 | '-Wl,-z,now', | |
118 | '-Wl,-fuse-ld=gold', | |
119 | ] | |
120 | ||
121 | if meson.version().version_compare('>=0.46') | |
122 | add_project_link_arguments(cc.get_supported_link_arguments(possible_link_flags), language: 'c') | |
123 | else | |
124 | add_project_link_arguments(possible_link_flags, language: 'c') | |
125 | endif | |
126 | ||
127 | add_project_arguments(cc.get_supported_arguments(possible_cc_flags), language: 'c') | |
128 | ||
129 | # Feature detection. | |
130 | foreach ident: [ | |
131 | ['strlcpy', '''#include <string.h>'''], | |
132 | ['strlcat', '''#include <string.h>'''], | |
133 | ['pidfd_send_signal', | |
134 | '''#include <stdlib.h> | |
135 | #include <unistd.h> | |
136 | #include <signal.h> | |
137 | #include <sys/wait.h>'''], | |
138 | ['pidfd_open', | |
139 | '''#include <stdlib.h> | |
140 | #include <unistd.h> | |
141 | #include <signal.h> | |
142 | #include <sys/wait.h>'''], | |
143 | ] | |
144 | have = cc.has_function(ident[0], prefix: ident[1], args: '-D_GNU_SOURCE') | |
145 | conf.set10('HAVE_' + ident[0].to_upper(), have) | |
146 | endforeach | |
147 | ||
148 | fuse_version = get_option('fuse-version') | |
149 | if fuse_version == '3' or fuse_version == 'auto' | |
150 | libfuse = dependency('fuse3', required: false) | |
151 | if libfuse.found() | |
152 | conf.set10('HAVE_FUSE3', true) | |
153 | conf.set('FUSE_USE_VERSION', 35) | |
154 | if libfuse.version().version_compare('>=3.10.3') | |
155 | conf.set10('HAVE_FUSE_RETURNS_DT_TYPE', true) | |
156 | else | |
157 | conf.set10('HAVE_FUSE_RETURNS_DT_TYPE', false) | |
158 | endif | |
159 | endif | |
160 | endif | |
161 | ||
162 | if fuse_version == '2' or (not libfuse.found() and fuse_version == 'auto') | |
163 | libfuse = dependency('fuse', version: '>= 2.6') | |
164 | if libfuse.found() | |
165 | conf.set10('HAVE_FUSE', true) | |
166 | conf.set('FUSE_USE_VERSION', 26) | |
167 | conf.set10('HAVE_FUSE_RETURNS_DT_TYPE', true) | |
168 | endif | |
169 | endif | |
170 | ||
171 | if not libfuse.found() | |
172 | error('no usable fuse version found') | |
173 | endif | |
174 | ||
175 | libdl = cc.find_library('dl') | |
176 | threads = dependency('threads') | |
177 | ||
178 | config_h = configure_file( | |
179 | output: 'config.h', | |
180 | configuration: conf) | |
181 | config_include = include_directories('.') | |
182 | add_project_arguments('-include', 'config.h', language: 'c') | |
183 | ||
184 | # Binary. | |
185 | lxcfs_sources = files('src/lxcfs.c') | |
186 | lxcfs = executable( | |
187 | 'lxcfs', | |
188 | lxcfs_sources, | |
189 | dependencies: [ | |
190 | threads, | |
191 | libdl, | |
192 | libfuse, | |
193 | ], | |
194 | install: true, | |
195 | install_dir: bindir) | |
196 | ||
197 | # Library. | |
198 | liblxcfs_sources = files( | |
199 | 'src/api_extensions.h', | |
200 | 'src/bindings.c', | |
201 | 'src/bindings.h', | |
202 | 'src/cgroups/cgfsng.c', | |
203 | 'src/cgroups/cgroup.c', | |
204 | 'src/cgroups/cgroup.h', | |
205 | 'src/cgroups/cgroup2_devices.c', | |
206 | 'src/cgroups/cgroup2_devices.h', | |
207 | 'src/cgroups/cgroup_utils.c', | |
208 | 'src/cgroups/cgroup_utils.h', | |
209 | 'src/cgroup_fuse.c', | |
210 | 'src/cgroup_fuse.h', | |
211 | 'src/cpuset_parse.c', | |
212 | 'src/cpuset_parse.h', | |
213 | 'src/lxcfs.c', | |
214 | 'src/lxcfs_fuse.h', | |
215 | 'src/lxcfs_fuse_compat.h', | |
216 | 'src/macro.h', | |
217 | 'src/memory_utils.h', | |
218 | 'src/proc_cpuview.c', | |
219 | 'src/proc_cpuview.h', | |
220 | 'src/proc_fuse.c', | |
221 | 'src/proc_fuse.h', | |
222 | 'src/proc_loadavg.c', | |
223 | 'src/proc_loadavg.h', | |
224 | 'src/syscall_numbers.h', | |
225 | 'src/sysfs_fuse.c', | |
226 | 'src/sysfs_fuse.h', | |
227 | 'src/utils.c', | |
228 | 'src/utils.h') | |
229 | ||
230 | liblxcfs_common_dependencies = declare_dependency( | |
231 | sources: liblxcfs_sources, | |
232 | dependencies: [ | |
233 | threads, | |
234 | libfuse, | |
235 | ]) | |
236 | ||
237 | liblxcfs = shared_module( | |
238 | 'lxcfs', | |
239 | liblxcfs_sources, | |
240 | dependencies: liblxcfs_common_dependencies, | |
241 | install: true, | |
242 | install_dir: lxcfsdir) | |
243 | ||
244 | # Tests. | |
245 | test_programs = [] | |
246 | if want_tests == true | |
247 | liblxcfs_test = shared_module( | |
248 | 'lxcfstest', | |
249 | liblxcfs_sources, | |
250 | dependencies: liblxcfs_common_dependencies, | |
251 | install: false, | |
252 | install_dir: lxcfsdir, | |
253 | c_args: '-DRELOADTEST -DDEBUG') | |
254 | endif | |
255 | ||
256 | # RPM spec. | |
257 | lxcfs_spec = custom_target( | |
258 | 'lxcfs.spec', | |
259 | build_by_default: true, | |
260 | input: 'lxcfs.spec.in', | |
261 | output: 'lxcfs.spec', | |
262 | command: [ | |
263 | meson_render_jinja2, | |
264 | config_h, | |
265 | '@INPUT@', | |
266 | '@OUTPUT@', | |
267 | ]) | |
268 | ||
269 | # Man pages | |
270 | if want_docs == true | |
271 | help2man = find_program('help2man') | |
272 | help2man_opts = [ | |
273 | '--name="System virtualization filesystem for containers"', | |
274 | '--no-discard-stderr', | |
275 | '--section=1', | |
276 | '--opt-include=docs/lxcfs.man.add', | |
277 | '--no-info', | |
278 | ] | |
279 | custom_target('lxcfs.1', | |
280 | output: 'lxcfs.1', | |
281 | command: [help2man, help2man_opts, '--output=@OUTPUT@', lxcfs], | |
282 | install: true, | |
283 | install_dir: join_paths(lxcmandir, 'man1')) | |
284 | endif | |
285 | ||
286 | ||
287 | # Include sub-directories. | |
288 | subdir('config/init') | |
289 | subdir('share') | |
290 | subdir('tests') | |
291 | ||
292 | # Build overview. | |
293 | status = [ | |
294 | '@0@ @1@'.format(meson.project_name(), meson.project_version()), | |
295 | ||
296 | 'FUSE version: @0@'.format(libfuse.version()), | |
297 | 'bin directory: @0@'.format(bindir), | |
298 | 'lib directory: @0@'.format(libdir), | |
299 | 'data directory: @0@'.format(datadir), | |
300 | 'local state directory: @0@'.format(localstatedir), | |
301 | 'prefix directory: @0@'.format(prefixdir), | |
302 | 'runtime directory: @0@'.format(runtimepath), | |
303 | 'sysconf directory: @0@'.format(sysconfdir), | |
304 | 'lxc conf directory: @0@'.format(lxcconfdir), | |
305 | 'lxcfs directory: @0@'.format(lxcfsdir), | |
306 | 'lxcfs shared directory: @0@'.format(lxcfssharedir), | |
307 | 'lxcfs build root directory: @0@'.format(project_build_root), | |
308 | 'lxcfs source root directory: @0@'.format(project_source_root), | |
309 | 'init system(s): @0@'.format(init_script), | |
310 | 'tests: @0@'.format(want_tests), | |
311 | 'documentation: @0@'.format(want_docs), | |
312 | ] | |
313 | message('\n '.join(status)) |