1 # SPDX-License-Identifier: LGPL-2.1-or-later
19 meson_version: '>= 0.50')
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-dir')
52 globalconfig = get_option('global-config')
53 localstatedir = join_paths('/', get_option('localstatedir'))
54 logpath = get_option('log-path')
55 lxcpathprefix = get_option('config-path')
56 rootfsmount = get_option('rootfs-mount-dir')
57 user_network_db_opt = get_option('user-network-db')
58 user_network_conf_opt = get_option('user-network-conf')
60 bindir = join_paths(prefixdir, get_option('bindir'))
61 datadir = join_paths(prefixdir, get_option('datadir'))
62 docdir = join_paths(prefixdir, get_option('docdir'))
63 includedir = join_paths(prefixdir, get_option('includedir'))
64 libdir = join_paths(prefixdir, get_option('libdir'))
65 libexecdir = join_paths(prefixdir, get_option('libexecdir'))
66 runtimepath = join_paths(prefixdir, get_option('runtime-path'))
67 sbindir = join_paths(prefixdir, get_option('sbindir'))
68 sysconfdir = join_paths(prefixdir, get_option('sysconfdir'))
70 lxcdefaultconfig = join_paths(sysconfdir, 'lxc/default.conf')
71 lxcglobalconfig = join_paths(sysconfdir, globalconfig)
72 lxcapparmorcachedir = join_paths(localstatedir, apparmorcachedir)
73 lxcrootfsmount = join_paths(prefixdir, rootfsmount)
74 lxcinclude = join_paths(includedir, 'lxc')
75 lxclibexec = join_paths(libexecdir, 'lxc')
76 lxclogpath = join_paths(localstatedir, logpath)
77 lxcpath = join_paths(localstatedir, lxcpathprefix)
78 lxctemplateconfig = join_paths(datadir, 'lxc/config')
79 lxctemplatedir = join_paths(datadir, 'lxc/templates')
80 lxchookdir = join_paths(datadir, 'lxc/hooks')
81 lxchookbindir = join_paths(libexecdir, 'lxc/hooks')
82 lxc_user_network_conf = join_paths(sysconfdir, user_network_conf_opt)
83 lxc_user_network_db = join_paths(runtimepath, user_network_db_opt)
85 conf.set_quoted('BINDIR', bindir)
86 conf.set_quoted('DATADIR', datadir)
87 conf.set_quoted('DOCDIR', docdir)
88 conf.set_quoted('INCLUDEDIR', includedir)
89 conf.set_quoted('LIBDIR', libdir)
90 conf.set_quoted('LIBEXECDIR', libexecdir)
91 conf.set_quoted('LOCALSTATEDIR', localstatedir)
92 conf.set_quoted('RUNTIME_PATH', runtimepath)
93 conf.set_quoted('SBINDIR', sbindir)
94 conf.set_quoted('SYSCONFDIR', sysconfdir)
96 conf.set_quoted('APPARMOR_CACHE_DIR', lxcapparmorcachedir)
97 conf.set_quoted('LOGPATH', lxclogpath)
98 conf.set_quoted('LXCBINHOOKDIR', lxchookbindir)
99 conf.set_quoted('LXC_DEFAULT_CONFIG', lxcdefaultconfig)
100 conf.set_quoted('LXC_GLOBAL_CONF', lxcglobalconfig)
101 conf.set_quoted('LXCHOOKDIR', lxchookdir)
102 conf.set_quoted('LXCINITDIR', libexecdir)
103 conf.set_quoted('LXCPATH', lxcpath)
104 conf.set_quoted('LXCROOTFSMOUNT', lxcrootfsmount)
105 conf.set_quoted('LXCTEMPLATECONFIG', lxctemplateconfig)
106 conf.set_quoted('LXCTEMPLATEDIR', lxctemplatedir)
107 conf.set_quoted('LXC_USERNIC_CONF', lxc_user_network_conf)
108 conf.set_quoted('LXC_USERNIC_DB', lxc_user_network_db)
110 # Custom configuration.
111 cgrouppattern = get_option('cgroup-pattern')
112 wants_io_uring = get_option('io-uring-event-loop')
113 want_tests = get_option('tests')
115 conf.set_quoted('DEFAULT_CGROUP_PATTERN', cgrouppattern)
117 dummy_config_data = configuration_data()
118 dummy_config_data.set_quoted('DUMMY_VARIABLE', '1')
121 possible_cc_flags = [
123 '-Wimplicit-fallthrough=5',
125 '-Wstrict-prototypes',
126 '-fno-strict-aliasing',
127 '-fstack-clash-protection',
128 '-fstack-protector-strong',
129 '--param=ssp-buffer-size=4',
130 '--mcet -fcf-protection',
131 '-Werror=implicit-function-declaration',
133 '-Wmissing-include-dirs',
134 '-Wold-style-definition',
136 '-Wunused-but-set-variable',
137 '-Wno-unused-parameter',
139 '-Wsuggest-attribute=noreturn',
140 '-Werror=return-type',
141 '-Werror=incompatible-pointer-types',
146 '-fdiagnostics-show-option',
147 '-Werror=shift-count-overflow',
148 '-Werror=shift-overflow=2',
151 '-fasynchronous-unwind-tables',
155 '-Wreturn-local-addr',
157 '-Wstringop-overflow',
160 possible_link_flags = [
167 if meson.version().version_compare('>=0.46')
168 add_project_link_arguments(cc.get_supported_link_arguments(possible_link_flags), language: 'c')
170 add_project_link_arguments(possible_link_flags, language: 'c')
173 add_project_arguments(cc.get_supported_arguments(possible_cc_flags), language: 'c')
177 if wants_io_uring == true
178 liburing = dependency('liburing')
179 if cc.has_function('io_uring_prep_poll_add', prefix: '#include <liburing.h>', dependencies: liburing) == false
180 error('liburing version does not support IORING_POLL_ADD_MULTI')
183 conf.set10('HAVE_LIBURING', true)
187 sh = find_program('sh')
188 date = find_program('date')
189 git = find_program('git', required: false)
190 time_epoch = run_command(sh, '-c', 'echo "$SOURCE_DATE_EPOCH"', check: true).stdout().strip()
191 if time_epoch == '' and git.found() and run_command('test', '-e', '.git', check: false).returncode() == 0
192 # If we're in a git repository, use the creation time of the latest git tag.
193 latest_tag = run_command(git, 'describe', '--abbrev=0', '--tags', check: true).stdout().strip()
194 time_epoch = run_command(git, 'log', '--no-show-signature', '-1', '--format=%at', latest_tag, check: true).stdout()
196 # Fallback to current epoch
197 time_epoch = run_command(date, '+%s', check: true).stdout()
199 time_epoch = time_epoch.to_int()
200 conf.set('TIME_EPOCH', time_epoch)
203 threads = dependency('threads')
206 libseccomp = dependency('libseccomp')
207 conf.set10('HAVE_SECCOMP', libseccomp.found())
208 if libseccomp.found()
209 pkgconfig_libs += '-lseccomp'
211 if libseccomp.version().version_compare('>=2.5.0')
212 # https://github.com/seccomp/libseccomp/commit/dead12bc788b259b148cc4d93b970ef0bd602b1a
213 conf.set10('HAVE_DECL_SECCOMP_NOTIFY_FD', true)
215 conf.set10('HAVE_DECL_SECCOMP_NOTIFY_FD', false)
218 if libseccomp.version().version_compare('>=2.0.0')
219 # https://github.com/seccomp/libseccomp/commit/6220c8c0fc479d97b6d3e3166a4e46fbfe25a3c0
220 conf.set10('HAVE_DECL_SECCOMP_SYSCALL_RESOLVE_NAME_ARCH', true)
222 conf.set10('HAVE_DECL_SECCOMP_SYSCALL_RESOLVE_NAME_ARCH', false)
225 seccomp_headers = '''
231 'struct seccomp_notif_sizes',
235 # We get -1 if the size cannot be determined
236 if cc.sizeof(decl, prefix: seccomp_headers, args: '-D_GNU_SOURCE') > 0
237 conf.set10('HAVE_' + decl.underscorify().to_upper(), true)
239 conf.set10('HAVE_' + decl.underscorify().to_upper(), false)
245 libselinux = dependency('libselinux', required: false)
246 conf.set10('HAVE_SELINUX', libselinux.found())
247 if libselinux.found()
248 pkgconfig_libs += '-lselinux'
252 libapparmor = dependency('libapparmor', required: false)
253 conf.set10('HAVE_APPARMOR', libapparmor.found())
256 libopenssl = dependency('openssl', required: false)
257 conf.set10('HAVE_OPENSSL', libopenssl.found())
258 if libopenssl.found()
259 pkgconfig_libs += '-lssl -lcrypto'
263 libcap = dependency('libcap', required: false)
264 if not libcap.found()
265 # Compat with Ubuntu 14.04 which ships libcap w/o .pc file
266 libcap = cc.find_library('cap', required: false)
268 conf.set10('HAVE_LIBCAP', libcap.found())
270 pkgconfig_libs += '-lcap'
273 libcap_static = dependency('libcap', required: false, static: true)
274 if not libcap_static.found()
275 # Compat with Ubuntu 14.04 which ships libcap w/o .pc file
276 libcap_static = cc.find_library('cap', required: false, static: true)
278 conf.set10('HAVE_STATIC_LIBCAP', libcap_static.found())
281 pam = cc.find_library('pam',
282 has_headers: 'security/pam_modules.h')
283 conf.set10('HAVE_PAM', pam.found())
285 pkgconfig_libs += '-lpam'
289 have = cc.has_function('strchrnul', prefix: '#include <string.h>', args: '-D_GNU_SOURCE')
290 conf.set10('HAVE_STRCHRNUL', have)
292 have = cc.has_function('openpty', prefix: '#include <pty.h>', args: '-D_GNU_SOURCE')
293 conf.set10('HAVE_OPENPTY', have)
295 ## Compiler attributes.
302 conf.set10('HAVE_COMPILER_ATTR_' + ccattr.underscorify().to_upper(), cc.has_function_attribute(ccattr))
307 missing_syscalls = []
334 ['pidfd_send_signal'],
350 if tuple.length() >= 2
353 ident1 = 'HAVE_' + tuple[0].underscorify().to_upper()
354 ident2 = 'ENABLE_' + tuple[0].underscorify().to_upper()
355 cond = conf.get(ident1, 0) == 1 or conf.get(ident2, 0) == 1
359 found_syscalls += tuple[0]
361 missing_syscalls += tuple[0]
368 #include <sys/mount.h>
369 #include <sys/stat.h>
370 #include <linux/fs.h>
371 #include <linux/types.h>
372 #include <linux/openat2.h>
373 #include <linux/sched.h>
383 # We get -1 if the size cannot be determined
384 if cc.sizeof(decl, prefix: decl_headers, args: '-D_GNU_SOURCE') > 0
385 conf.set10('HAVE_' + decl.underscorify().to_upper(), true)
387 conf.set10('HAVE_' + decl.underscorify().to_upper(), false)
395 ['struct seccomp_notif_sizes'],
396 ['struct clone_args'],
398 ['struct mount_attr'],
402 if tuple.length() >= 2
405 ident1 = 'HAVE_' + tuple[0].underscorify().to_upper()
406 ident2 = 'ENABLE_' + tuple[0].underscorify().to_upper()
407 cond = conf.get(ident1, 0) == 1 or conf.get(ident2, 0) == 1
411 found_types += tuple[0]
413 missing_types += tuple[0]
419 ['bpf', '''#include <sys/syscall.h>
420 #include <unistd.h>'''],
421 ['close_range', '''#include <unistd.h>'''],
422 ['execveat', '''#include <unistd.h>'''],
423 ['endmntent', '''#include <stdio.h>
424 #include <mntent.h>'''],
425 ['faccessat', '''#include <fcntl.h>
426 #include <unistd.h>'''],
427 ['fexecve', '''#include <unistd.h>'''],
428 ['fgetln', '''#include <stdio.h>'''],
429 ['fsconfig', '''#include <sys/mount.h>'''],
430 ['fsmount', '''#include <sys/mount.h>'''],
431 ['fsopen', '''#include <sys/mount.h>'''],
432 ['fspick', '''#include <sys/mount.h>'''],
433 ['getgrgid_r', '''#include <sys/types.h>
434 #include <grp.h>'''],
435 ['getline', '''#include <stdio.h>'''],
436 ['getsubopt', '''#include <stdlib.h>'''],
437 ['gettid', '''#include <sys/types.h>
438 #include <unistd.h>'''],
439 ['hasmntopt', '''#include <stdio.h>
440 #include <mntent.h>'''],
441 ['kcmp', '''#include <linux/kcmp.h>'''],
442 ['keyctl', '''#include <sys/types.h>
443 #include <keyutils.h>'''],
444 ['memfd_create', '''#include <sys/mman.h>'''],
445 ['mount_setattr', '''#include <sys/mount.h>'''],
446 ['move_mount', '''#include <sys/mount.h>'''],
447 ['openat2', '''#include <sys/types.h>
448 #include <sys/stat.h>
449 #include <fctnl.h>'''],
450 ['open_tree', '''#include <sys/mount.h>'''],
451 ['personality', '''#include <sys/personality.h>'''],
452 ['pidfd_open', '''#include <stdlib.h>
455 #include <sys/wait.h>'''],
456 ['pidfd_send_signal', '''#include <stdlib.h>
459 #include <sys/wait.h>'''],
460 ['pivot_root', '''#include <stdlib.h>
461 #include <unistd.h>'''], # no known header declares pivot_root
462 ['prlimit', '''#include <sys/time.h>
463 #include <sys/resource.h>'''],
464 ['prlimit64', '''#include <sys/time.h>
465 #include <sys/resource.h>'''],
466 ['renameat2', '''#include <stdio.h>
467 #include <fcntl.h>'''],
468 ['sethostname', '''#include <unistd.h>'''],
469 ['setmntent', '''#include <stdio.h>
470 #include <mntent.h>'''],
471 ['setns', '''#include <sched.h>'''],
472 ['sigdescr_np', '''#include <string.h>'''],
473 ['signalfd', '''#include <sys/signalfd.h>'''],
474 ['statx', '''#include <sys/types.h>
475 #include <sys/stat.h>
476 #include <unistd.h>'''],
477 ['strchrnul', '''#include <string.h>'''],
478 ['strlcat', '''#include <string.h>'''],
479 ['strlcpy', '''#include <string.h>'''],
480 ['unshare', '''#include <sched.h>'''],
483 have = cc.has_function(ident[0], prefix: ident[1], args: '-D_GNU_SOURCE')
484 conf.set10('HAVE_' + ident[0].to_upper(), have)
492 ['sys/personality.h'],
498 conf.set10('HAVE_' + tuple[0].underscorify().to_upper(), cc.has_header(tuple[0]))
500 if tuple.length() >= 2
503 ident1 = 'HAVE_' + tuple[0].underscorify().to_upper()
504 ident2 = 'ENABLE_' + tuple[0].underscorify().to_upper()
505 cond = conf.get(ident1, 0) == 1 or conf.get(ident2, 0) == 1
509 found_headers += tuple[0]
511 missing_headers += tuple[0]
528 if tuple.length() >= 2
531 ident1 = 'HAVE_' + tuple[0].underscorify().to_upper()
532 ident2 = 'ENABLE_' + tuple[0].underscorify().to_upper()
533 cond = conf.get(ident1, 0) == 1 or conf.get(ident2, 0) == 1
537 found_deps += tuple[0]
539 missing_deps += tuple[0]
544 config_h = configure_file(
548 add_project_arguments('-include', 'config.h', language: 'c')
554 template_scripts = []
558 basic_includes = include_directories(
563 liblxc_includes = [basic_includes, include_directories(
568 # Early sub-directories.
569 subdir('src/include')
573 liblxc_dependencies = [
582 if wants_io_uring == true
583 liblxc_dependencies += [liburing]
586 liblxc = shared_library(
588 version: liblxc_version,
589 include_directories: liblxc_includes,
590 link_args: ['-DPIC'],
592 link_whole: [liblxc_static],
593 dependencies: liblxc_dependencies,
596 liblxc_dep = declare_dependency(
598 dependencies: liblxc_dependencies)
600 # Rest of sub-directories.
602 subdir('src/lxc/cmd')
603 subdir('src/lxc/tools')
604 subdir('src/lxc/tools/include')
609 pkg_config_file = pkgconfig.generate(liblxc,
610 description: 'linux container tools',
611 version: version_data.get('LXC_VERSION'),
612 url: 'http://linuxcontainers.org',
613 libraries: '-lutil -lpthread -ldl',
614 libraries_private: pkgconfig_libs,
615 install_dir: join_paths(libdir, 'pkgconfig')
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))