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 mandir = join_paths(prefixdir, get_option('mandir'))
64 docdir = join_paths(datadir, get_option('doc-path'))
65 includedir = join_paths(prefixdir, get_option('includedir'))
66 libdir = join_paths(prefixdir, get_option('libdir'))
67 libexecdir = join_paths(prefixdir, get_option('libexecdir'))
68 runtimepath = join_paths(prefixdir, get_option('runtime-path'))
69 sbindir = join_paths(prefixdir, get_option('sbindir'))
70 sysconfdir = join_paths(prefixdir, get_option('sysconfdir'))
72 lxcapparmorcachedir = join_paths(localstatedir, apparmorcachedir)
73 lxcconfdir = join_paths(sysconfdir, globalconfig)
74 lxcdefaultconfig = join_paths(lxcconfdir, 'default.conf')
75 lxcglobalconfig = join_paths(lxcconfdir, 'lxc.conf')
76 lxcexamplesdir = join_paths(docdir, 'examples')
77 lxchookbindir = join_paths(libexecdir, 'lxc/hooks')
78 lxcinclude = join_paths(includedir, 'lxc')
79 lxclibexec = join_paths(libexecdir, 'lxc')
80 lxclogpath = join_paths(localstatedir, logpath)
81 lxcpath = join_paths(localstatedir, lxcpathprefix)
82 lxcrootfsmount = join_paths(libdir, rootfsmount)
83 lxcdatadir = join_paths(datadir, 'lxc')
84 lxchookdir = join_paths(lxcdatadir, 'hooks')
85 lxcselinuxdir = join_paths(lxcdatadir, 'selinux')
86 lxctemplateconfdir = join_paths(lxcdatadir, 'config')
87 lxctemplateconfcommondir = join_paths(lxctemplateconfdir, 'common.conf.d')
88 lxctemplatedir = join_paths(lxcdatadir, 'templates')
89 lxc_user_network_conf = join_paths(sysconfdir, user_network_conf_opt)
90 lxc_user_network_db = join_paths(runtimepath, user_network_db_opt)
91 pam_security = join_paths(libdir, 'security')
93 conf.set_quoted('BINDIR', bindir)
94 conf.set_quoted('DATADIR', datadir)
95 conf.set_quoted('DOCDIR', docdir)
96 conf.set_quoted('INCLUDEDIR', includedir)
97 conf.set_quoted('LIBDIR', libdir)
98 conf.set_quoted('LIBEXECDIR', libexecdir)
99 conf.set_quoted('LOCALSTATEDIR', localstatedir)
100 conf.set_quoted('RUNTIME_PATH', runtimepath)
101 conf.set_quoted('SBINDIR', sbindir)
102 conf.set_quoted('SYSCONFDIR', sysconfdir)
104 conf.set_quoted('APPARMOR_CACHE_DIR', lxcapparmorcachedir)
105 conf.set_quoted('LOGPATH', lxclogpath)
106 conf.set_quoted('LXCBINHOOKDIR', lxchookbindir)
107 conf.set_quoted('LXC_DEFAULT_CONFIG', lxcdefaultconfig)
108 conf.set_quoted('LXC_GLOBAL_CONF', lxcglobalconfig)
109 conf.set_quoted('LXCHOOKDIR', lxchookdir)
110 conf.set_quoted('LXCINITDIR', libexecdir)
111 conf.set_quoted('LXCPATH', lxcpath)
112 conf.set_quoted('LXCROOTFSMOUNT', lxcrootfsmount)
113 conf.set_quoted('LXCTEMPLATECONFIG', lxctemplateconfdir)
114 conf.set_quoted('LXCTEMPLATEDIR', lxctemplatedir)
115 conf.set_quoted('LXC_USERNIC_CONF', lxc_user_network_conf)
116 conf.set_quoted('LXC_USERNIC_DB', lxc_user_network_db)
118 # Custom configuration.
119 cgrouppattern = get_option('cgroup-pattern')
120 init_script = get_option('init-script')
121 want_examples = get_option('examples')
122 want_io_uring = get_option('io-uring-event-loop')
123 want_pam_cgroup = get_option('pam-cgroup')
124 want_mans = get_option('man')
125 want_tests = get_option('tests')
126 want_tools = get_option('tools')
128 conf.set_quoted('DEFAULT_CGROUP_PATTERN', cgrouppattern)
130 dummy_config_data = configuration_data()
131 dummy_config_data.set_quoted('DUMMY_VARIABLE', '1')
134 possible_cc_flags = [
136 '-Wimplicit-fallthrough=5',
138 '-Wstrict-prototypes',
139 '-fno-strict-aliasing',
140 '-fstack-clash-protection',
141 '-fstack-protector-strong',
142 '--param=ssp-buffer-size=4',
143 '--mcet -fcf-protection',
144 '-Werror=implicit-function-declaration',
146 '-Wmissing-include-dirs',
147 '-Wold-style-definition',
149 '-Wunused-but-set-variable',
150 '-Wno-unused-parameter',
152 '-Wsuggest-attribute=noreturn',
153 '-Werror=return-type',
154 '-Werror=incompatible-pointer-types',
159 '-fdiagnostics-show-option',
160 '-Werror=shift-count-overflow',
161 '-Werror=shift-overflow=2',
164 '-fasynchronous-unwind-tables',
168 '-Wreturn-local-addr',
170 '-Wstringop-overflow',
173 possible_link_flags = [
180 if meson.version().version_compare('>=0.46')
181 add_project_link_arguments(cc.get_supported_link_arguments(possible_link_flags), language: 'c')
183 add_project_link_arguments(possible_link_flags, language: 'c')
186 add_project_arguments(cc.get_supported_arguments(possible_cc_flags), language: 'c')
191 liburing = dependency('liburing')
192 if cc.has_function('io_uring_prep_poll_add', prefix: '#include <liburing.h>', dependencies: liburing) == false
193 error('liburing version does not support IORING_POLL_ADD_MULTI')
196 conf.set10('HAVE_LIBURING', true)
200 sh = find_program('sh')
201 date = find_program('date')
202 git = find_program('git', required: false)
203 time_epoch = run_command(sh, '-c', 'echo "$SOURCE_DATE_EPOCH"', check: true).stdout().strip()
204 if time_epoch == '' and git.found() and run_command('test', '-e', '.git', check: false).returncode() == 0
205 # If we're in a git repository, use the creation time of the latest git tag.
206 latest_tag = run_command(git, 'describe', '--abbrev=0', '--tags', check: true).stdout().strip()
207 time_epoch = run_command(git, 'log', '--no-show-signature', '-1', '--format=%at', latest_tag, check: true).stdout()
209 # Fallback to current epoch
210 time_epoch = run_command(date, '+%s', check: true).stdout()
212 generate_date = run_command(date, '--utc', '--date=@' + time_epoch, '+%Y-%m-%d', check: true).stdout().strip()
213 time_epoch = time_epoch.to_int()
214 conf.set('TIME_EPOCH', time_epoch)
217 sgml2man = find_program('docbook2X2man', 'docbook2x-man', 'db2x_docbook2man', 'docbook2man', 'docbook-to-man', required: want_mans)
218 docbook2man = find_program('docbook2man', required: false)
220 docconf = configuration_data()
221 docconf.set('builddir', '.')
222 docconf.set('LXC_GENERATE_DATE', generate_date)
223 docconf.set('PACKAGE_VERSION', version_data.get('LXC_VERSION'))
224 if sgml2man.found() and docbook2man.found() and sgml2man.full_path() == docbook2man.full_path()
225 docconf.set('docdtd', '"-//Davenport//DTD DocBook V3.0//EN"')
227 docconf.set('docdtd', '"-//OASIS//DTD DocBook XML" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd"')
231 threads = dependency('threads')
234 libseccomp = dependency('libseccomp')
235 conf.set10('HAVE_SECCOMP', libseccomp.found())
236 pkgconfig_libs += libseccomp
237 if libseccomp.found()
238 if libseccomp.version().version_compare('>=2.5.0')
239 # https://github.com/seccomp/libseccomp/commit/dead12bc788b259b148cc4d93b970ef0bd602b1a
240 conf.set10('HAVE_DECL_SECCOMP_NOTIFY_FD', true)
242 conf.set10('HAVE_DECL_SECCOMP_NOTIFY_FD', false)
245 if libseccomp.version().version_compare('>=2.0.0')
246 # https://github.com/seccomp/libseccomp/commit/6220c8c0fc479d97b6d3e3166a4e46fbfe25a3c0
247 conf.set10('HAVE_DECL_SECCOMP_SYSCALL_RESOLVE_NAME_ARCH', true)
249 conf.set10('HAVE_DECL_SECCOMP_SYSCALL_RESOLVE_NAME_ARCH', false)
252 seccomp_headers = '''
258 'struct seccomp_notif_sizes',
262 # We get -1 if the size cannot be determined
263 if cc.sizeof(decl, prefix: seccomp_headers, args: '-D_GNU_SOURCE') > 0
264 conf.set10('HAVE_' + decl.underscorify().to_upper(), true)
266 conf.set10('HAVE_' + decl.underscorify().to_upper(), false)
272 libselinux = dependency('libselinux', required: false)
273 conf.set10('HAVE_SELINUX', libselinux.found())
274 pkgconfig_libs += libselinux
277 libapparmor = dependency('libapparmor', required: false)
278 conf.set10('HAVE_APPARMOR', libapparmor.found())
281 libopenssl = dependency('openssl', required: false)
282 conf.set10('HAVE_OPENSSL', libopenssl.found())
283 pkgconfig_libs += libopenssl
286 libcap = dependency('libcap', required: false)
287 if not libcap.found()
288 # Compat with Ubuntu 14.04 which ships libcap w/o .pc file
289 libcap = cc.find_library('cap', required: false)
291 conf.set10('HAVE_LIBCAP', libcap.found())
292 pkgconfig_libs += libcap
294 libcap_static = dependency('libcap', required: false, static: true)
295 if not libcap_static.found()
296 # Compat with Ubuntu 14.04 which ships libcap w/o .pc file
297 libcap_static = cc.find_library('cap', required: false, static: true)
299 conf.set10('HAVE_STATIC_LIBCAP', libcap_static.found())
302 pam = cc.find_library('pam', has_headers: 'security/pam_modules.h', required: want_pam_cgroup)
303 conf.set10('HAVE_PAM', pam.found())
304 pkgconfig_libs += pam
307 have = cc.has_function('strchrnul', prefix: '#include <string.h>', args: '-D_GNU_SOURCE')
308 conf.set10('HAVE_STRCHRNUL', have)
310 have = cc.has_function('openpty', prefix: '#include <pty.h>', args: '-D_GNU_SOURCE')
311 conf.set10('HAVE_OPENPTY', have)
313 ## Compiler attributes.
320 conf.set10('HAVE_COMPILER_ATTR_' + ccattr.underscorify().to_upper(), cc.has_function_attribute(ccattr))
325 missing_syscalls = []
352 ['pidfd_send_signal'],
368 if tuple.length() >= 2
371 ident1 = 'HAVE_' + tuple[0].underscorify().to_upper()
372 ident2 = 'ENABLE_' + tuple[0].underscorify().to_upper()
373 cond = conf.get(ident1, 0) == 1 or conf.get(ident2, 0) == 1
377 found_syscalls += tuple[0]
379 missing_syscalls += tuple[0]
386 #include <sys/mount.h>
387 #include <sys/stat.h>
388 #include <linux/fs.h>
389 #include <linux/types.h>
390 #include <linux/openat2.h>
391 #include <linux/sched.h>
401 # We get -1 if the size cannot be determined
402 if cc.sizeof(decl, prefix: decl_headers, args: '-D_GNU_SOURCE') > 0
403 conf.set10('HAVE_' + decl.underscorify().to_upper(), true)
405 conf.set10('HAVE_' + decl.underscorify().to_upper(), false)
413 ['struct seccomp_notif_sizes'],
414 ['struct clone_args'],
416 ['struct mount_attr'],
420 if tuple.length() >= 2
423 ident1 = 'HAVE_' + tuple[0].underscorify().to_upper()
424 ident2 = 'ENABLE_' + tuple[0].underscorify().to_upper()
425 cond = conf.get(ident1, 0) == 1 or conf.get(ident2, 0) == 1
429 found_types += tuple[0]
431 missing_types += tuple[0]
437 ['bpf', '''#include <sys/syscall.h>
438 #include <unistd.h>'''],
439 ['close_range', '''#include <unistd.h>'''],
440 ['execveat', '''#include <unistd.h>'''],
441 ['endmntent', '''#include <stdio.h>
442 #include <mntent.h>'''],
443 ['faccessat', '''#include <fcntl.h>
444 #include <unistd.h>'''],
445 ['fexecve', '''#include <unistd.h>'''],
446 ['fgetln', '''#include <stdio.h>'''],
447 ['fsconfig', '''#include <sys/mount.h>'''],
448 ['fsmount', '''#include <sys/mount.h>'''],
449 ['fsopen', '''#include <sys/mount.h>'''],
450 ['fspick', '''#include <sys/mount.h>'''],
451 ['getgrgid_r', '''#include <sys/types.h>
452 #include <grp.h>'''],
453 ['getline', '''#include <stdio.h>'''],
454 ['getsubopt', '''#include <stdlib.h>'''],
455 ['gettid', '''#include <sys/types.h>
456 #include <unistd.h>'''],
457 ['hasmntopt', '''#include <stdio.h>
458 #include <mntent.h>'''],
459 ['kcmp', '''#include <linux/kcmp.h>'''],
460 ['keyctl', '''#include <sys/types.h>
461 #include <keyutils.h>'''],
462 ['memfd_create', '''#include <sys/mman.h>'''],
463 ['mount_setattr', '''#include <sys/mount.h>'''],
464 ['move_mount', '''#include <sys/mount.h>'''],
465 ['openat2', '''#include <sys/types.h>
466 #include <sys/stat.h>
467 #include <fctnl.h>'''],
468 ['open_tree', '''#include <sys/mount.h>'''],
469 ['personality', '''#include <sys/personality.h>'''],
470 ['pidfd_open', '''#include <stdlib.h>
473 #include <sys/wait.h>'''],
474 ['pidfd_send_signal', '''#include <stdlib.h>
477 #include <sys/wait.h>'''],
478 ['pivot_root', '''#include <stdlib.h>
479 #include <unistd.h>'''], # no known header declares pivot_root
480 ['prlimit', '''#include <sys/time.h>
481 #include <sys/resource.h>'''],
482 ['prlimit64', '''#include <sys/time.h>
483 #include <sys/resource.h>'''],
484 ['renameat2', '''#include <stdio.h>
485 #include <fcntl.h>'''],
486 ['sethostname', '''#include <unistd.h>'''],
487 ['setmntent', '''#include <stdio.h>
488 #include <mntent.h>'''],
489 ['setns', '''#include <sched.h>'''],
490 ['sigdescr_np', '''#include <string.h>'''],
491 ['signalfd', '''#include <sys/signalfd.h>'''],
492 ['statx', '''#include <sys/types.h>
493 #include <sys/stat.h>
494 #include <unistd.h>'''],
495 ['strchrnul', '''#include <string.h>'''],
496 ['strlcat', '''#include <string.h>'''],
497 ['strlcpy', '''#include <string.h>'''],
498 ['unshare', '''#include <sched.h>'''],
501 have = cc.has_function(ident[0], prefix: ident[1], args: '-D_GNU_SOURCE')
502 conf.set10('HAVE_' + ident[0].to_upper(), have)
510 ['sys/personality.h'],
516 conf.set10('HAVE_' + tuple[0].underscorify().to_upper(), cc.has_header(tuple[0]))
518 if tuple.length() >= 2
521 ident1 = 'HAVE_' + tuple[0].underscorify().to_upper()
522 ident2 = 'ENABLE_' + tuple[0].underscorify().to_upper()
523 cond = conf.get(ident1, 0) == 1 or conf.get(ident2, 0) == 1
527 found_headers += tuple[0]
529 missing_headers += tuple[0]
547 if tuple.length() >= 2
550 ident1 = 'HAVE_' + tuple[0].underscorify().to_upper()
551 ident2 = 'ENABLE_' + tuple[0].underscorify().to_upper()
552 cond = conf.get(ident1, 0) == 1 or conf.get(ident2, 0) == 1
556 found_deps += tuple[0]
558 missing_deps += tuple[0]
563 config_h = configure_file(
567 add_project_arguments('-include', 'config.h', language: 'c')
573 template_scripts = []
577 basic_includes = include_directories(
582 liblxc_includes = [basic_includes, include_directories(
587 # Early sub-directories.
588 subdir('src/include')
590 subdir('src/lxc/pam')
593 liblxc_dependencies = [
603 liblxc_dependencies += [liburing]
606 liblxc = shared_library(
608 version: liblxc_version,
609 include_directories: liblxc_includes,
610 link_args: ['-DPIC'],
612 link_whole: [liblxc_static],
613 dependencies: liblxc_dependencies,
616 liblxc_dep = declare_dependency(
618 dependencies: liblxc_dependencies)
620 # Rest of sub-directories.
621 subdir('config/bash')
623 subdir('config/init/common')
624 subdir('config/init/systemd')
625 subdir('config/init/sysvinit')
626 subdir('config/init/upstart')
627 subdir('config/selinux')
628 subdir('config/sysconfig')
629 subdir('config/templates')
630 subdir('config/templates/common.conf.d')
635 subdir('doc/examples')
638 subdir('src/lxc/cmd')
639 subdir('src/lxc/tools')
640 subdir('src/lxc/tools/include')
645 pkg_config_file = pkgconfig.generate(liblxc,
646 description: 'linux container tools',
647 version: version_data.get('LXC_VERSION'),
648 url: 'http://linuxcontainers.org',
649 libraries: '-lutil -lpthread -ldl',
650 libraries_private: pkgconfig_libs,
654 install_emptydir(join_paths(localstatedir, 'cache', 'lxc'))
655 install_emptydir(join_paths(localstatedir, 'lib', 'lxc'))
659 '@0@ @1@'.format(meson.project_name(), meson.project_version()),
661 'Meson version: @0@'.format(meson.version()),
663 'prefix directory: @0@'.format(prefixdir),
664 'bin directory: @0@'.format(bindir),
665 'data directory: @0@'.format(datadir),
666 'doc directory: @0@'.format(docdir),
667 'include directory: @0@'.format(includedir),
668 'lib directory: @0@'.format(libdir),
669 'libexec directory: @0@'.format(libexecdir),
670 'local state directory: @0@'.format(localstatedir),
671 'sbin directory: @0@'.format(sbindir),
672 'sysconf directory: @0@'.format(sysconfdir),
674 'lxc cgroup pattern: @0@'.format(cgrouppattern),
675 'lxc init directory: @0@'.format(libexecdir),
676 'runtime path: @0@'.format(runtimepath),
678 'lxc default config: @0@'.format(lxcdefaultconfig),
679 'lxc global config: @0@'.format(lxcglobalconfig),
680 'lxc hook directory: @0@'.format(lxchookdir),
681 'lxc hook bin directory: @0@'.format(lxchookbindir),
682 'lxc rootfs mount directory: @0@'.format(lxcrootfsmount),
683 'log path: @0@'.format(lxclogpath),
684 'lxc path: @0@'.format(lxcpath),
685 'lxc template config: @0@'.format(lxctemplateconfdir),
686 'lxc template directory: @0@'.format(lxctemplatedir),
687 'lxc user network config: @0@'.format(lxc_user_network_conf),
688 'lxc user network database: @0@'.format(lxc_user_network_db)]
690 alt_time_epoch = run_command('date', '-Is', '-u', '-d',
691 '@@0@'.format(time_epoch), check: true).stdout().strip()
693 'time epoch: @0@ (@1@)'.format(time_epoch, alt_time_epoch)]
697 'supported dependencies: @0@'.format(', '.join(found_deps)),
699 'unsupported dependencies: @0@'.format(', '.join(missing_deps)),
704 'supported headers: @0@'.format(', '.join(found_headers)),
706 'unsupported headers: @0@'.format(', '.join(missing_headers)),
711 'supported calls: @0@'.format(', '.join(found_syscalls)),
713 'unsupported calls: @0@'.format(', '.join(missing_syscalls)),
718 'supported types: @0@'.format(', '.join(found_types)),
720 'unsupported types: @0@'.format(', '.join(missing_types)),
723 message('\n '.join(status))