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