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 lxcconfdir = join_paths(sysconfdir, globalconfig)
73 lxcdefaultconfig = join_paths(lxcconfdir, 'default.conf')
74 lxcglobalconfig = join_paths(lxcconfdir, 'lxc.conf')
75 lxcexamplesdir = join_paths(docdir, 'examples')
76 lxchookbindir = join_paths(libexecdir, '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 lxcdatadir = join_paths(datadir, 'lxc')
83 lxchookdir = join_paths(lxcdatadir, 'hooks')
84 lxcselinuxdir = join_paths(lxcdatadir, 'selinux')
85 lxctemplateconfdir = join_paths(lxcdatadir, 'config')
86 lxctemplateconfcommondir = join_paths(lxctemplateconfdir, 'common.conf.d')
87 lxctemplatedir = join_paths(lxcdatadir, 'templates')
88 lxc_user_network_conf = join_paths(sysconfdir, user_network_conf_opt)
89 lxc_user_network_db = join_paths(runtimepath, user_network_db_opt)
91 conf.set_quoted('BINDIR', bindir)
92 conf.set_quoted('DATADIR', datadir)
93 conf.set_quoted('DOCDIR', docdir)
94 conf.set_quoted('INCLUDEDIR', includedir)
95 conf.set_quoted('LIBDIR', libdir)
96 conf.set_quoted('LIBEXECDIR', libexecdir)
97 conf.set_quoted('LOCALSTATEDIR', localstatedir)
98 conf.set_quoted('RUNTIME_PATH', runtimepath)
99 conf.set_quoted('SBINDIR', sbindir)
100 conf.set_quoted('SYSCONFDIR', sysconfdir)
102 conf.set_quoted('APPARMOR_CACHE_DIR', lxcapparmorcachedir)
103 conf.set_quoted('LOGPATH', lxclogpath)
104 conf.set_quoted('LXCBINHOOKDIR', lxchookbindir)
105 conf.set_quoted('LXC_DEFAULT_CONFIG', lxcdefaultconfig)
106 conf.set_quoted('LXC_GLOBAL_CONF', lxcglobalconfig)
107 conf.set_quoted('LXCHOOKDIR', lxchookdir)
108 conf.set_quoted('LXCINITDIR', libexecdir)
109 conf.set_quoted('LXCPATH', lxcpath)
110 conf.set_quoted('LXCROOTFSMOUNT', lxcrootfsmount)
111 conf.set_quoted('LXCTEMPLATECONFIG', lxctemplateconfdir)
112 conf.set_quoted('LXCTEMPLATEDIR', lxctemplatedir)
113 conf.set_quoted('LXC_USERNIC_CONF', lxc_user_network_conf)
114 conf.set_quoted('LXC_USERNIC_DB', lxc_user_network_db)
116 # Custom configuration.
117 cgrouppattern = get_option('cgroup-pattern')
118 wants_io_uring = get_option('io-uring-event-loop')
119 want_examples = get_option('examples')
120 want_mans = get_option('man')
121 want_tests = get_option('tests')
123 conf.set_quoted('DEFAULT_CGROUP_PATTERN', cgrouppattern)
125 dummy_config_data = configuration_data()
126 dummy_config_data.set_quoted('DUMMY_VARIABLE', '1')
129 possible_cc_flags = [
131 '-Wimplicit-fallthrough=5',
133 '-Wstrict-prototypes',
134 '-fno-strict-aliasing',
135 '-fstack-clash-protection',
136 '-fstack-protector-strong',
137 '--param=ssp-buffer-size=4',
138 '--mcet -fcf-protection',
139 '-Werror=implicit-function-declaration',
141 '-Wmissing-include-dirs',
142 '-Wold-style-definition',
144 '-Wunused-but-set-variable',
145 '-Wno-unused-parameter',
147 '-Wsuggest-attribute=noreturn',
148 '-Werror=return-type',
149 '-Werror=incompatible-pointer-types',
154 '-fdiagnostics-show-option',
155 '-Werror=shift-count-overflow',
156 '-Werror=shift-overflow=2',
159 '-fasynchronous-unwind-tables',
163 '-Wreturn-local-addr',
165 '-Wstringop-overflow',
168 possible_link_flags = [
175 if meson.version().version_compare('>=0.46')
176 add_project_link_arguments(cc.get_supported_link_arguments(possible_link_flags), language: 'c')
178 add_project_link_arguments(possible_link_flags, language: 'c')
181 add_project_arguments(cc.get_supported_arguments(possible_cc_flags), language: 'c')
185 if wants_io_uring == true
186 liburing = dependency('liburing')
187 if cc.has_function('io_uring_prep_poll_add', prefix: '#include <liburing.h>', dependencies: liburing) == false
188 error('liburing version does not support IORING_POLL_ADD_MULTI')
191 conf.set10('HAVE_LIBURING', true)
195 sh = find_program('sh')
196 date = find_program('date')
197 git = find_program('git', required: false)
198 time_epoch = run_command(sh, '-c', 'echo "$SOURCE_DATE_EPOCH"', check: true).stdout().strip()
199 if time_epoch == '' and git.found() and run_command('test', '-e', '.git', check: false).returncode() == 0
200 # If we're in a git repository, use the creation time of the latest git tag.
201 latest_tag = run_command(git, 'describe', '--abbrev=0', '--tags', check: true).stdout().strip()
202 time_epoch = run_command(git, 'log', '--no-show-signature', '-1', '--format=%at', latest_tag, check: true).stdout()
204 # Fallback to current epoch
205 time_epoch = run_command(date, '+%s', check: true).stdout()
207 time_epoch = time_epoch.to_int()
208 conf.set('TIME_EPOCH', time_epoch)
211 threads = dependency('threads')
214 libseccomp = dependency('libseccomp')
215 conf.set10('HAVE_SECCOMP', libseccomp.found())
216 pkgconfig_libs += libseccomp
217 if libseccomp.found()
218 if libseccomp.version().version_compare('>=2.5.0')
219 # https://github.com/seccomp/libseccomp/commit/dead12bc788b259b148cc4d93b970ef0bd602b1a
220 conf.set10('HAVE_DECL_SECCOMP_NOTIFY_FD', true)
222 conf.set10('HAVE_DECL_SECCOMP_NOTIFY_FD', false)
225 if libseccomp.version().version_compare('>=2.0.0')
226 # https://github.com/seccomp/libseccomp/commit/6220c8c0fc479d97b6d3e3166a4e46fbfe25a3c0
227 conf.set10('HAVE_DECL_SECCOMP_SYSCALL_RESOLVE_NAME_ARCH', true)
229 conf.set10('HAVE_DECL_SECCOMP_SYSCALL_RESOLVE_NAME_ARCH', false)
232 seccomp_headers = '''
238 'struct seccomp_notif_sizes',
242 # We get -1 if the size cannot be determined
243 if cc.sizeof(decl, prefix: seccomp_headers, args: '-D_GNU_SOURCE') > 0
244 conf.set10('HAVE_' + decl.underscorify().to_upper(), true)
246 conf.set10('HAVE_' + decl.underscorify().to_upper(), false)
252 libselinux = dependency('libselinux', required: false)
253 conf.set10('HAVE_SELINUX', libselinux.found())
254 pkgconfig_libs += libselinux
257 libapparmor = dependency('libapparmor', required: false)
258 conf.set10('HAVE_APPARMOR', libapparmor.found())
261 libopenssl = dependency('openssl', required: false)
262 conf.set10('HAVE_OPENSSL', libopenssl.found())
263 pkgconfig_libs += libopenssl
266 libcap = dependency('libcap', required: false)
267 if not libcap.found()
268 # Compat with Ubuntu 14.04 which ships libcap w/o .pc file
269 libcap = cc.find_library('cap', required: false)
271 conf.set10('HAVE_LIBCAP', libcap.found())
272 pkgconfig_libs += libcap
274 libcap_static = dependency('libcap', required: false, static: true)
275 if not libcap_static.found()
276 # Compat with Ubuntu 14.04 which ships libcap w/o .pc file
277 libcap_static = cc.find_library('cap', required: false, static: true)
279 conf.set10('HAVE_STATIC_LIBCAP', libcap_static.found())
282 pam = cc.find_library('pam',
283 has_headers: 'security/pam_modules.h')
284 conf.set10('HAVE_PAM', pam.found())
285 pkgconfig_libs += pam
288 have = cc.has_function('strchrnul', prefix: '#include <string.h>', args: '-D_GNU_SOURCE')
289 conf.set10('HAVE_STRCHRNUL', have)
291 have = cc.has_function('openpty', prefix: '#include <pty.h>', args: '-D_GNU_SOURCE')
292 conf.set10('HAVE_OPENPTY', have)
294 ## Compiler attributes.
301 conf.set10('HAVE_COMPILER_ATTR_' + ccattr.underscorify().to_upper(), cc.has_function_attribute(ccattr))
306 missing_syscalls = []
333 ['pidfd_send_signal'],
349 if tuple.length() >= 2
352 ident1 = 'HAVE_' + tuple[0].underscorify().to_upper()
353 ident2 = 'ENABLE_' + tuple[0].underscorify().to_upper()
354 cond = conf.get(ident1, 0) == 1 or conf.get(ident2, 0) == 1
358 found_syscalls += tuple[0]
360 missing_syscalls += tuple[0]
367 #include <sys/mount.h>
368 #include <sys/stat.h>
369 #include <linux/fs.h>
370 #include <linux/types.h>
371 #include <linux/openat2.h>
372 #include <linux/sched.h>
382 # We get -1 if the size cannot be determined
383 if cc.sizeof(decl, prefix: decl_headers, args: '-D_GNU_SOURCE') > 0
384 conf.set10('HAVE_' + decl.underscorify().to_upper(), true)
386 conf.set10('HAVE_' + decl.underscorify().to_upper(), false)
394 ['struct seccomp_notif_sizes'],
395 ['struct clone_args'],
397 ['struct mount_attr'],
401 if tuple.length() >= 2
404 ident1 = 'HAVE_' + tuple[0].underscorify().to_upper()
405 ident2 = 'ENABLE_' + tuple[0].underscorify().to_upper()
406 cond = conf.get(ident1, 0) == 1 or conf.get(ident2, 0) == 1
410 found_types += tuple[0]
412 missing_types += tuple[0]
418 ['bpf', '''#include <sys/syscall.h>
419 #include <unistd.h>'''],
420 ['close_range', '''#include <unistd.h>'''],
421 ['execveat', '''#include <unistd.h>'''],
422 ['endmntent', '''#include <stdio.h>
423 #include <mntent.h>'''],
424 ['faccessat', '''#include <fcntl.h>
425 #include <unistd.h>'''],
426 ['fexecve', '''#include <unistd.h>'''],
427 ['fgetln', '''#include <stdio.h>'''],
428 ['fsconfig', '''#include <sys/mount.h>'''],
429 ['fsmount', '''#include <sys/mount.h>'''],
430 ['fsopen', '''#include <sys/mount.h>'''],
431 ['fspick', '''#include <sys/mount.h>'''],
432 ['getgrgid_r', '''#include <sys/types.h>
433 #include <grp.h>'''],
434 ['getline', '''#include <stdio.h>'''],
435 ['getsubopt', '''#include <stdlib.h>'''],
436 ['gettid', '''#include <sys/types.h>
437 #include <unistd.h>'''],
438 ['hasmntopt', '''#include <stdio.h>
439 #include <mntent.h>'''],
440 ['kcmp', '''#include <linux/kcmp.h>'''],
441 ['keyctl', '''#include <sys/types.h>
442 #include <keyutils.h>'''],
443 ['memfd_create', '''#include <sys/mman.h>'''],
444 ['mount_setattr', '''#include <sys/mount.h>'''],
445 ['move_mount', '''#include <sys/mount.h>'''],
446 ['openat2', '''#include <sys/types.h>
447 #include <sys/stat.h>
448 #include <fctnl.h>'''],
449 ['open_tree', '''#include <sys/mount.h>'''],
450 ['personality', '''#include <sys/personality.h>'''],
451 ['pidfd_open', '''#include <stdlib.h>
454 #include <sys/wait.h>'''],
455 ['pidfd_send_signal', '''#include <stdlib.h>
458 #include <sys/wait.h>'''],
459 ['pivot_root', '''#include <stdlib.h>
460 #include <unistd.h>'''], # no known header declares pivot_root
461 ['prlimit', '''#include <sys/time.h>
462 #include <sys/resource.h>'''],
463 ['prlimit64', '''#include <sys/time.h>
464 #include <sys/resource.h>'''],
465 ['renameat2', '''#include <stdio.h>
466 #include <fcntl.h>'''],
467 ['sethostname', '''#include <unistd.h>'''],
468 ['setmntent', '''#include <stdio.h>
469 #include <mntent.h>'''],
470 ['setns', '''#include <sched.h>'''],
471 ['sigdescr_np', '''#include <string.h>'''],
472 ['signalfd', '''#include <sys/signalfd.h>'''],
473 ['statx', '''#include <sys/types.h>
474 #include <sys/stat.h>
475 #include <unistd.h>'''],
476 ['strchrnul', '''#include <string.h>'''],
477 ['strlcat', '''#include <string.h>'''],
478 ['strlcpy', '''#include <string.h>'''],
479 ['unshare', '''#include <sched.h>'''],
482 have = cc.has_function(ident[0], prefix: ident[1], args: '-D_GNU_SOURCE')
483 conf.set10('HAVE_' + ident[0].to_upper(), have)
491 ['sys/personality.h'],
497 conf.set10('HAVE_' + tuple[0].underscorify().to_upper(), cc.has_header(tuple[0]))
499 if tuple.length() >= 2
502 ident1 = 'HAVE_' + tuple[0].underscorify().to_upper()
503 ident2 = 'ENABLE_' + tuple[0].underscorify().to_upper()
504 cond = conf.get(ident1, 0) == 1 or conf.get(ident2, 0) == 1
508 found_headers += tuple[0]
510 missing_headers += tuple[0]
527 if tuple.length() >= 2
530 ident1 = 'HAVE_' + tuple[0].underscorify().to_upper()
531 ident2 = 'ENABLE_' + tuple[0].underscorify().to_upper()
532 cond = conf.get(ident1, 0) == 1 or conf.get(ident2, 0) == 1
536 found_deps += tuple[0]
538 missing_deps += tuple[0]
543 config_h = configure_file(
547 add_project_arguments('-include', 'config.h', language: 'c')
553 template_scripts = []
557 basic_includes = include_directories(
562 liblxc_includes = [basic_includes, include_directories(
567 # Early sub-directories.
568 subdir('src/include')
572 liblxc_dependencies = [
581 if wants_io_uring == true
582 liblxc_dependencies += [liburing]
585 liblxc = shared_library(
587 version: liblxc_version,
588 include_directories: liblxc_includes,
589 link_args: ['-DPIC'],
591 link_whole: [liblxc_static],
592 dependencies: liblxc_dependencies,
595 liblxc_dep = declare_dependency(
597 dependencies: liblxc_dependencies)
599 # Rest of sub-directories.
600 subdir('config/bash')
602 subdir('config/init/common')
603 subdir('config/init/systemd')
604 subdir('config/selinux')
605 subdir('config/templates')
606 subdir('config/templates/common.conf.d')
608 subdir('doc/examples')
611 subdir('src/lxc/cmd')
612 subdir('src/lxc/tools')
613 subdir('src/lxc/tools/include')
618 pkg_config_file = pkgconfig.generate(liblxc,
619 description: 'linux container tools',
620 version: version_data.get('LXC_VERSION'),
621 url: 'http://linuxcontainers.org',
622 libraries: '-lutil -lpthread -ldl',
623 libraries_private: pkgconfig_libs,
627 install_emptydir(join_paths(localstatedir, 'cache', 'lxc'))
628 install_emptydir(join_paths(localstatedir, 'lib', 'lxc'))
632 '@0@ @1@'.format(meson.project_name(), meson.project_version()),
634 'Meson version: @0@'.format(meson.version()),
636 'prefix directory: @0@'.format(prefixdir),
637 'bin directory: @0@'.format(bindir),
638 'data directory: @0@'.format(datadir),
639 'doc directory: @0@'.format(docdir),
640 'include directory: @0@'.format(includedir),
641 'lib directory: @0@'.format(libdir),
642 'libexec directory: @0@'.format(libexecdir),
643 'local state directory: @0@'.format(localstatedir),
644 'sbin directory: @0@'.format(sbindir),
645 'sysconf directory: @0@'.format(sysconfdir),
647 'lxc cgroup pattern: @0@'.format(cgrouppattern),
648 'lxc init directory: @0@'.format(libexecdir),
649 'runtime path: @0@'.format(runtimepath),
651 'lxc default config: @0@'.format(lxcdefaultconfig),
652 'lxc global config: @0@'.format(lxcglobalconfig),
653 'lxc hook directory: @0@'.format(lxchookdir),
654 'lxc hook bin directory: @0@'.format(lxchookbindir),
655 'lxc rootfs mount directory: @0@'.format(lxcrootfsmount),
656 'log path: @0@'.format(lxclogpath),
657 'lxc path: @0@'.format(lxcpath),
658 'lxc template config: @0@'.format(lxctemplateconfdir),
659 'lxc template directory: @0@'.format(lxctemplatedir),
660 'lxc user network config: @0@'.format(lxc_user_network_conf),
661 'lxc user network database: @0@'.format(lxc_user_network_db)]
663 alt_time_epoch = run_command('date', '-Is', '-u', '-d',
664 '@@0@'.format(time_epoch), check: true).stdout().strip()
666 'time epoch: @0@ (@1@)'.format(time_epoch, alt_time_epoch)]
670 'supported dependencies: @0@'.format(', '.join(found_deps)),
672 'unsupported dependencies: @0@'.format(', '.join(missing_deps)),
677 'supported headers: @0@'.format(', '.join(found_headers)),
679 'unsupported headers: @0@'.format(', '.join(missing_headers)),
684 'supported calls: @0@'.format(', '.join(found_syscalls)),
686 'unsupported calls: @0@'.format(', '.join(missing_syscalls)),
691 'supported types: @0@'.format(', '.join(found_types)),
693 'unsupported types: @0@'.format(', '.join(missing_types)),
696 message('\n '.join(status))