1 # SPDX-License-Identifier: LGPL-2.1-or-later
19 meson_version: '>= 0.61')
21 cc = meson.get_compiler('c')
22 pkgconfig = import('pkgconfig')
26 version_data = configuration_data()
27 version_data.set('LXC_VERSION_MAJOR', '4')
28 version_data.set('LXC_VERSION_MINOR', '0')
29 version_data.set('LXC_VERSION_MICRO', '7')
30 version_data.set('LXC_ABI', '4.0.7')
31 version_data.set('LXC_DEVEL', '1')
32 version_data.set('LXC_VERSION', '4.0.7-devel')
33 liblxc_version = '1.7.0'
35 # Configuration options.
36 conf = configuration_data()
37 conf.set_quoted('PROJECT', meson.project_name())
38 conf.set_quoted('PROJECT_URL', 'https://linuxcontainers.org/lxc/')
39 conf.set_quoted('PROJECT_VERSION', meson.project_version())
40 conf.set_quoted('PACKAGE_VERSION', meson.project_version())
41 conf.set('_GNU_SOURCE', true)
42 conf.set('_FILE_OFFSET_BITS', 64)
43 conf.set('__STDC_FORMAT_MACROS', true)
45 project_source_root = meson.current_source_dir()
46 project_build_root = meson.current_build_dir()
49 prefixdir = get_option('prefix')
51 apparmorcachedir = get_option('apparmor-cache-path')
52 globalconfig = get_option('global-config-path')
53 localstatedir = join_paths('/', get_option('localstatedir'))
54 logpath = get_option('log-path')
55 lxcpathprefix = get_option('data-path')
56 rootfsmount = get_option('rootfs-mount-path')
57 user_network_db_opt = get_option('usernet-db-path')
58 user_network_conf_opt = get_option('usernet-config-path')
60 bashcompletiondir = join_paths('/', 'usr', 'share', 'bash-completion', 'completions')
61 bindir = join_paths(prefixdir, get_option('bindir'))
62 datadir = join_paths(prefixdir, get_option('datadir'))
63 docdir = join_paths(datadir, get_option('doc-path'))
64 includedir = join_paths(prefixdir, get_option('includedir'))
65 libdir = join_paths(prefixdir, get_option('libdir'))
66 libexecdir = join_paths(prefixdir, get_option('libexecdir'))
67 runtimepath = join_paths(prefixdir, get_option('runtime-path'))
68 sbindir = join_paths(prefixdir, get_option('sbindir'))
69 sysconfdir = join_paths(prefixdir, get_option('sysconfdir'))
71 lxcapparmorcachedir = join_paths(localstatedir, apparmorcachedir)
72 lxcdefaultconfig = join_paths(sysconfdir, 'lxc/default.conf')
73 lxcexamplesdir = join_paths(docdir, 'examples')
74 lxcglobalconfig = join_paths(sysconfdir, globalconfig)
75 lxchookbindir = join_paths(libexecdir, 'lxc/hooks')
76 lxchookdir = join_paths(datadir, 'lxc/hooks')
77 lxcinclude = join_paths(includedir, 'lxc')
78 lxclibexec = join_paths(libexecdir, 'lxc')
79 lxclogpath = join_paths(localstatedir, logpath)
80 lxcpath = join_paths(localstatedir, lxcpathprefix)
81 lxcrootfsmount = join_paths(libdir, rootfsmount)
82 lxctemplateconfig = join_paths(datadir, 'lxc/config')
83 lxctemplatedir = join_paths(datadir, 'lxc/templates')
84 lxc_user_network_conf = join_paths(sysconfdir, user_network_conf_opt)
85 lxc_user_network_db = join_paths(runtimepath, user_network_db_opt)
87 conf.set_quoted('BINDIR', bindir)
88 conf.set_quoted('DATADIR', datadir)
89 conf.set_quoted('DOCDIR', docdir)
90 conf.set_quoted('INCLUDEDIR', includedir)
91 conf.set_quoted('LIBDIR', libdir)
92 conf.set_quoted('LIBEXECDIR', libexecdir)
93 conf.set_quoted('LOCALSTATEDIR', localstatedir)
94 conf.set_quoted('RUNTIME_PATH', runtimepath)
95 conf.set_quoted('SBINDIR', sbindir)
96 conf.set_quoted('SYSCONFDIR', sysconfdir)
98 conf.set_quoted('APPARMOR_CACHE_DIR', lxcapparmorcachedir)
99 conf.set_quoted('LOGPATH', lxclogpath)
100 conf.set_quoted('LXCBINHOOKDIR', lxchookbindir)
101 conf.set_quoted('LXC_DEFAULT_CONFIG', lxcdefaultconfig)
102 conf.set_quoted('LXC_GLOBAL_CONF', lxcglobalconfig)
103 conf.set_quoted('LXCHOOKDIR', lxchookdir)
104 conf.set_quoted('LXCINITDIR', libexecdir)
105 conf.set_quoted('LXCPATH', lxcpath)
106 conf.set_quoted('LXCROOTFSMOUNT', lxcrootfsmount)
107 conf.set_quoted('LXCTEMPLATECONFIG', lxctemplateconfig)
108 conf.set_quoted('LXCTEMPLATEDIR', lxctemplatedir)
109 conf.set_quoted('LXC_USERNIC_CONF', lxc_user_network_conf)
110 conf.set_quoted('LXC_USERNIC_DB', lxc_user_network_db)
112 # Custom configuration.
113 cgrouppattern = get_option('cgroup-pattern')
114 wants_io_uring = get_option('io-uring-event-loop')
115 want_examples = get_option('examples')
116 want_mans = get_option('man')
117 want_tests = get_option('tests')
119 conf.set_quoted('DEFAULT_CGROUP_PATTERN', cgrouppattern)
121 dummy_config_data = configuration_data()
122 dummy_config_data.set_quoted('DUMMY_VARIABLE', '1')
125 possible_cc_flags = [
127 '-Wimplicit-fallthrough=5',
129 '-Wstrict-prototypes',
130 '-fno-strict-aliasing',
131 '-fstack-clash-protection',
132 '-fstack-protector-strong',
133 '--param=ssp-buffer-size=4',
134 '--mcet -fcf-protection',
135 '-Werror=implicit-function-declaration',
137 '-Wmissing-include-dirs',
138 '-Wold-style-definition',
140 '-Wunused-but-set-variable',
141 '-Wno-unused-parameter',
143 '-Wsuggest-attribute=noreturn',
144 '-Werror=return-type',
145 '-Werror=incompatible-pointer-types',
150 '-fdiagnostics-show-option',
151 '-Werror=shift-count-overflow',
152 '-Werror=shift-overflow=2',
155 '-fasynchronous-unwind-tables',
159 '-Wreturn-local-addr',
161 '-Wstringop-overflow',
164 possible_link_flags = [
171 if meson.version().version_compare('>=0.46')
172 add_project_link_arguments(cc.get_supported_link_arguments(possible_link_flags), language: 'c')
174 add_project_link_arguments(possible_link_flags, language: 'c')
177 add_project_arguments(cc.get_supported_arguments(possible_cc_flags), language: 'c')
181 if wants_io_uring == true
182 liburing = dependency('liburing')
183 if cc.has_function('io_uring_prep_poll_add', prefix: '#include <liburing.h>', dependencies: liburing) == false
184 error('liburing version does not support IORING_POLL_ADD_MULTI')
187 conf.set10('HAVE_LIBURING', true)
191 sh = find_program('sh')
192 date = find_program('date')
193 git = find_program('git', required: false)
194 time_epoch = run_command(sh, '-c', 'echo "$SOURCE_DATE_EPOCH"', check: true).stdout().strip()
195 if time_epoch == '' and git.found() and run_command('test', '-e', '.git', check: false).returncode() == 0
196 # If we're in a git repository, use the creation time of the latest git tag.
197 latest_tag = run_command(git, 'describe', '--abbrev=0', '--tags', check: true).stdout().strip()
198 time_epoch = run_command(git, 'log', '--no-show-signature', '-1', '--format=%at', latest_tag, check: true).stdout()
200 # Fallback to current epoch
201 time_epoch = run_command(date, '+%s', check: true).stdout()
203 time_epoch = time_epoch.to_int()
204 conf.set('TIME_EPOCH', time_epoch)
207 threads = dependency('threads')
210 libseccomp = dependency('libseccomp')
211 conf.set10('HAVE_SECCOMP', libseccomp.found())
212 pkgconfig_libs += libseccomp
213 if libseccomp.found()
214 if libseccomp.version().version_compare('>=2.5.0')
215 # https://github.com/seccomp/libseccomp/commit/dead12bc788b259b148cc4d93b970ef0bd602b1a
216 conf.set10('HAVE_DECL_SECCOMP_NOTIFY_FD', true)
218 conf.set10('HAVE_DECL_SECCOMP_NOTIFY_FD', false)
221 if libseccomp.version().version_compare('>=2.0.0')
222 # https://github.com/seccomp/libseccomp/commit/6220c8c0fc479d97b6d3e3166a4e46fbfe25a3c0
223 conf.set10('HAVE_DECL_SECCOMP_SYSCALL_RESOLVE_NAME_ARCH', true)
225 conf.set10('HAVE_DECL_SECCOMP_SYSCALL_RESOLVE_NAME_ARCH', false)
228 seccomp_headers = '''
234 'struct seccomp_notif_sizes',
238 # We get -1 if the size cannot be determined
239 if cc.sizeof(decl, prefix: seccomp_headers, args: '-D_GNU_SOURCE') > 0
240 conf.set10('HAVE_' + decl.underscorify().to_upper(), true)
242 conf.set10('HAVE_' + decl.underscorify().to_upper(), false)
248 libselinux = dependency('libselinux', required: false)
249 conf.set10('HAVE_SELINUX', libselinux.found())
250 pkgconfig_libs += libselinux
253 libapparmor = dependency('libapparmor', required: false)
254 conf.set10('HAVE_APPARMOR', libapparmor.found())
257 libopenssl = dependency('openssl', required: false)
258 conf.set10('HAVE_OPENSSL', libopenssl.found())
259 pkgconfig_libs += libopenssl
262 libcap = dependency('libcap', required: false)
263 if not libcap.found()
264 # Compat with Ubuntu 14.04 which ships libcap w/o .pc file
265 libcap = cc.find_library('cap', required: false)
267 conf.set10('HAVE_LIBCAP', libcap.found())
268 pkgconfig_libs += libcap
270 libcap_static = dependency('libcap', required: false, static: true)
271 if not libcap_static.found()
272 # Compat with Ubuntu 14.04 which ships libcap w/o .pc file
273 libcap_static = cc.find_library('cap', required: false, static: true)
275 conf.set10('HAVE_STATIC_LIBCAP', libcap_static.found())
278 pam = cc.find_library('pam',
279 has_headers: 'security/pam_modules.h')
280 conf.set10('HAVE_PAM', pam.found())
281 pkgconfig_libs += pam
284 have = cc.has_function('strchrnul', prefix: '#include <string.h>', args: '-D_GNU_SOURCE')
285 conf.set10('HAVE_STRCHRNUL', have)
287 have = cc.has_function('openpty', prefix: '#include <pty.h>', args: '-D_GNU_SOURCE')
288 conf.set10('HAVE_OPENPTY', have)
290 ## Compiler attributes.
297 conf.set10('HAVE_COMPILER_ATTR_' + ccattr.underscorify().to_upper(), cc.has_function_attribute(ccattr))
302 missing_syscalls = []
329 ['pidfd_send_signal'],
345 if tuple.length() >= 2
348 ident1 = 'HAVE_' + tuple[0].underscorify().to_upper()
349 ident2 = 'ENABLE_' + tuple[0].underscorify().to_upper()
350 cond = conf.get(ident1, 0) == 1 or conf.get(ident2, 0) == 1
354 found_syscalls += tuple[0]
356 missing_syscalls += tuple[0]
363 #include <sys/mount.h>
364 #include <sys/stat.h>
365 #include <linux/fs.h>
366 #include <linux/types.h>
367 #include <linux/openat2.h>
368 #include <linux/sched.h>
378 # We get -1 if the size cannot be determined
379 if cc.sizeof(decl, prefix: decl_headers, args: '-D_GNU_SOURCE') > 0
380 conf.set10('HAVE_' + decl.underscorify().to_upper(), true)
382 conf.set10('HAVE_' + decl.underscorify().to_upper(), false)
390 ['struct seccomp_notif_sizes'],
391 ['struct clone_args'],
393 ['struct mount_attr'],
397 if tuple.length() >= 2
400 ident1 = 'HAVE_' + tuple[0].underscorify().to_upper()
401 ident2 = 'ENABLE_' + tuple[0].underscorify().to_upper()
402 cond = conf.get(ident1, 0) == 1 or conf.get(ident2, 0) == 1
406 found_types += tuple[0]
408 missing_types += tuple[0]
414 ['bpf', '''#include <sys/syscall.h>
415 #include <unistd.h>'''],
416 ['close_range', '''#include <unistd.h>'''],
417 ['execveat', '''#include <unistd.h>'''],
418 ['endmntent', '''#include <stdio.h>
419 #include <mntent.h>'''],
420 ['faccessat', '''#include <fcntl.h>
421 #include <unistd.h>'''],
422 ['fexecve', '''#include <unistd.h>'''],
423 ['fgetln', '''#include <stdio.h>'''],
424 ['fsconfig', '''#include <sys/mount.h>'''],
425 ['fsmount', '''#include <sys/mount.h>'''],
426 ['fsopen', '''#include <sys/mount.h>'''],
427 ['fspick', '''#include <sys/mount.h>'''],
428 ['getgrgid_r', '''#include <sys/types.h>
429 #include <grp.h>'''],
430 ['getline', '''#include <stdio.h>'''],
431 ['getsubopt', '''#include <stdlib.h>'''],
432 ['gettid', '''#include <sys/types.h>
433 #include <unistd.h>'''],
434 ['hasmntopt', '''#include <stdio.h>
435 #include <mntent.h>'''],
436 ['kcmp', '''#include <linux/kcmp.h>'''],
437 ['keyctl', '''#include <sys/types.h>
438 #include <keyutils.h>'''],
439 ['memfd_create', '''#include <sys/mman.h>'''],
440 ['mount_setattr', '''#include <sys/mount.h>'''],
441 ['move_mount', '''#include <sys/mount.h>'''],
442 ['openat2', '''#include <sys/types.h>
443 #include <sys/stat.h>
444 #include <fctnl.h>'''],
445 ['open_tree', '''#include <sys/mount.h>'''],
446 ['personality', '''#include <sys/personality.h>'''],
447 ['pidfd_open', '''#include <stdlib.h>
450 #include <sys/wait.h>'''],
451 ['pidfd_send_signal', '''#include <stdlib.h>
454 #include <sys/wait.h>'''],
455 ['pivot_root', '''#include <stdlib.h>
456 #include <unistd.h>'''], # no known header declares pivot_root
457 ['prlimit', '''#include <sys/time.h>
458 #include <sys/resource.h>'''],
459 ['prlimit64', '''#include <sys/time.h>
460 #include <sys/resource.h>'''],
461 ['renameat2', '''#include <stdio.h>
462 #include <fcntl.h>'''],
463 ['sethostname', '''#include <unistd.h>'''],
464 ['setmntent', '''#include <stdio.h>
465 #include <mntent.h>'''],
466 ['setns', '''#include <sched.h>'''],
467 ['sigdescr_np', '''#include <string.h>'''],
468 ['signalfd', '''#include <sys/signalfd.h>'''],
469 ['statx', '''#include <sys/types.h>
470 #include <sys/stat.h>
471 #include <unistd.h>'''],
472 ['strchrnul', '''#include <string.h>'''],
473 ['strlcat', '''#include <string.h>'''],
474 ['strlcpy', '''#include <string.h>'''],
475 ['unshare', '''#include <sched.h>'''],
478 have = cc.has_function(ident[0], prefix: ident[1], args: '-D_GNU_SOURCE')
479 conf.set10('HAVE_' + ident[0].to_upper(), have)
487 ['sys/personality.h'],
493 conf.set10('HAVE_' + tuple[0].underscorify().to_upper(), cc.has_header(tuple[0]))
495 if tuple.length() >= 2
498 ident1 = 'HAVE_' + tuple[0].underscorify().to_upper()
499 ident2 = 'ENABLE_' + tuple[0].underscorify().to_upper()
500 cond = conf.get(ident1, 0) == 1 or conf.get(ident2, 0) == 1
504 found_headers += tuple[0]
506 missing_headers += tuple[0]
523 if tuple.length() >= 2
526 ident1 = 'HAVE_' + tuple[0].underscorify().to_upper()
527 ident2 = 'ENABLE_' + tuple[0].underscorify().to_upper()
528 cond = conf.get(ident1, 0) == 1 or conf.get(ident2, 0) == 1
532 found_deps += tuple[0]
534 missing_deps += tuple[0]
539 config_h = configure_file(
543 add_project_arguments('-include', 'config.h', language: 'c')
549 template_scripts = []
553 basic_includes = include_directories(
558 liblxc_includes = [basic_includes, include_directories(
563 # Early sub-directories.
564 subdir('src/include')
568 liblxc_dependencies = [
577 if wants_io_uring == true
578 liblxc_dependencies += [liburing]
581 liblxc = shared_library(
583 version: liblxc_version,
584 include_directories: liblxc_includes,
585 link_args: ['-DPIC'],
587 link_whole: [liblxc_static],
588 dependencies: liblxc_dependencies,
591 liblxc_dep = declare_dependency(
593 dependencies: liblxc_dependencies)
595 # Rest of sub-directories.
596 subdir('config/bash')
599 subdir('src/lxc/cmd')
600 subdir('src/lxc/tools')
601 subdir('src/lxc/tools/include')
606 pkg_config_file = pkgconfig.generate(liblxc,
607 description: 'linux container tools',
608 version: version_data.get('LXC_VERSION'),
609 url: 'http://linuxcontainers.org',
610 libraries: '-lutil -lpthread -ldl',
611 libraries_private: pkgconfig_libs,
615 install_emptydir(join_paths(localstatedir, 'cache', 'lxc'))
616 install_emptydir(join_paths(localstatedir, 'lib', 'lxc'))
620 '@0@ @1@'.format(meson.project_name(), meson.project_version()),
622 'Meson version: @0@'.format(meson.version()),
624 'prefix directory: @0@'.format(prefixdir),
625 'bin directory: @0@'.format(bindir),
626 'data directory: @0@'.format(datadir),
627 'doc directory: @0@'.format(docdir),
628 'include directory: @0@'.format(includedir),
629 'lib directory: @0@'.format(libdir),
630 'libexec directory: @0@'.format(libexecdir),
631 'local state directory: @0@'.format(localstatedir),
632 'sbin directory: @0@'.format(sbindir),
633 'sysconf directory: @0@'.format(sysconfdir),
635 'lxc cgroup pattern: @0@'.format(cgrouppattern),
636 'lxc init directory: @0@'.format(libexecdir),
637 'runtime path: @0@'.format(runtimepath),
639 'lxc default config: @0@'.format(lxcdefaultconfig),
640 'lxc global config: @0@'.format(lxcglobalconfig),
641 'lxc hook directory: @0@'.format(lxchookdir),
642 'lxc hook bin directory: @0@'.format(lxchookbindir),
643 'lxc rootfs mount directory: @0@'.format(lxcrootfsmount),
644 'log path: @0@'.format(lxclogpath),
645 'lxc path: @0@'.format(lxcpath),
646 'lxc template config: @0@'.format(lxctemplateconfig),
647 'lxc template directory: @0@'.format(lxctemplatedir),
648 'lxc user network config: @0@'.format(lxc_user_network_conf),
649 'lxc user network database: @0@'.format(lxc_user_network_db)]
651 alt_time_epoch = run_command('date', '-Is', '-u', '-d',
652 '@@0@'.format(time_epoch), check: true).stdout().strip()
654 'time epoch: @0@ (@1@)'.format(time_epoch, alt_time_epoch)]
658 'supported dependencies: @0@'.format(', '.join(found_deps)),
660 'unsupported dependencies: @0@'.format(', '.join(missing_deps)),
665 'supported headers: @0@'.format(', '.join(found_headers)),
667 'unsupported headers: @0@'.format(', '.join(missing_headers)),
672 'supported calls: @0@'.format(', '.join(found_syscalls)),
674 'unsupported calls: @0@'.format(', '.join(missing_syscalls)),
679 'supported types: @0@'.format(', '.join(found_types)),
681 'unsupported types: @0@'.format(', '.join(missing_types)),
684 message('\n '.join(status))