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