]> git.proxmox.com Git - mirror_lxc.git/blame - meson.build
build: support thread-safety enforcement as option
[mirror_lxc.git] / meson.build
CommitLineData
9b9d56e6
CB
1# SPDX-License-Identifier: LGPL-2.1-or-later
2
20b03401
SG
3# Project.
4project(
5 'lxc',
6 'c',
eba7f7a6 7 version: '4.0.0-devel',
20b03401
SG
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 ],
d841229e 19 meson_version: '>= 0.61')
9b9d56e6 20
20b03401
SG
21cc = meson.get_compiler('c')
22pkgconfig = import('pkgconfig')
0860988e 23pkgconfig_libs = []
9b9d56e6 24
20b03401 25# Version.
eba7f7a6 26liblxc_version = '1.7.0'
9b9d56e6
CB
27version_data = configuration_data()
28version_data.set('LXC_VERSION_MAJOR', '4')
29version_data.set('LXC_VERSION_MINOR', '0')
eba7f7a6 30version_data.set('LXC_VERSION_MICRO', '0')
e18dbec7 31version_data.set('LXC_VERSION_BETA', '')
eba7f7a6 32version_data.set('LXC_ABI', liblxc_version)
9b9d56e6 33version_data.set('LXC_DEVEL', '1')
eba7f7a6 34version_data.set('LXC_VERSION', meson.project_version())
9b9d56e6 35
eba7f7a6 36# Path handling.
9b9d56e6
CB
37project_source_root = meson.current_source_dir()
38project_build_root = meson.current_build_dir()
9b9d56e6 39prefixdir = get_option('prefix')
20b03401 40
7609de18
SG
41apparmorcachedir = get_option('apparmor-cache-path')
42globalconfig = get_option('global-config-path')
20b03401
SG
43localstatedir = join_paths('/', get_option('localstatedir'))
44logpath = get_option('log-path')
7609de18
SG
45lxcpathprefix = get_option('data-path')
46rootfsmount = get_option('rootfs-mount-path')
47user_network_db_opt = get_option('usernet-db-path')
48user_network_conf_opt = get_option('usernet-config-path')
20b03401 49
4a858b56 50bashcompletiondir = join_paths('/', 'usr', 'share', 'bash-completion', 'completions')
9b9d56e6 51bindir = join_paths(prefixdir, get_option('bindir'))
bf1f3470 52datadir = join_paths(prefixdir, get_option('datadir'))
47c56c50 53mandir = join_paths(prefixdir, get_option('mandir'))
7609de18 54docdir = join_paths(datadir, get_option('doc-path'))
9b9d56e6
CB
55includedir = join_paths(prefixdir, get_option('includedir'))
56libdir = join_paths(prefixdir, get_option('libdir'))
57libexecdir = join_paths(prefixdir, get_option('libexecdir'))
20b03401 58runtimepath = join_paths(prefixdir, get_option('runtime-path'))
bf1f3470
CB
59sbindir = join_paths(prefixdir, get_option('sbindir'))
60sysconfdir = join_paths(prefixdir, get_option('sysconfdir'))
61
7609de18 62lxcapparmorcachedir = join_paths(localstatedir, apparmorcachedir)
9d18059b
SG
63lxcconfdir = join_paths(sysconfdir, globalconfig)
64lxcdefaultconfig = join_paths(lxcconfdir, 'default.conf')
65lxcglobalconfig = join_paths(lxcconfdir, 'lxc.conf')
7609de18 66lxcexamplesdir = join_paths(docdir, 'examples')
7609de18 67lxchookbindir = join_paths(libexecdir, 'lxc/hooks')
1a9afacc 68lxcinclude = join_paths(includedir, 'lxc')
2f1bf5f5 69lxclibexec = join_paths(libexecdir, 'lxc')
bf1f3470 70lxclogpath = join_paths(localstatedir, logpath)
bf1f3470 71lxcpath = join_paths(localstatedir, lxcpathprefix)
7609de18 72lxcrootfsmount = join_paths(libdir, rootfsmount)
51f90ad9
SG
73lxcdatadir = join_paths(datadir, 'lxc')
74lxchookdir = join_paths(lxcdatadir, 'hooks')
75lxcselinuxdir = join_paths(lxcdatadir, 'selinux')
76lxctemplateconfdir = join_paths(lxcdatadir, 'config')
77lxctemplateconfcommondir = join_paths(lxctemplateconfdir, 'common.conf.d')
78lxctemplatedir = join_paths(lxcdatadir, 'templates')
72f1c44a 79lxc_user_network_conf = join_paths(sysconfdir, user_network_conf_opt)
72f1c44a 80lxc_user_network_db = join_paths(runtimepath, user_network_db_opt)
8c48813a 81pam_security = join_paths(libdir, 'security')
72f1c44a 82
eba7f7a6
SG
83# Configuration options.
84srcconf = configuration_data()
85srcconf.set('_GNU_SOURCE', true)
86srcconf.set('_FILE_OFFSET_BITS', 64)
87srcconf.set('__STDC_FORMAT_MACROS', true)
88srcconf.set_quoted('APPARMOR_CACHE_DIR', lxcapparmorcachedir)
89srcconf.set_quoted('LIBEXECDIR', libexecdir)
90srcconf.set_quoted('LOGPATH', lxclogpath)
91srcconf.set_quoted('LXC_DEFAULT_CONFIG', lxcdefaultconfig)
92srcconf.set_quoted('LXC_GLOBAL_CONF', lxcglobalconfig)
93srcconf.set_quoted('LXCINITDIR', libexecdir)
94srcconf.set_quoted('LXCPATH', lxcpath)
95srcconf.set_quoted('LXCROOTFSMOUNT', lxcrootfsmount)
96srcconf.set_quoted('LXCTEMPLATECONFIG', lxctemplateconfdir)
97srcconf.set_quoted('LXCTEMPLATECONFIG', lxctemplateconfdir)
98srcconf.set_quoted('LXCTEMPLATEDIR', lxctemplatedir)
99srcconf.set_quoted('LXC_USERNIC_CONF', lxc_user_network_conf)
100srcconf.set_quoted('LXC_USERNIC_DB', lxc_user_network_db)
101srcconf.set_quoted('RUNTIME_PATH', runtimepath)
102srcconf.set_quoted('SBINDIR', sbindir)
103
104conf = configuration_data()
105conf.set('BINDIR', bindir)
106conf.set('LIBEXECDIR', libexecdir)
107conf.set('LOCALSTATEDIR', localstatedir)
108conf.set('LXC_GLOBAL_CONF', lxcglobalconfig)
109conf.set('LXCHOOKDIR', lxchookdir)
110conf.set('LXCINITDIR', libexecdir)
111conf.set('LXCROOTFSMOUNT', lxcrootfsmount)
112conf.set('LXCTEMPLATECONFIG', lxctemplateconfdir)
113conf.set('LXCTEMPLATEDIR', lxctemplatedir)
114conf.set('PACKAGE_VERSION', meson.project_version())
115conf.set('RUNTIME_PATH', runtimepath)
116conf.set('SYSCONFDIR', sysconfdir)
20b03401 117
299f3f80
SG
118# Set sysconfdir
119fs = import('fs')
120if fs.is_dir('/etc/sysconfig')
121 distrosysconfdir = join_paths(sysconfdir, 'sysconfig')
122 conf.set('LXC_DISTRO_SYSCONF', distrosysconfdir)
123elif fs.is_dir('/etc/default')
124 distrosysconfdir = join_paths(sysconfdir, 'default')
125 conf.set('LXC_DISTRO_SYSCONF', distrosysconfdir)
126else
127 distrosysconfdir = ''
128endif
129
d5dff814 130# Cross-compile on Android.
cd3d6515 131srcconf.set10('IS_BIONIC', host_machine.system() == 'android')
d5dff814 132
20b03401
SG
133# Custom configuration.
134cgrouppattern = get_option('cgroup-pattern')
4dd5e0cf 135coverity = get_option('coverity-build')
8131bb44 136init_script = get_option('init-script')
5055c73d 137sanitize = get_option('b_sanitize')
7609de18 138want_examples = get_option('examples')
7d8a38b2 139want_io_uring = get_option('io-uring-event-loop')
8c48813a 140want_pam_cgroup = get_option('pam-cgroup')
7609de18 141want_mans = get_option('man')
20b03401 142want_tests = get_option('tests')
b3d18992 143want_tools = get_option('tools')
575d0e34
CB
144want_commands = get_option('commands')
145want_capabilities = get_option('capabilities')
146want_apparmor = get_option('apparmor')
147want_openssl = get_option('openssl')
148want_selinux = get_option('selinux')
d42a3b13 149want_oss_fuzz = get_option('oss-fuzz')
0b9adfda 150want_seccomp = get_option('seccomp')
0c4549a3 151want_thread_safety = get_option('thread-safety')
20b03401 152
eba7f7a6 153srcconf.set_quoted('DEFAULT_CGROUP_PATTERN', cgrouppattern)
4dd5e0cf
SG
154if coverity
155 srcconf.set('ENABLE_COVERITY_BUILD', 1)
156endif
9b9d56e6 157
20b03401
SG
158dummy_config_data = configuration_data()
159dummy_config_data.set_quoted('DUMMY_VARIABLE', '1')
9b9d56e6 160
abc5e6bb
CB
161# Those generate many false positives, and we do not want to change the code to
162# avoid them.
163basic_disabled_warnings = [
164 '-Wno-format-signedness',
165 '-Wno-missing-field-initializers',
166 '-Wno-unused-parameter',
167]
168
20b03401 169# Build flags.
9b9d56e6 170possible_cc_flags = [
20b03401
SG
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',
9b9d56e6
CB
207]
208
209possible_link_flags = [
20b03401
SG
210 '-Wl,--gc-sections',
211 '-Wl,-z,relro',
212 '-Wl,-z,now',
213 '-Wl,-fuse-ld=gold',
abc5e6bb 214 '-fstack-protector',
9b9d56e6
CB
215]
216
abc5e6bb
CB
217if sanitize == 'none'
218 possible_link_flags += '-Wl,--warn-common'
219endif
220
221if cc.get_id() == 'clang'
222 possible_cc_flags += [
223 '-Wno-typedef-redefinition',
224 '-Wno-gnu-variable-sized-type-not-at-end',
225 ]
226endif
227
9b9d56e6 228if meson.version().version_compare('>=0.46')
20b03401 229 add_project_link_arguments(cc.get_supported_link_arguments(possible_link_flags), language: 'c')
9b9d56e6 230else
20b03401 231 add_project_link_arguments(possible_link_flags, language: 'c')
9b9d56e6
CB
232endif
233
abc5e6bb 234add_project_arguments(cc.get_supported_arguments(basic_disabled_warnings), language : 'c')
20b03401 235add_project_arguments(cc.get_supported_arguments(possible_cc_flags), language: 'c')
9b9d56e6 236
d42a3b13
CB
237if 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')
242endif
243
20b03401
SG
244# Feature detection
245## I/O uring.
7d8a38b2 246if want_io_uring
20b03401
SG
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
eba7f7a6 252 srcconf.set10('HAVE_LIBURING', true)
4c96107d
SG
253else
254 srcconf.set10('HAVE_LIBURING', false)
747bc634
CB
255endif
256
20b03401 257## Time EPOCH.
ea6da257 258sh = find_program('sh')
23ba778f 259date = find_program('date')
20b03401 260git = find_program('git', required: false)
aa326e18
SG
261time_epoch = run_command(sh, '-c', 'echo "$SOURCE_DATE_EPOCH"', check: true).stdout().strip()
262if time_epoch == '' and git.found() and run_command('test', '-e', '.git', check: false).returncode() == 0
20b03401 263 # If we're in a git repository, use the creation time of the latest git tag.
f7de7d7a
SG
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
268endif
269
270# Fallback to current epoch.
271if time_epoch == ''
23ba778f 272 time_epoch = run_command(date, '+%s', check: true).stdout()
ea6da257 273endif
47c56c50 274generate_date = run_command(date, '--utc', '--date=@' + time_epoch, '+%Y-%m-%d', check: true).stdout().strip()
ea6da257 275
2bd9ab6f 276## Manpages.
4412d151 277sgml2man = find_program('docbook2X2man', 'docbook2x-man', 'db2x_docbook2man', 'docbook2man', 'docbook-to-man', required: want_mans)
2bd9ab6f
SG
278docbook2man = find_program('docbook2man', required: false)
279
280docconf = configuration_data()
281docconf.set('builddir', '.')
f80af4e1
SG
282docconf.set('BINDIR', bindir)
283docconf.set('DATADIR', datadir)
284docconf.set('DOCDIR', docdir)
285docconf.set('LOGPATH', lxclogpath)
286docconf.set('LXC_DEFAULT_CONFIG', lxcdefaultconfig)
2bd9ab6f 287docconf.set('LXC_GENERATE_DATE', generate_date)
f80af4e1
SG
288docconf.set('LXC_GLOBAL_CONF', lxcglobalconfig)
289docconf.set('LXCPATH', lxcpath)
290docconf.set('LXCTEMPLATEDIR', lxctemplatedir)
291docconf.set('LXC_USERNIC_CONF', lxc_user_network_conf)
292docconf.set('LXC_USERNIC_DB', lxc_user_network_db)
2bd9ab6f
SG
293docconf.set('PACKAGE_VERSION', version_data.get('LXC_VERSION'))
294if sgml2man.found() and docbook2man.found() and sgml2man.full_path() == docbook2man.full_path()
295 docconf.set('docdtd', '"-//Davenport//DTD DocBook V3.0//EN"')
296else
297 docconf.set('docdtd', '"-//OASIS//DTD DocBook XML" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd"')
298endif
299
20b03401 300## Threads.
9b9d56e6 301threads = dependency('threads')
20b03401
SG
302
303## Seccomp.
0b9adfda
CB
304if 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
20b03401 315
0b9adfda
CB
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)
20b03401 319 else
0b9adfda 320 srcconf.set10('HAVE_DECL_SECCOMP_SYSCALL_RESOLVE_NAME_ARCH', false)
20b03401 321 endif
0b9adfda
CB
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
341else
342 srcconf.set10('HAVE_SECCOMP', false)
9b9d56e6
CB
343endif
344
20b03401 345## SELinux.
575d0e34
CB
346if want_selinux
347 libselinux = dependency('libselinux', required: false)
348 srcconf.set10('HAVE_SELINUX', libselinux.found())
349 pkgconfig_libs += libselinux
350else
351 srcconf.set10('HAVE_SELINUX', false)
352endif
9b9d56e6 353
20b03401 354## AppArmor.
575d0e34
CB
355if want_apparmor
356 libapparmor = dependency('libapparmor', required: false)
357 srcconf.set10('HAVE_APPARMOR', libapparmor.found())
358else
359 srcconf.set10('HAVE_APPARMOR', false)
360endif
9b9d56e6 361
20b03401 362## OpenSSL.
575d0e34
CB
363if want_openssl
364 libopenssl = dependency('openssl', required: false)
365 srcconf.set10('HAVE_OPENSSL', libopenssl.found())
366 pkgconfig_libs += libopenssl
367else
368 srcconf.set10('HAVE_OPENSSL', false)
369endif
9b9d56e6 370
20b03401 371## Libcap..
575d0e34
CB
372if 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
9b9d56e6 380
575d0e34
CB
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
de4543d8
CB
386
387 code = '''
388int 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
575d0e34
CB
396else
397 srcconf.set10('HAVE_LIBCAP', false)
398 srcconf.set10('HAVE_STATIC_LIBCAP', false)
d0a16061 399endif
d0a16061 400
d42a3b13
CB
401if 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')
405endif
406
0c4549a3
CB
407srcconf.set10('ENFORCE_THREAD_SAFETY', want_thread_safety)
408
0860988e 409## PAM.
8c48813a 410pam = cc.find_library('pam', has_headers: 'security/pam_modules.h', required: want_pam_cgroup)
eba7f7a6 411srcconf.set10('HAVE_PAM', pam.found())
181cd6dc 412pkgconfig_libs += pam
0860988e 413
20b03401
SG
414## Others.
415have = cc.has_function('strchrnul', prefix: '#include <string.h>', args: '-D_GNU_SOURCE')
eba7f7a6 416srcconf.set10('HAVE_STRCHRNUL', have)
db4af8c5 417
20b03401 418have = cc.has_function('openpty', prefix: '#include <pty.h>', args: '-D_GNU_SOURCE')
eba7f7a6 419srcconf.set10('HAVE_OPENPTY', have)
db4af8c5 420
0c4549a3
CB
421have_func_strerror_r = cc.has_function('strerror_r', prefix: '#include <string.h>', args: '-D_GNU_SOURCE')
422srcconf.set10('HAVE_STRERROR_R', have)
423
424have_func_strerror_r_char_p = false
425
426if have_func_strerror_r
427 code = '''
428#define _GNU_SOURCE
429#include <string.h>
430int 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
438have_func_strerror_r_char_p = cc.compiles(code, name : 'strerror_r() returns char *')
439endif
440
441srcconf.set10('STRERROR_R_CHAR_P', have_func_strerror_r_char_p)
442
20b03401
SG
443## Compiler attributes.
444foreach ccattr: [
445 'fallthrough',
446 'nonnull',
447 'returns_nonnull',
448]
ae13cb3b 449
eba7f7a6 450 srcconf.set10('HAVE_COMPILER_ATTR_' + ccattr.underscorify().to_upper(), cc.has_function_attribute(ccattr))
ae13cb3b 451endforeach
5c26176d 452
20b03401 453## Syscalls.
ea6da257
CB
454found_syscalls = []
455missing_syscalls = []
20b03401
SG
456foreach tuple: [
457 ['bpf'],
458 ['close_range'],
459 ['endmntent'],
460 ['execveat'],
461 ['faccessat'],
462 ['strchrnul'],
0c4549a3 463 ['strerror_r'],
20b03401
SG
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()
eba7f7a6 504 cond = srcconf.get(ident1, 0) == 1 or srcconf.get(ident2, 0) == 1
20b03401
SG
505 endif
506
507 if cond
508 found_syscalls += tuple[0]
509 else
510 missing_syscalls += tuple[0]
511 endif
512endforeach
513
514## Types.
515decl_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'''
ea6da257 524
20b03401
SG
525foreach decl: [
526 '__aligned_u64',
527 'struct mount_attr',
528 'struct open_how',
529 'struct clone_args',
ea6da257
CB
530]
531
20b03401
SG
532 # We get -1 if the size cannot be determined
533 if cc.sizeof(decl, prefix: decl_headers, args: '-D_GNU_SOURCE') > 0
eba7f7a6 534 srcconf.set10('HAVE_' + decl.underscorify().to_upper(), true)
20b03401 535 else
eba7f7a6 536 srcconf.set10('HAVE_' + decl.underscorify().to_upper(), false)
20b03401 537 endif
ea6da257
CB
538endforeach
539
540found_types = []
541missing_types = []
20b03401
SG
542foreach 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]
ea6da257 550
20b03401
SG
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()
eba7f7a6 556 cond = srcconf.get(ident1, 0) == 1 or srcconf.get(ident2, 0) == 1
20b03401
SG
557 endif
558
559 if cond
560 found_types += tuple[0]
561 else
562 missing_types += tuple[0]
563 endif
564endforeach
565
566## Headers.
567foreach 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>'''],
ea6da257
CB
630]
631
20b03401 632 have = cc.has_function(ident[0], prefix: ident[1], args: '-D_GNU_SOURCE')
eba7f7a6 633 srcconf.set10('HAVE_' + ident[0].to_upper(), have)
ea6da257
CB
634endforeach
635
636found_headers = []
637missing_headers = []
20b03401
SG
638foreach 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'],
ea6da257 646]
eba7f7a6 647 srcconf.set10('HAVE_' + tuple[0].underscorify().to_upper(), cc.has_header(tuple[0]))
20b03401
SG
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()
eba7f7a6 654 cond = srcconf.get(ident1, 0) == 1 or srcconf.get(ident2, 0) == 1
20b03401
SG
655 endif
656
657 if cond
658 found_headers += tuple[0]
659 else
660 missing_headers += tuple[0]
661 endif
ea6da257
CB
662endforeach
663
20b03401 664## Deps.
ea6da257
CB
665found_deps = []
666missing_deps = []
20b03401
SG
667foreach tuple: [
668 ['AppArmor'],
669 ['SECCOMP'],
670 ['SELinux'],
671 ['libcap'],
672 ['static libcap'],
8c48813a 673 ['pam'],
20b03401
SG
674 ['openssl'],
675 ['liburing'],
ea6da257
CB
676]
677
20b03401
SG
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()
eba7f7a6 683 cond = srcconf.get(ident1, 0) == 1 or srcconf.get(ident2, 0) == 1
20b03401
SG
684 endif
685
686 if cond
687 found_deps += tuple[0]
688 else
689 missing_deps += tuple[0]
690 endif
ea6da257
CB
691endforeach
692
20b03401
SG
693# Generate config.h
694config_h = configure_file(
695 output: 'config.h',
eba7f7a6 696 configuration: srcconf)
20b03401
SG
697
698add_project_arguments('-include', 'config.h', language: 'c')
699
700# Binaries.
701cmd_programs = []
702hook_programs = []
703public_programs = []
704template_scripts = []
705test_programs = []
706
707# Includes.
8d77f43f 708liblxc_includes = include_directories(
20b03401
SG
709 '.',
710 'src',
8d77f43f
SG
711 'src/include',
712 'src/lxc',
20b03401 713 'src/lxc/cgroups',
8d77f43f 714 'src/lxc/storage')
20b03401
SG
715
716# Early sub-directories.
717subdir('src/include')
718subdir('src/lxc')
24dcd86d 719subdir('src/lxc/pam')
20b03401
SG
720
721# Library.
722liblxc_dependencies = [
723 threads,
20b03401
SG
724]
725
0b9adfda
CB
726if want_seccomp
727 liblxc_dependencies += libseccomp
728endif
729
826391b2
CB
730if want_capabilities
731 liblxc_dependencies += [libcap]
732endif
733
734if want_openssl
735 liblxc_dependencies += [libopenssl]
736endif
737
738if want_selinux
739 liblxc_dependencies += [libselinux]
740endif
741
742if want_apparmor
743 liblxc_dependencies += [libapparmor]
744endif
745
7d8a38b2 746if want_io_uring
20b03401
SG
747 liblxc_dependencies += [liburing]
748endif
749
d42a3b13 750liblxc_link_whole = [liblxc_static]
5055c73d 751
20b03401
SG
752liblxc = shared_library(
753 'lxc',
754 version: liblxc_version,
755 include_directories: liblxc_includes,
756 link_args: ['-DPIC'],
757 c_args: ['-DPIC'],
5055c73d 758 link_whole: liblxc_link_whole,
20b03401
SG
759 dependencies: liblxc_dependencies,
760 install: true)
761
762liblxc_dep = declare_dependency(
763 link_with: liblxc,
764 dependencies: liblxc_dependencies)
765
766# Rest of sub-directories.
826391b2
CB
767if want_apparmor
768 subdir('config/apparmor')
769 subdir('config/apparmor/abstractions')
770 subdir('config/apparmor/profiles')
771endif
4a858b56 772subdir('config/bash')
9d18059b 773subdir('config/etc')
e4e52844
SG
774subdir('config/init/common')
775subdir('config/init/systemd')
8131bb44
SG
776subdir('config/init/sysvinit')
777subdir('config/init/upstart')
826391b2
CB
778if want_selinux
779 subdir('config/selinux')
780endif
36a53f30 781subdir('config/sysconfig')
c2931f74
SG
782subdir('config/templates')
783subdir('config/templates/common.conf.d')
d9121fff 784subdir('config/yum')
47c56c50
SG
785subdir('doc')
786subdir('doc/ja')
787subdir('doc/ko')
b3da01d7 788subdir('doc/examples')
6dfabed1 789subdir('doc/rootfs')
20b03401 790subdir('hooks')
575d0e34
CB
791if want_commands
792 subdir('src/lxc/cmd')
793endif
794if want_tools
795 subdir('src/lxc/tools')
796endif
20b03401
SG
797subdir('src/lxc/tools/include')
798subdir('src/tests')
799subdir('templates')
800
0860988e
SG
801# Pkg-config.
802pkg_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,
0860988e
SG
808)
809
1404fcb8
SG
810# Empty dirs.
811install_emptydir(join_paths(localstatedir, 'cache', 'lxc'))
812install_emptydir(join_paths(localstatedir, 'lib', 'lxc'))
813
9c562440 814# RPM spec file.
e18dbec7
SG
815specconf = configuration_data()
816specconf.set('LXC_VERSION_BASE', meson.project_version())
817specconf.set('LXC_VERSION_BETA', version_data.get('LXC_VERSION_BETA'))
818specconf.set('PACKAGE', meson.project_name())
819specconf.set('LXC_DISTRO_SYSCONF', conf.get('LXC_DISTRO_SYSCONF'))
820
9c562440 821configure_file(
e18dbec7 822 configuration: specconf,
9c562440
SG
823 input: 'lxc.spec.in',
824 output: 'lxc.spec',
825 install: false)
826
20b03401 827# Build overview.
bf1f3470 828status = [
20b03401
SG
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),
51f90ad9 855 'lxc template config: @0@'.format(lxctemplateconfdir),
20b03401
SG
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)]
bf1f3470 859
ea6da257 860alt_time_epoch = run_command('date', '-Is', '-u', '-d',
aa326e18 861 '@@0@'.format(time_epoch), check: true).stdout().strip()
ea6da257 862status += [
20b03401 863 'time epoch: @0@ (@1@)'.format(time_epoch, alt_time_epoch)]
ea6da257
CB
864
865status += [
20b03401
SG
866 '',
867 'supported dependencies: @0@'.format(', '.join(found_deps)),
868 '',
869 'unsupported dependencies: @0@'.format(', '.join(missing_deps)),
870 '']
ea6da257
CB
871
872status += [
20b03401
SG
873 '',
874 'supported headers: @0@'.format(', '.join(found_headers)),
875 '',
876 'unsupported headers: @0@'.format(', '.join(missing_headers)),
877 '']
ea6da257
CB
878
879status += [
20b03401
SG
880 '',
881 'supported calls: @0@'.format(', '.join(found_syscalls)),
882 '',
883 'unsupported calls: @0@'.format(', '.join(missing_syscalls)),
884 '']
ea6da257
CB
885
886status += [
20b03401
SG
887 '',
888 'supported types: @0@'.format(', '.join(found_types)),
889 '',
890 'unsupported types: @0@'.format(', '.join(missing_types)),
891 '']
ea6da257 892
20b03401 893message('\n '.join(status))