]> git.proxmox.com Git - mirror_lxc.git/blob - meson.build
add check for statvfs
[mirror_lxc.git] / meson.build
1 # SPDX-License-Identifier: LGPL-2.1-or-later
2
3 # Project.
4 project(
5 'lxc',
6 'c',
7 version: '5.0.0',
8 license: 'LGPLv2+',
9 default_options: [
10 'b_lto=true',
11 'b_lto_mode=thin',
12 'b_colorout=always',
13 'b_asneeded=true',
14 'b_pie=true',
15 'b_staticpic=true',
16 'c_std=gnu11',
17 'warning_level=2',
18 ],
19 meson_version: '>= 0.61')
20
21 cc = meson.get_compiler('c')
22 pkgconfig = import('pkgconfig')
23 pkgconfig_libs = []
24
25 # Version.
26 liblxc_version = '1.7.0'
27 version_data = configuration_data()
28 version_data.set('LXC_VERSION_MAJOR', '5')
29 version_data.set('LXC_VERSION_MINOR', '0')
30 version_data.set('LXC_VERSION_MICRO', '0')
31 version_data.set('LXC_VERSION_BETA', '')
32 version_data.set('LXC_ABI', liblxc_version)
33 version_data.set('LXC_DEVEL', '1')
34 version_data.set('LXC_VERSION', meson.project_version())
35
36 # Path handling.
37 project_source_root = meson.current_source_dir()
38 project_build_root = meson.current_build_dir()
39 prefixdir = get_option('prefix')
40
41 apparmorcachedir = get_option('apparmor-cache-path')
42 globalconfig = get_option('global-config-path')
43 localstatedir = join_paths('/', get_option('localstatedir'))
44 logpath = get_option('log-path')
45 lxcpathprefix = get_option('data-path')
46 rootfsmount = get_option('rootfs-mount-path')
47 user_network_db_opt = get_option('usernet-db-path')
48 user_network_conf_opt = get_option('usernet-config-path')
49
50 bashcompletiondir = join_paths('/', 'usr', 'share', 'bash-completion', 'completions')
51 bindir = join_paths(prefixdir, get_option('bindir'))
52 datadir = join_paths(prefixdir, get_option('datadir'))
53 mandir = join_paths(prefixdir, get_option('mandir'))
54 docdir = join_paths(datadir, get_option('doc-path'))
55 includedir = join_paths(prefixdir, get_option('includedir'))
56 libdir = join_paths(prefixdir, get_option('libdir'))
57 libexecdir = join_paths(prefixdir, get_option('libexecdir'))
58 runtimepath = join_paths(prefixdir, get_option('runtime-path'))
59 sbindir = join_paths(prefixdir, get_option('sbindir'))
60 sysconfdir = join_paths(prefixdir, get_option('sysconfdir'))
61
62 lxcapparmorcachedir = join_paths(localstatedir, apparmorcachedir)
63 lxcconfdir = join_paths(sysconfdir, globalconfig)
64 lxcdefaultconfig = join_paths(lxcconfdir, 'default.conf')
65 lxcglobalconfig = join_paths(lxcconfdir, 'lxc.conf')
66 lxcexamplesdir = join_paths(docdir, 'examples')
67 lxchookbindir = join_paths(libexecdir, 'lxc/hooks')
68 lxcinclude = join_paths(includedir, 'lxc')
69 lxclibexec = join_paths(libexecdir, 'lxc')
70 lxclogpath = join_paths(localstatedir, logpath)
71 lxcpath = join_paths(localstatedir, lxcpathprefix)
72 lxcrootfsmount = join_paths(libdir, rootfsmount)
73 lxcdatadir = join_paths(datadir, 'lxc')
74 lxchookdir = join_paths(lxcdatadir, 'hooks')
75 lxcselinuxdir = join_paths(lxcdatadir, 'selinux')
76 lxctemplateconfdir = join_paths(lxcdatadir, 'config')
77 lxctemplateconfcommondir = join_paths(lxctemplateconfdir, 'common.conf.d')
78 lxctemplatedir = join_paths(lxcdatadir, 'templates')
79 lxc_user_network_conf = join_paths(sysconfdir, user_network_conf_opt)
80 lxc_user_network_db = join_paths(runtimepath, user_network_db_opt)
81 pam_security = join_paths(libdir, 'security')
82
83 # Configuration options.
84 srcconf = configuration_data()
85 srcconf.set('_GNU_SOURCE', true)
86 srcconf.set('_FILE_OFFSET_BITS', 64)
87 srcconf.set('__STDC_FORMAT_MACROS', true)
88 srcconf.set_quoted('APPARMOR_CACHE_DIR', lxcapparmorcachedir)
89 srcconf.set_quoted('LIBEXECDIR', libexecdir)
90 srcconf.set_quoted('LOGPATH', lxclogpath)
91 srcconf.set_quoted('LXC_DEFAULT_CONFIG', lxcdefaultconfig)
92 srcconf.set_quoted('LXC_GLOBAL_CONF', lxcglobalconfig)
93 srcconf.set_quoted('LXCINITDIR', libexecdir)
94 srcconf.set_quoted('LXCPATH', lxcpath)
95 srcconf.set_quoted('LXCROOTFSMOUNT', lxcrootfsmount)
96 srcconf.set_quoted('LXCTEMPLATECONFIG', lxctemplateconfdir)
97 srcconf.set_quoted('LXCTEMPLATECONFIG', lxctemplateconfdir)
98 srcconf.set_quoted('LXCTEMPLATEDIR', lxctemplatedir)
99 srcconf.set_quoted('LXC_USERNIC_CONF', lxc_user_network_conf)
100 srcconf.set_quoted('LXC_USERNIC_DB', lxc_user_network_db)
101 srcconf.set_quoted('RUNTIME_PATH', runtimepath)
102 srcconf.set_quoted('SBINDIR', sbindir)
103
104 conf = configuration_data()
105 conf.set('BINDIR', bindir)
106 conf.set('LIBEXECDIR', libexecdir)
107 conf.set('LOCALSTATEDIR', localstatedir)
108 conf.set('LXC_GLOBAL_CONF', lxcglobalconfig)
109 conf.set('LXCHOOKDIR', lxchookdir)
110 conf.set('LXCINITDIR', libexecdir)
111 conf.set('LXCROOTFSMOUNT', lxcrootfsmount)
112 conf.set('LXCTEMPLATECONFIG', lxctemplateconfdir)
113 conf.set('LXCTEMPLATEDIR', lxctemplatedir)
114 conf.set('PACKAGE_VERSION', meson.project_version())
115 conf.set('RUNTIME_PATH', runtimepath)
116 conf.set('SYSCONFDIR', sysconfdir)
117
118 # Set sysconfdir
119 fs = import('fs')
120 if fs.is_dir('/etc/sysconfig')
121 distrosysconfdir = join_paths(sysconfdir, 'sysconfig')
122 conf.set('LXC_DISTRO_SYSCONF', distrosysconfdir)
123 elif fs.is_dir('/etc/default')
124 distrosysconfdir = join_paths(sysconfdir, 'default')
125 conf.set('LXC_DISTRO_SYSCONF', distrosysconfdir)
126 else
127 distrosysconfdir = ''
128 endif
129
130 # Cross-compile on Android.
131 srcconf.set10('IS_BIONIC', host_machine.system() == 'android')
132
133 # Custom configuration.
134 cgrouppattern = get_option('cgroup-pattern')
135 coverity = get_option('coverity-build')
136 init_script = get_option('init-script')
137 sanitize = get_option('b_sanitize')
138 want_examples = get_option('examples')
139 want_io_uring = get_option('io-uring-event-loop')
140 want_pam_cgroup = get_option('pam-cgroup')
141 want_mans = get_option('man')
142 want_tests = get_option('tests')
143 want_tools = get_option('tools')
144 want_tools_multicall = get_option('tools-multicall')
145 want_commands = get_option('commands')
146 want_capabilities = get_option('capabilities')
147 want_apparmor = get_option('apparmor')
148 want_openssl = get_option('openssl')
149 want_selinux = get_option('selinux')
150 want_oss_fuzz = get_option('oss-fuzz')
151 want_seccomp = get_option('seccomp')
152 want_thread_safety = get_option('thread-safety')
153 want_memfd_rexec = get_option('memfd-rexec')
154 want_sd_bus = get_option('sd-bus')
155
156 srcconf.set_quoted('DEFAULT_CGROUP_PATTERN', cgrouppattern)
157 if coverity
158 srcconf.set('ENABLE_COVERITY_BUILD', 1)
159 endif
160
161 dummy_config_data = configuration_data()
162 dummy_config_data.set_quoted('DUMMY_VARIABLE', '1')
163
164 # Those generate many false positives, and we do not want to change the code to
165 # avoid them.
166 basic_disabled_warnings = [
167 '-Wno-format-signedness',
168 '-Wno-missing-field-initializers',
169 '-Wno-unused-parameter',
170 ]
171
172 # Build flags.
173 possible_cc_flags = [
174 '-Wvla',
175 '-Wimplicit-fallthrough=5',
176 '-Wcast-align',
177 '-Wstrict-prototypes',
178 '-fno-strict-aliasing',
179 '-fstack-clash-protection',
180 '-fstack-protector-strong',
181 '--param=ssp-buffer-size=4',
182 '--mcet -fcf-protection',
183 '-Werror=implicit-function-declaration',
184 '-Wlogical-op',
185 '-Wmissing-include-dirs',
186 '-Wold-style-definition',
187 '-Winit-self',
188 '-Wunused-but-set-variable',
189 '-Wno-unused-parameter',
190 '-Wfloat-equal',
191 '-Wsuggest-attribute=noreturn',
192 '-Werror=return-type',
193 '-Werror=incompatible-pointer-types',
194 '-Wformat=2',
195 '-Wshadow',
196 '-Wendif-labels',
197 '-Werror=overflow',
198 '-fdiagnostics-show-option',
199 '-Werror=shift-count-overflow',
200 '-Werror=shift-overflow=2',
201 '-Wdate-time',
202 '-Wnested-externs',
203 '-fasynchronous-unwind-tables',
204 '-fexceptions',
205 '-Warray-bounds',
206 '-Wrestrict',
207 '-Wreturn-local-addr',
208 '-fsanitize=cfi',
209 '-Wstringop-overflow',
210 ]
211
212 possible_link_flags = [
213 '-Wl,--gc-sections',
214 '-Wl,-z,relro',
215 '-Wl,-z,now',
216 '-Wl,-fuse-ld=gold',
217 '-fstack-protector',
218 ]
219
220 if sanitize == 'none'
221 possible_link_flags += '-Wl,--warn-common'
222 endif
223
224 if cc.get_id() == 'clang'
225 possible_cc_flags += [
226 '-Wno-typedef-redefinition',
227 '-Wno-gnu-variable-sized-type-not-at-end',
228 ]
229 endif
230
231 if meson.version().version_compare('>=0.46')
232 add_project_link_arguments(cc.get_supported_link_arguments(possible_link_flags), language: 'c')
233 else
234 add_project_link_arguments(possible_link_flags, language: 'c')
235 endif
236
237 add_project_arguments(cc.get_supported_arguments(basic_disabled_warnings), language : 'c')
238 add_project_arguments(cc.get_supported_arguments(possible_cc_flags), language: 'c')
239
240 if add_languages('cpp', required : want_oss_fuzz)
241 # Used only for tests
242 cxx = meson.get_compiler('cpp')
243 cxx_cmd = ' '.join(cxx.cmd_array())
244 add_project_arguments(cxx.get_supported_arguments(basic_disabled_warnings), language : 'cpp')
245 endif
246
247 # Feature detection
248 ## I/O uring.
249 if want_io_uring
250 liburing = dependency('liburing')
251 if cc.has_function('io_uring_prep_poll_add', prefix: '#include <liburing.h>', dependencies: liburing) == false
252 error('liburing version does not support IORING_POLL_ADD_MULTI')
253 endif
254
255 srcconf.set10('HAVE_LIBURING', true)
256 else
257 srcconf.set10('HAVE_LIBURING', false)
258 endif
259
260 if not want_sd_bus.disabled()
261 has_sd_bus = true
262 sd_bus_optional = want_sd_bus.auto()
263
264 libsystemd = dependency('libsystemd', required: not sd_bus_optional)
265 if not libsystemd.found()
266 if not sd_bus_optional
267 error('missing required libsystemd dependency')
268 endif
269
270 has_sd_bus = false
271 endif
272
273 if not cc.has_header('systemd/sd-bus.h')
274 if not sd_bus_optional
275 error('libsystemd misses required systemd/sd-bus.h header')
276 endif
277
278 has_sd_bus = false
279 endif
280
281 if not cc.has_header('systemd/sd-event.h')
282 if not sd_bus_optional
283 error('libsystemd misses required systemd/sd-event.h header')
284 endif
285
286 has_sd_bus = false
287 endif
288
289 if not cc.has_function('sd_bus_call_method_asyncv', prefix: '#include <systemd/sd-bus.h>', dependencies: libsystemd)
290 if not sd_bus_optional
291 error('libsystemd misses required sd_bus_call_method_asyncv function')
292 endif
293
294 has_sd_bus = false
295 endif
296
297 srcconf.set10('HAVE_LIBSYSTEMD', has_sd_bus)
298 else
299 has_sd_bus = false
300 srcconf.set10('HAVE_LIBSYSTEMD', false)
301 endif
302
303 ## Time EPOCH.
304 sh = find_program('sh')
305 date = find_program('date')
306 git = find_program('git', required: false)
307 time_epoch = run_command(sh, '-c', 'echo "$SOURCE_DATE_EPOCH"', check: true).stdout().strip()
308 if time_epoch == '' and git.found() and run_command('test', '-e', '.git', check: false).returncode() == 0
309 # If we're in a git repository, use the creation time of the latest git tag.
310 latest_tag = run_command(git, 'describe', '--abbrev=0', '--tags', check: false).stdout().strip()
311 if latest_tag != ''
312 time_epoch = run_command(git, 'log', '--no-show-signature', '-1', '--format=%at', latest_tag, check: true).stdout()
313 endif
314 endif
315
316 # Fallback to current epoch.
317 if time_epoch == ''
318 time_epoch = run_command(date, '+%s', check: true).stdout()
319 endif
320 generate_date = run_command(date, '--utc', '--date=@' + time_epoch, '+%Y-%m-%d', check: true).stdout().strip()
321
322 ## Manpages.
323 sgml2man = find_program('docbook2X2man', 'docbook2x-man', 'db2x_docbook2man', 'docbook2man', 'docbook-to-man', required: want_mans)
324 docbook2man = find_program('docbook2man', required: false)
325
326 docconf = configuration_data()
327 docconf.set('builddir', '.')
328 docconf.set('BINDIR', bindir)
329 docconf.set('DATADIR', datadir)
330 docconf.set('DOCDIR', docdir)
331 docconf.set('LOGPATH', lxclogpath)
332 docconf.set('LXC_DEFAULT_CONFIG', lxcdefaultconfig)
333 docconf.set('LXC_GENERATE_DATE', generate_date)
334 docconf.set('LXC_GLOBAL_CONF', lxcglobalconfig)
335 docconf.set('LXCPATH', lxcpath)
336 docconf.set('LXCTEMPLATEDIR', lxctemplatedir)
337 docconf.set('LXC_USERNIC_CONF', lxc_user_network_conf)
338 docconf.set('LXC_USERNIC_DB', lxc_user_network_db)
339 docconf.set('PACKAGE_VERSION', version_data.get('LXC_VERSION'))
340 if sgml2man.found() and docbook2man.found() and sgml2man.full_path() == docbook2man.full_path()
341 docconf.set('docdtd', '"-//Davenport//DTD DocBook V3.0//EN"')
342 else
343 docconf.set('docdtd', '"-//OASIS//DTD DocBook XML" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd"')
344 endif
345
346 ## Threads.
347 threads = dependency('threads')
348
349 ## Seccomp.
350 if want_seccomp
351 libseccomp = dependency('libseccomp', required: false)
352 srcconf.set10('HAVE_SECCOMP', libseccomp.found())
353 pkgconfig_libs += libseccomp
354 if libseccomp.found()
355 if libseccomp.version().version_compare('>=2.5.0')
356 # https://github.com/seccomp/libseccomp/commit/dead12bc788b259b148cc4d93b970ef0bd602b1a
357 srcconf.set10('HAVE_DECL_SECCOMP_NOTIFY_FD', true)
358 else
359 srcconf.set10('HAVE_DECL_SECCOMP_NOTIFY_FD', false)
360 endif
361
362 if libseccomp.version().version_compare('>=2.0.0')
363 # https://github.com/seccomp/libseccomp/commit/6220c8c0fc479d97b6d3e3166a4e46fbfe25a3c0
364 srcconf.set10('HAVE_DECL_SECCOMP_SYSCALL_RESOLVE_NAME_ARCH', true)
365 else
366 srcconf.set10('HAVE_DECL_SECCOMP_SYSCALL_RESOLVE_NAME_ARCH', false)
367 endif
368
369 seccomp_headers = '''
370 #include <seccomp.h>
371 '''
372
373 foreach decl: [
374 'scmp_filter_ctx',
375 'struct seccomp_notif_sizes',
376 'struct clone_args',
377 ]
378
379 # We get -1 if the size cannot be determined
380 if cc.sizeof(decl, prefix: seccomp_headers, args: '-D_GNU_SOURCE') > 0
381 srcconf.set10('HAVE_' + decl.underscorify().to_upper(), true)
382 else
383 srcconf.set10('HAVE_' + decl.underscorify().to_upper(), false)
384 endif
385 endforeach
386 endif
387 else
388 srcconf.set10('HAVE_SECCOMP', false)
389 endif
390
391 ## SELinux.
392 if want_selinux
393 libselinux = dependency('libselinux', required: false)
394 srcconf.set10('HAVE_SELINUX', libselinux.found())
395 pkgconfig_libs += libselinux
396 else
397 srcconf.set10('HAVE_SELINUX', false)
398 endif
399
400 ## AppArmor.
401 if want_apparmor
402 libapparmor = dependency('libapparmor', required: false)
403 srcconf.set10('HAVE_APPARMOR', libapparmor.found())
404 else
405 srcconf.set10('HAVE_APPARMOR', false)
406 endif
407
408 ## OpenSSL.
409 if want_openssl
410 libopenssl = dependency('openssl', required: false)
411 srcconf.set10('HAVE_OPENSSL', libopenssl.found())
412 pkgconfig_libs += libopenssl
413 else
414 srcconf.set10('HAVE_OPENSSL', false)
415 endif
416
417 ## Libcap..
418 if want_capabilities
419 libcap = dependency('libcap', required: false)
420 if not libcap.found()
421 # Compat with Ubuntu 14.04 which ships libcap w/o .pc file
422 libcap = cc.find_library('cap', required: false)
423 endif
424 srcconf.set10('HAVE_LIBCAP', libcap.found())
425 pkgconfig_libs += libcap
426
427 libcap_static = dependency('libcap', required: false, static: true)
428 if not libcap_static.found()
429 # Compat with Ubuntu 14.04 which ships libcap w/o .pc file
430 libcap_static = cc.find_library('cap', required: false, static: true)
431 endif
432
433 code = '''
434 int main(int argc, char *argv[]) { return 0; };
435 '''
436 if libcap_static.found()
437 libcap_static_linkable = cc.links(code, args: '-static', dependencies: libcap_static)
438 srcconf.set10('HAVE_STATIC_LIBCAP', libcap_static_linkable)
439 else
440 srcconf.set10('HAVE_STATIC_LIBCAP', false)
441 endif
442 else
443 srcconf.set10('HAVE_LIBCAP', false)
444 srcconf.set10('HAVE_STATIC_LIBCAP', false)
445 endif
446
447 if want_oss_fuzz
448 srcconf.set10('FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION', true)
449 srcconf.set10('RUN_ON_OSS_FUZZ', true)
450 fuzzing_engine = meson.get_compiler('cpp').find_library('FuzzingEngine')
451 endif
452
453 srcconf.set10('ENFORCE_THREAD_SAFETY', want_thread_safety)
454 srcconf.set10('ENFORCE_MEMFD_REXEC', want_memfd_rexec)
455
456 ## PAM.
457 pam = cc.find_library('pam', has_headers: 'security/pam_modules.h', required: want_pam_cgroup)
458 srcconf.set10('HAVE_PAM', pam.found())
459 pkgconfig_libs += pam
460
461 ## Others.
462 have = cc.has_function('strchrnul', prefix: '#include <string.h>', args: '-D_GNU_SOURCE')
463 srcconf.set10('HAVE_STRCHRNUL', have)
464
465 have = cc.has_function('openpty', prefix: '#include <pty.h>', args: '-D_GNU_SOURCE')
466 srcconf.set10('HAVE_OPENPTY', have)
467
468 have_func_strerror_r = cc.has_function('strerror_r', prefix: '#include <string.h>', args: '-D_GNU_SOURCE')
469 srcconf.set10('HAVE_STRERROR_R', have_func_strerror_r)
470
471 have_func_strerror_r_char_p = false
472
473 if have_func_strerror_r
474 code = '''
475 #define _GNU_SOURCE
476 #include <string.h>
477 int func (void) {
478 char error_string[256];
479 char *ptr = strerror_r (-2, error_string, 256);
480 char c = *strerror_r (-2, error_string, 256);
481 return c != 0 && ptr != (void*) 0L;
482 }
483 '''
484
485 have_func_strerror_r_char_p = cc.compiles(code, name : 'strerror_r() returns char *')
486 endif
487
488 srcconf.set10('STRERROR_R_CHAR_P', have_func_strerror_r_char_p)
489
490 ## Compiler attributes.
491 foreach ccattr: [
492 'fallthrough',
493 'nonnull',
494 'returns_nonnull',
495 ]
496
497 srcconf.set10('HAVE_COMPILER_ATTR_' + ccattr.underscorify().to_upper(), cc.has_function_attribute(ccattr))
498 endforeach
499
500 ## Syscalls.
501 found_syscalls = []
502 missing_syscalls = []
503 foreach tuple: [
504 ['bpf'],
505 ['close_range'],
506 ['endmntent'],
507 ['execveat'],
508 ['faccessat'],
509 ['strchrnul'],
510 ['strerror_r'],
511 ['fgetln'],
512 ['fsconfig'],
513 ['fsmount'],
514 ['fsopen'],
515 ['fspick'],
516 ['getgrgid_r'],
517 ['getline'],
518 ['getsubopt'],
519 ['gettid'],
520 ['hasmntopt'],
521 ['kcmp'],
522 ['keyctl'],
523 ['memfd_create'],
524 ['mount_setattr'],
525 ['move_mount'],
526 ['openat2'],
527 ['open_tree'],
528 ['personality'],
529 ['pidfd_open'],
530 ['pidfd_send_signal'],
531 ['pivot_root'],
532 ['prlimit'],
533 ['prlimit64'],
534 ['renameat2'],
535 ['sethostname'],
536 ['setmntent'],
537 ['setns'],
538 ['sigdescr_np'],
539 ['signalfd'],
540 ['statx'],
541 ['statvfs'],
542 ['strlcat'],
543 ['strlcpy'],
544 ['unshare'],
545 ]
546
547 if tuple.length() >= 2
548 cond = tuple[1]
549 else
550 ident1 = 'HAVE_' + tuple[0].underscorify().to_upper()
551 ident2 = 'ENABLE_' + tuple[0].underscorify().to_upper()
552 cond = srcconf.get(ident1, 0) == 1 or srcconf.get(ident2, 0) == 1
553 endif
554
555 if cond
556 found_syscalls += tuple[0]
557 else
558 missing_syscalls += tuple[0]
559 endif
560 endforeach
561
562 ## Types.
563 decl_headers = '''
564 #include <uchar.h>
565 #include <sys/mount.h>
566 #include <sys/stat.h>
567 #include <linux/fs.h>
568 #include <linux/types.h>
569 #include <linux/openat2.h>
570 #include <linux/sched.h>
571 '''
572
573 foreach decl: [
574 '__aligned_u64',
575 'struct mount_attr',
576 'struct open_how',
577 'struct clone_args',
578 ]
579
580 # We get -1 if the size cannot be determined
581 if cc.sizeof(decl, prefix: decl_headers, args: '-D_GNU_SOURCE') > 0
582 srcconf.set10('HAVE_' + decl.underscorify().to_upper(), true)
583 else
584 srcconf.set10('HAVE_' + decl.underscorify().to_upper(), false)
585 endif
586 endforeach
587
588 found_types = []
589 missing_types = []
590 foreach tuple: [
591 ['scmp_filter_ctx'],
592 ['struct seccomp_notif_sizes'],
593 ['struct clone_args'],
594 ['__aligned_u64'],
595 ['struct mount_attr'],
596 ['struct open_how'],
597 ]
598
599 if tuple.length() >= 2
600 cond = tuple[1]
601 else
602 ident1 = 'HAVE_' + tuple[0].underscorify().to_upper()
603 ident2 = 'ENABLE_' + tuple[0].underscorify().to_upper()
604 cond = srcconf.get(ident1, 0) == 1 or srcconf.get(ident2, 0) == 1
605 endif
606
607 if cond
608 found_types += tuple[0]
609 else
610 missing_types += tuple[0]
611 endif
612 endforeach
613
614 ## Headers.
615 foreach ident: [
616 ['bpf', '''#include <sys/syscall.h>
617 #include <unistd.h>'''],
618 ['close_range', '''#include <unistd.h>'''],
619 ['execveat', '''#include <unistd.h>'''],
620 ['endmntent', '''#include <stdio.h>
621 #include <mntent.h>'''],
622 ['faccessat', '''#include <fcntl.h>
623 #include <unistd.h>'''],
624 ['fexecve', '''#include <unistd.h>'''],
625 ['fgetln', '''#include <stdio.h>'''],
626 ['fsconfig', '''#include <sys/mount.h>'''],
627 ['fsmount', '''#include <sys/mount.h>'''],
628 ['fsopen', '''#include <sys/mount.h>'''],
629 ['fspick', '''#include <sys/mount.h>'''],
630 ['getgrgid_r', '''#include <sys/types.h>
631 #include <grp.h>'''],
632 ['getline', '''#include <stdio.h>'''],
633 ['getsubopt', '''#include <stdlib.h>'''],
634 ['gettid', '''#include <sys/types.h>
635 #include <unistd.h>'''],
636 ['hasmntopt', '''#include <stdio.h>
637 #include <mntent.h>'''],
638 ['kcmp', '''#include <linux/kcmp.h>'''],
639 ['keyctl', '''#include <sys/types.h>
640 #include <keyutils.h>'''],
641 ['memfd_create', '''#include <sys/mman.h>'''],
642 ['mount_setattr', '''#include <sys/mount.h>'''],
643 ['move_mount', '''#include <sys/mount.h>'''],
644 ['openat2', '''#include <sys/types.h>
645 #include <sys/stat.h>
646 #include <fctnl.h>'''],
647 ['open_tree', '''#include <sys/mount.h>'''],
648 ['personality', '''#include <sys/personality.h>'''],
649 ['pidfd_open', '''#include <stdlib.h>
650 #include <unistd.h>
651 #include <signal.h>
652 #include <sys/wait.h>'''],
653 ['pidfd_send_signal', '''#include <stdlib.h>
654 #include <unistd.h>
655 #include <signal.h>
656 #include <sys/wait.h>'''],
657 ['pivot_root', '''#include <stdlib.h>
658 #include <unistd.h>'''], # no known header declares pivot_root
659 ['prlimit', '''#include <sys/time.h>
660 #include <sys/resource.h>'''],
661 ['prlimit64', '''#include <sys/time.h>
662 #include <sys/resource.h>'''],
663 ['renameat2', '''#include <stdio.h>
664 #include <fcntl.h>'''],
665 ['sethostname', '''#include <unistd.h>'''],
666 ['setmntent', '''#include <stdio.h>
667 #include <mntent.h>'''],
668 ['setns', '''#include <sched.h>'''],
669 ['sigdescr_np', '''#include <string.h>'''],
670 ['signalfd', '''#include <sys/signalfd.h>'''],
671 ['statvfs', '''#include <sys/statvfs.h>'''],
672 ['statx', '''#include <sys/types.h>
673 #include <sys/stat.h>
674 #include <unistd.h>'''],
675 ['strchrnul', '''#include <string.h>'''],
676 ['strlcat', '''#include <string.h>'''],
677 ['strlcpy', '''#include <string.h>'''],
678 ['unshare', '''#include <sched.h>'''],
679 ]
680
681 have = cc.has_function(ident[0], prefix: ident[1], args: '-D_GNU_SOURCE')
682 srcconf.set10('HAVE_' + ident[0].to_upper(), have)
683 endforeach
684
685 found_headers = []
686 missing_headers = []
687 foreach tuple: [
688 ['systemd/sd-bus.h'],
689 ['systemd/sd-event.h'],
690 ['sys/resource.h'],
691 ['sys/memfd.h'],
692 ['sys/personality.h'],
693 ['sys/signalfd.h'],
694 ['sys/timerfd.h'],
695 ['pty.h'],
696 ['utmpx.h'],
697 ]
698 srcconf.set10('HAVE_' + tuple[0].underscorify().to_upper(), cc.has_header(tuple[0]))
699
700 if tuple.length() >= 2
701 cond = tuple[1]
702 else
703 ident1 = 'HAVE_' + tuple[0].underscorify().to_upper()
704 ident2 = 'ENABLE_' + tuple[0].underscorify().to_upper()
705 cond = srcconf.get(ident1, 0) == 1 or srcconf.get(ident2, 0) == 1
706 endif
707
708 if cond
709 found_headers += tuple[0]
710 else
711 missing_headers += tuple[0]
712 endif
713 endforeach
714
715 ## Deps.
716 found_deps = []
717 missing_deps = []
718 foreach tuple: [
719 ['AppArmor'],
720 ['SECCOMP'],
721 ['SELinux'],
722 ['libcap'],
723 ['static libcap'],
724 ['pam'],
725 ['openssl'],
726 ['liburing'],
727 ['libsystemd'],
728 ]
729
730 if tuple.length() >= 2
731 cond = tuple[1]
732 else
733 ident1 = 'HAVE_' + tuple[0].underscorify().to_upper()
734 ident2 = 'ENABLE_' + tuple[0].underscorify().to_upper()
735 cond = srcconf.get(ident1, 0) == 1 or srcconf.get(ident2, 0) == 1
736 endif
737
738 if cond
739 found_deps += tuple[0]
740 else
741 missing_deps += tuple[0]
742 endif
743 endforeach
744
745 # Generate config.h
746 config_h = configure_file(
747 output: 'config.h',
748 configuration: srcconf)
749
750 add_project_arguments('-include', 'config.h', language: 'c')
751
752 # Binaries.
753 cmd_programs = []
754 hook_programs = []
755 public_programs = []
756 template_scripts = []
757 test_programs = []
758
759 # Includes.
760 liblxc_includes = include_directories(
761 '.',
762 'src',
763 'src/include',
764 'src/lxc',
765 'src/lxc/cgroups',
766 'src/lxc/storage')
767
768 # Early sub-directories.
769 subdir('src/include')
770 subdir('src/lxc')
771 subdir('src/lxc/pam')
772
773 # Library.
774 liblxc_dependencies = [
775 threads,
776 ]
777
778 if want_seccomp
779 liblxc_dependencies += libseccomp
780 endif
781
782 if want_capabilities
783 liblxc_dependencies += [libcap]
784 endif
785
786 if want_openssl
787 liblxc_dependencies += [libopenssl]
788 endif
789
790 if want_selinux
791 liblxc_dependencies += [libselinux]
792 endif
793
794 if want_apparmor
795 liblxc_dependencies += [libapparmor]
796 endif
797
798 if want_io_uring
799 liblxc_dependencies += [liburing]
800 endif
801
802 if has_sd_bus
803 liblxc_dependencies += [libsystemd]
804 endif
805
806 liblxc_link_whole = [liblxc_static]
807
808 liblxc = shared_library(
809 'lxc',
810 version: liblxc_version,
811 include_directories: liblxc_includes,
812 link_args: ['-DPIC'],
813 c_args: ['-DPIC'],
814 link_whole: liblxc_link_whole,
815 dependencies: liblxc_dependencies,
816 install: true)
817
818 liblxc_dep = declare_dependency(
819 link_with: liblxc,
820 dependencies: liblxc_dependencies)
821
822 # Rest of sub-directories.
823 if want_apparmor
824 subdir('config/apparmor')
825 subdir('config/apparmor/abstractions')
826 subdir('config/apparmor/profiles')
827 endif
828 subdir('config/bash')
829 subdir('config/etc')
830 subdir('config/init/common')
831 subdir('config/init/systemd')
832 subdir('config/init/sysvinit')
833 subdir('config/init/upstart')
834 if want_selinux
835 subdir('config/selinux')
836 endif
837 subdir('config/sysconfig')
838 subdir('config/templates')
839 subdir('config/templates/common.conf.d')
840 subdir('config/yum')
841 subdir('doc')
842 subdir('doc/ja')
843 subdir('doc/ko')
844 subdir('doc/examples')
845 subdir('doc/rootfs')
846 subdir('hooks')
847 if want_commands
848 subdir('src/lxc/cmd')
849 endif
850 if want_tools or want_tools_multicall
851 subdir('src/lxc/tools')
852 endif
853 subdir('src/lxc/tools/include')
854 subdir('src/tests')
855 subdir('templates')
856
857 # Pkg-config.
858 pkg_config_file = pkgconfig.generate(liblxc,
859 description: 'linux container tools',
860 version: version_data.get('LXC_VERSION'),
861 url: 'http://linuxcontainers.org',
862 libraries: '-lutil -lpthread -ldl',
863 libraries_private: pkgconfig_libs,
864 )
865
866 # Empty dirs.
867 install_emptydir(join_paths(localstatedir, 'cache', 'lxc'))
868 install_emptydir(join_paths(localstatedir, 'lib', 'lxc'))
869
870 # RPM spec file.
871 specconf = configuration_data()
872 specconf.set('LXC_VERSION_BASE', meson.project_version())
873 specconf.set('LXC_VERSION_BETA', version_data.get('LXC_VERSION_BETA'))
874 specconf.set('PACKAGE', meson.project_name())
875 specconf.set('LXC_DISTRO_SYSCONF', conf.get('LXC_DISTRO_SYSCONF'))
876
877 configure_file(
878 configuration: specconf,
879 input: 'lxc.spec.in',
880 output: 'lxc.spec',
881 install: false)
882
883 # Build overview.
884 status = [
885 '@0@ @1@'.format(meson.project_name(), meson.project_version()),
886
887 'Meson version: @0@'.format(meson.version()),
888
889 'prefix directory: @0@'.format(prefixdir),
890 'bin directory: @0@'.format(bindir),
891 'data directory: @0@'.format(datadir),
892 'doc directory: @0@'.format(docdir),
893 'include directory: @0@'.format(includedir),
894 'lib directory: @0@'.format(libdir),
895 'libexec directory: @0@'.format(libexecdir),
896 'local state directory: @0@'.format(localstatedir),
897 'sbin directory: @0@'.format(sbindir),
898 'sysconf directory: @0@'.format(sysconfdir),
899
900 'lxc cgroup pattern: @0@'.format(cgrouppattern),
901 'lxc init directory: @0@'.format(libexecdir),
902 'runtime path: @0@'.format(runtimepath),
903
904 'lxc default config: @0@'.format(lxcdefaultconfig),
905 'lxc global config: @0@'.format(lxcglobalconfig),
906 'lxc hook directory: @0@'.format(lxchookdir),
907 'lxc hook bin directory: @0@'.format(lxchookbindir),
908 'lxc rootfs mount directory: @0@'.format(lxcrootfsmount),
909 'log path: @0@'.format(lxclogpath),
910 'lxc path: @0@'.format(lxcpath),
911 'lxc template config: @0@'.format(lxctemplateconfdir),
912 'lxc template directory: @0@'.format(lxctemplatedir),
913 'lxc user network config: @0@'.format(lxc_user_network_conf),
914 'lxc user network database: @0@'.format(lxc_user_network_db)]
915
916 alt_time_epoch = run_command('date', '-Is', '-u', '-d',
917 '@@0@'.format(time_epoch), check: true).stdout().strip()
918 status += [
919 'time epoch: @0@ (@1@)'.format(time_epoch, alt_time_epoch)]
920
921 status += [
922 '',
923 'supported dependencies: @0@'.format(', '.join(found_deps)),
924 '',
925 'unsupported dependencies: @0@'.format(', '.join(missing_deps)),
926 '']
927
928 status += [
929 '',
930 'supported headers: @0@'.format(', '.join(found_headers)),
931 '',
932 'unsupported headers: @0@'.format(', '.join(missing_headers)),
933 '']
934
935 status += [
936 '',
937 'supported calls: @0@'.format(', '.join(found_syscalls)),
938 '',
939 'unsupported calls: @0@'.format(', '.join(missing_syscalls)),
940 '']
941
942 status += [
943 '',
944 'supported types: @0@'.format(', '.join(found_types)),
945 '',
946 'unsupported types: @0@'.format(', '.join(missing_types)),
947 '']
948
949 message('\n '.join(status))