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