]> git.proxmox.com Git - mirror_lxc.git/blame - meson.build
meson: Always define HAVE_LIBURING
[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
SG
130# Cross-compile on Android.
131if host_machine.system() == 'android'
132 srcconf.set10('IS_BIONIC', true)
133endif
134
20b03401
SG
135# Custom configuration.
136cgrouppattern = get_option('cgroup-pattern')
4dd5e0cf 137coverity = get_option('coverity-build')
8131bb44 138init_script = get_option('init-script')
5055c73d 139sanitize = get_option('b_sanitize')
7609de18 140want_examples = get_option('examples')
7d8a38b2 141want_io_uring = get_option('io-uring-event-loop')
8c48813a 142want_pam_cgroup = get_option('pam-cgroup')
7609de18 143want_mans = get_option('man')
20b03401 144want_tests = get_option('tests')
b3d18992 145want_tools = get_option('tools')
20b03401 146
eba7f7a6 147srcconf.set_quoted('DEFAULT_CGROUP_PATTERN', cgrouppattern)
4dd5e0cf
SG
148if coverity
149 srcconf.set('ENABLE_COVERITY_BUILD', 1)
150endif
9b9d56e6 151
20b03401
SG
152dummy_config_data = configuration_data()
153dummy_config_data.set_quoted('DUMMY_VARIABLE', '1')
9b9d56e6 154
20b03401 155# Build flags.
9b9d56e6 156possible_cc_flags = [
20b03401
SG
157 '-Wvla',
158 '-Wimplicit-fallthrough=5',
159 '-Wcast-align',
160 '-Wstrict-prototypes',
161 '-fno-strict-aliasing',
162 '-fstack-clash-protection',
163 '-fstack-protector-strong',
164 '--param=ssp-buffer-size=4',
165 '--mcet -fcf-protection',
166 '-Werror=implicit-function-declaration',
167 '-Wlogical-op',
168 '-Wmissing-include-dirs',
169 '-Wold-style-definition',
170 '-Winit-self',
171 '-Wunused-but-set-variable',
172 '-Wno-unused-parameter',
173 '-Wfloat-equal',
174 '-Wsuggest-attribute=noreturn',
175 '-Werror=return-type',
176 '-Werror=incompatible-pointer-types',
177 '-Wformat=2',
178 '-Wshadow',
179 '-Wendif-labels',
180 '-Werror=overflow',
181 '-fdiagnostics-show-option',
182 '-Werror=shift-count-overflow',
183 '-Werror=shift-overflow=2',
184 '-Wdate-time',
185 '-Wnested-externs',
186 '-fasynchronous-unwind-tables',
187 '-fexceptions',
188 '-Warray-bounds',
189 '-Wrestrict',
190 '-Wreturn-local-addr',
191 '-fsanitize=cfi',
192 '-Wstringop-overflow',
9b9d56e6
CB
193]
194
195possible_link_flags = [
20b03401
SG
196 '-Wl,--gc-sections',
197 '-Wl,-z,relro',
198 '-Wl,-z,now',
199 '-Wl,-fuse-ld=gold',
9b9d56e6
CB
200]
201
202if meson.version().version_compare('>=0.46')
20b03401 203 add_project_link_arguments(cc.get_supported_link_arguments(possible_link_flags), language: 'c')
9b9d56e6 204else
20b03401 205 add_project_link_arguments(possible_link_flags, language: 'c')
9b9d56e6
CB
206endif
207
20b03401 208add_project_arguments(cc.get_supported_arguments(possible_cc_flags), language: 'c')
9b9d56e6 209
20b03401
SG
210# Feature detection
211## I/O uring.
7d8a38b2 212if want_io_uring
20b03401
SG
213 liburing = dependency('liburing')
214 if cc.has_function('io_uring_prep_poll_add', prefix: '#include <liburing.h>', dependencies: liburing) == false
215 error('liburing version does not support IORING_POLL_ADD_MULTI')
216 endif
217
eba7f7a6 218 srcconf.set10('HAVE_LIBURING', true)
4c96107d
SG
219else
220 srcconf.set10('HAVE_LIBURING', false)
747bc634
CB
221endif
222
20b03401 223## Time EPOCH.
ea6da257 224sh = find_program('sh')
23ba778f 225date = find_program('date')
20b03401 226git = find_program('git', required: false)
aa326e18
SG
227time_epoch = run_command(sh, '-c', 'echo "$SOURCE_DATE_EPOCH"', check: true).stdout().strip()
228if time_epoch == '' and git.found() and run_command('test', '-e', '.git', check: false).returncode() == 0
20b03401 229 # If we're in a git repository, use the creation time of the latest git tag.
f7de7d7a
SG
230 latest_tag = run_command(git, 'describe', '--abbrev=0', '--tags', check: false).stdout().strip()
231 if latest_tag != ''
232 time_epoch = run_command(git, 'log', '--no-show-signature', '-1', '--format=%at', latest_tag, check: true).stdout()
233 endif
234endif
235
236# Fallback to current epoch.
237if time_epoch == ''
23ba778f 238 time_epoch = run_command(date, '+%s', check: true).stdout()
ea6da257 239endif
47c56c50 240generate_date = run_command(date, '--utc', '--date=@' + time_epoch, '+%Y-%m-%d', check: true).stdout().strip()
ea6da257 241
2bd9ab6f 242## Manpages.
4412d151 243sgml2man = find_program('docbook2X2man', 'docbook2x-man', 'db2x_docbook2man', 'docbook2man', 'docbook-to-man', required: want_mans)
2bd9ab6f
SG
244docbook2man = find_program('docbook2man', required: false)
245
246docconf = configuration_data()
247docconf.set('builddir', '.')
f80af4e1
SG
248docconf.set('BINDIR', bindir)
249docconf.set('DATADIR', datadir)
250docconf.set('DOCDIR', docdir)
251docconf.set('LOGPATH', lxclogpath)
252docconf.set('LXC_DEFAULT_CONFIG', lxcdefaultconfig)
2bd9ab6f 253docconf.set('LXC_GENERATE_DATE', generate_date)
f80af4e1
SG
254docconf.set('LXC_GLOBAL_CONF', lxcglobalconfig)
255docconf.set('LXCPATH', lxcpath)
256docconf.set('LXCTEMPLATEDIR', lxctemplatedir)
257docconf.set('LXC_USERNIC_CONF', lxc_user_network_conf)
258docconf.set('LXC_USERNIC_DB', lxc_user_network_db)
2bd9ab6f
SG
259docconf.set('PACKAGE_VERSION', version_data.get('LXC_VERSION'))
260if sgml2man.found() and docbook2man.found() and sgml2man.full_path() == docbook2man.full_path()
261 docconf.set('docdtd', '"-//Davenport//DTD DocBook V3.0//EN"')
262else
263 docconf.set('docdtd', '"-//OASIS//DTD DocBook XML" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd"')
264endif
265
20b03401 266## Threads.
9b9d56e6 267threads = dependency('threads')
20b03401
SG
268
269## Seccomp.
869deb91 270libseccomp = dependency('libseccomp', required: false)
eba7f7a6 271srcconf.set10('HAVE_SECCOMP', libseccomp.found())
181cd6dc 272pkgconfig_libs += libseccomp
9b9d56e6 273if libseccomp.found()
20b03401
SG
274 if libseccomp.version().version_compare('>=2.5.0')
275 # https://github.com/seccomp/libseccomp/commit/dead12bc788b259b148cc4d93b970ef0bd602b1a
eba7f7a6 276 srcconf.set10('HAVE_DECL_SECCOMP_NOTIFY_FD', true)
20b03401 277 else
eba7f7a6 278 srcconf.set10('HAVE_DECL_SECCOMP_NOTIFY_FD', false)
20b03401
SG
279 endif
280
281 if libseccomp.version().version_compare('>=2.0.0')
282 # https://github.com/seccomp/libseccomp/commit/6220c8c0fc479d97b6d3e3166a4e46fbfe25a3c0
eba7f7a6 283 srcconf.set10('HAVE_DECL_SECCOMP_SYSCALL_RESOLVE_NAME_ARCH', true)
20b03401 284 else
eba7f7a6 285 srcconf.set10('HAVE_DECL_SECCOMP_SYSCALL_RESOLVE_NAME_ARCH', false)
20b03401
SG
286 endif
287
288 seccomp_headers = '''
289 #include <seccomp.h>
290 '''
291
292 foreach decl: [
293 'scmp_filter_ctx',
294 'struct seccomp_notif_sizes',
295 'struct clone_args',
296 ]
297
298 # We get -1 if the size cannot be determined
299 if cc.sizeof(decl, prefix: seccomp_headers, args: '-D_GNU_SOURCE') > 0
eba7f7a6 300 srcconf.set10('HAVE_' + decl.underscorify().to_upper(), true)
20b03401 301 else
eba7f7a6 302 srcconf.set10('HAVE_' + decl.underscorify().to_upper(), false)
20b03401
SG
303 endif
304 endforeach
9b9d56e6
CB
305endif
306
20b03401
SG
307## SELinux.
308libselinux = dependency('libselinux', required: false)
eba7f7a6 309srcconf.set10('HAVE_SELINUX', libselinux.found())
181cd6dc 310pkgconfig_libs += libselinux
9b9d56e6 311
20b03401
SG
312## AppArmor.
313libapparmor = dependency('libapparmor', required: false)
eba7f7a6 314srcconf.set10('HAVE_APPARMOR', libapparmor.found())
9b9d56e6 315
20b03401
SG
316## OpenSSL.
317libopenssl = dependency('openssl', required: false)
eba7f7a6 318srcconf.set10('HAVE_OPENSSL', libopenssl.found())
181cd6dc 319pkgconfig_libs += libopenssl
9b9d56e6 320
20b03401
SG
321## Libcap..
322libcap = dependency('libcap', required: false)
9b9d56e6 323if not libcap.found()
20b03401
SG
324 # Compat with Ubuntu 14.04 which ships libcap w/o .pc file
325 libcap = cc.find_library('cap', required: false)
9b9d56e6 326endif
eba7f7a6 327srcconf.set10('HAVE_LIBCAP', libcap.found())
181cd6dc 328pkgconfig_libs += libcap
9b9d56e6 329
20b03401 330libcap_static = dependency('libcap', required: false, static: true)
d0a16061 331if not libcap_static.found()
20b03401
SG
332 # Compat with Ubuntu 14.04 which ships libcap w/o .pc file
333 libcap_static = cc.find_library('cap', required: false, static: true)
d0a16061 334endif
eba7f7a6 335srcconf.set10('HAVE_STATIC_LIBCAP', libcap_static.found())
d0a16061 336
0860988e 337## PAM.
8c48813a 338pam = cc.find_library('pam', has_headers: 'security/pam_modules.h', required: want_pam_cgroup)
eba7f7a6 339srcconf.set10('HAVE_PAM', pam.found())
181cd6dc 340pkgconfig_libs += pam
0860988e 341
20b03401
SG
342## Others.
343have = cc.has_function('strchrnul', prefix: '#include <string.h>', args: '-D_GNU_SOURCE')
eba7f7a6 344srcconf.set10('HAVE_STRCHRNUL', have)
db4af8c5 345
20b03401 346have = cc.has_function('openpty', prefix: '#include <pty.h>', args: '-D_GNU_SOURCE')
eba7f7a6 347srcconf.set10('HAVE_OPENPTY', have)
db4af8c5 348
20b03401
SG
349## Compiler attributes.
350foreach ccattr: [
351 'fallthrough',
352 'nonnull',
353 'returns_nonnull',
354]
ae13cb3b 355
eba7f7a6 356 srcconf.set10('HAVE_COMPILER_ATTR_' + ccattr.underscorify().to_upper(), cc.has_function_attribute(ccattr))
ae13cb3b 357endforeach
5c26176d 358
20b03401 359## Syscalls.
ea6da257
CB
360found_syscalls = []
361missing_syscalls = []
20b03401
SG
362foreach tuple: [
363 ['bpf'],
364 ['close_range'],
365 ['endmntent'],
366 ['execveat'],
367 ['faccessat'],
368 ['strchrnul'],
369 ['fgetln'],
370 ['fsconfig'],
371 ['fsmount'],
372 ['fsopen'],
373 ['fspick'],
374 ['getgrgid_r'],
375 ['getline'],
376 ['getsubopt'],
377 ['gettid'],
378 ['hasmntopt'],
379 ['kcmp'],
380 ['keyctl'],
381 ['memfd_create'],
382 ['mount_setattr'],
383 ['move_mount'],
384 ['openat2'],
385 ['open_tree'],
386 ['personality'],
387 ['pidfd_open'],
388 ['pidfd_send_signal'],
389 ['pivot_root'],
390 ['prlimit'],
391 ['prlimit64'],
392 ['renameat2'],
393 ['sethostname'],
394 ['setmntent'],
395 ['setns'],
396 ['sigdescr_np'],
397 ['signalfd'],
398 ['statx'],
399 ['strlcat'],
400 ['strlcpy'],
401 ['unshare'],
402]
403
404 if tuple.length() >= 2
405 cond = tuple[1]
406 else
407 ident1 = 'HAVE_' + tuple[0].underscorify().to_upper()
408 ident2 = 'ENABLE_' + tuple[0].underscorify().to_upper()
eba7f7a6 409 cond = srcconf.get(ident1, 0) == 1 or srcconf.get(ident2, 0) == 1
20b03401
SG
410 endif
411
412 if cond
413 found_syscalls += tuple[0]
414 else
415 missing_syscalls += tuple[0]
416 endif
417endforeach
418
419## Types.
420decl_headers = '''
421#include <uchar.h>
422#include <sys/mount.h>
423#include <sys/stat.h>
424#include <linux/fs.h>
425#include <linux/types.h>
426#include <linux/openat2.h>
427#include <linux/sched.h>
428'''
ea6da257 429
20b03401
SG
430foreach decl: [
431 '__aligned_u64',
432 'struct mount_attr',
433 'struct open_how',
434 'struct clone_args',
ea6da257
CB
435]
436
20b03401
SG
437 # We get -1 if the size cannot be determined
438 if cc.sizeof(decl, prefix: decl_headers, args: '-D_GNU_SOURCE') > 0
eba7f7a6 439 srcconf.set10('HAVE_' + decl.underscorify().to_upper(), true)
20b03401 440 else
eba7f7a6 441 srcconf.set10('HAVE_' + decl.underscorify().to_upper(), false)
20b03401 442 endif
ea6da257
CB
443endforeach
444
445found_types = []
446missing_types = []
20b03401
SG
447foreach tuple: [
448 ['scmp_filter_ctx'],
449 ['struct seccomp_notif_sizes'],
450 ['struct clone_args'],
451 ['__aligned_u64'],
452 ['struct mount_attr'],
453 ['struct open_how'],
454]
ea6da257 455
20b03401
SG
456 if tuple.length() >= 2
457 cond = tuple[1]
458 else
459 ident1 = 'HAVE_' + tuple[0].underscorify().to_upper()
460 ident2 = 'ENABLE_' + tuple[0].underscorify().to_upper()
eba7f7a6 461 cond = srcconf.get(ident1, 0) == 1 or srcconf.get(ident2, 0) == 1
20b03401
SG
462 endif
463
464 if cond
465 found_types += tuple[0]
466 else
467 missing_types += tuple[0]
468 endif
469endforeach
470
471## Headers.
472foreach ident: [
473 ['bpf', '''#include <sys/syscall.h>
474 #include <unistd.h>'''],
475 ['close_range', '''#include <unistd.h>'''],
476 ['execveat', '''#include <unistd.h>'''],
477 ['endmntent', '''#include <stdio.h>
478 #include <mntent.h>'''],
479 ['faccessat', '''#include <fcntl.h>
480 #include <unistd.h>'''],
481 ['fexecve', '''#include <unistd.h>'''],
482 ['fgetln', '''#include <stdio.h>'''],
483 ['fsconfig', '''#include <sys/mount.h>'''],
484 ['fsmount', '''#include <sys/mount.h>'''],
485 ['fsopen', '''#include <sys/mount.h>'''],
486 ['fspick', '''#include <sys/mount.h>'''],
487 ['getgrgid_r', '''#include <sys/types.h>
488 #include <grp.h>'''],
489 ['getline', '''#include <stdio.h>'''],
490 ['getsubopt', '''#include <stdlib.h>'''],
491 ['gettid', '''#include <sys/types.h>
492 #include <unistd.h>'''],
493 ['hasmntopt', '''#include <stdio.h>
494 #include <mntent.h>'''],
495 ['kcmp', '''#include <linux/kcmp.h>'''],
496 ['keyctl', '''#include <sys/types.h>
497 #include <keyutils.h>'''],
498 ['memfd_create', '''#include <sys/mman.h>'''],
499 ['mount_setattr', '''#include <sys/mount.h>'''],
500 ['move_mount', '''#include <sys/mount.h>'''],
501 ['openat2', '''#include <sys/types.h>
502 #include <sys/stat.h>
503 #include <fctnl.h>'''],
504 ['open_tree', '''#include <sys/mount.h>'''],
505 ['personality', '''#include <sys/personality.h>'''],
506 ['pidfd_open', '''#include <stdlib.h>
507 #include <unistd.h>
508 #include <signal.h>
509 #include <sys/wait.h>'''],
510 ['pidfd_send_signal', '''#include <stdlib.h>
511 #include <unistd.h>
512 #include <signal.h>
513 #include <sys/wait.h>'''],
514 ['pivot_root', '''#include <stdlib.h>
515 #include <unistd.h>'''], # no known header declares pivot_root
516 ['prlimit', '''#include <sys/time.h>
517 #include <sys/resource.h>'''],
518 ['prlimit64', '''#include <sys/time.h>
519 #include <sys/resource.h>'''],
520 ['renameat2', '''#include <stdio.h>
521 #include <fcntl.h>'''],
522 ['sethostname', '''#include <unistd.h>'''],
523 ['setmntent', '''#include <stdio.h>
524 #include <mntent.h>'''],
525 ['setns', '''#include <sched.h>'''],
526 ['sigdescr_np', '''#include <string.h>'''],
527 ['signalfd', '''#include <sys/signalfd.h>'''],
528 ['statx', '''#include <sys/types.h>
529 #include <sys/stat.h>
530 #include <unistd.h>'''],
531 ['strchrnul', '''#include <string.h>'''],
532 ['strlcat', '''#include <string.h>'''],
533 ['strlcpy', '''#include <string.h>'''],
534 ['unshare', '''#include <sched.h>'''],
ea6da257
CB
535]
536
20b03401 537 have = cc.has_function(ident[0], prefix: ident[1], args: '-D_GNU_SOURCE')
eba7f7a6 538 srcconf.set10('HAVE_' + ident[0].to_upper(), have)
ea6da257
CB
539endforeach
540
541found_headers = []
542missing_headers = []
20b03401
SG
543foreach tuple: [
544 ['sys/resource.h'],
545 ['sys/memfd.h'],
546 ['sys/personality.h'],
547 ['sys/signalfd.h'],
548 ['sys/timerfd.h'],
549 ['pty.h'],
550 ['utmpx.h'],
ea6da257 551]
eba7f7a6 552 srcconf.set10('HAVE_' + tuple[0].underscorify().to_upper(), cc.has_header(tuple[0]))
20b03401
SG
553
554 if tuple.length() >= 2
555 cond = tuple[1]
556 else
557 ident1 = 'HAVE_' + tuple[0].underscorify().to_upper()
558 ident2 = 'ENABLE_' + tuple[0].underscorify().to_upper()
eba7f7a6 559 cond = srcconf.get(ident1, 0) == 1 or srcconf.get(ident2, 0) == 1
20b03401
SG
560 endif
561
562 if cond
563 found_headers += tuple[0]
564 else
565 missing_headers += tuple[0]
566 endif
ea6da257
CB
567endforeach
568
20b03401 569## Deps.
ea6da257
CB
570found_deps = []
571missing_deps = []
20b03401
SG
572foreach tuple: [
573 ['AppArmor'],
574 ['SECCOMP'],
575 ['SELinux'],
576 ['libcap'],
577 ['static libcap'],
8c48813a 578 ['pam'],
20b03401
SG
579 ['openssl'],
580 ['liburing'],
ea6da257
CB
581]
582
20b03401
SG
583 if tuple.length() >= 2
584 cond = tuple[1]
585 else
586 ident1 = 'HAVE_' + tuple[0].underscorify().to_upper()
587 ident2 = 'ENABLE_' + tuple[0].underscorify().to_upper()
eba7f7a6 588 cond = srcconf.get(ident1, 0) == 1 or srcconf.get(ident2, 0) == 1
20b03401
SG
589 endif
590
591 if cond
592 found_deps += tuple[0]
593 else
594 missing_deps += tuple[0]
595 endif
ea6da257
CB
596endforeach
597
20b03401
SG
598# Generate config.h
599config_h = configure_file(
600 output: 'config.h',
eba7f7a6 601 configuration: srcconf)
20b03401
SG
602
603add_project_arguments('-include', 'config.h', language: 'c')
604
605# Binaries.
606cmd_programs = []
607hook_programs = []
608public_programs = []
609template_scripts = []
610test_programs = []
611
612# Includes.
8d77f43f 613liblxc_includes = include_directories(
20b03401
SG
614 '.',
615 'src',
8d77f43f
SG
616 'src/include',
617 'src/lxc',
20b03401 618 'src/lxc/cgroups',
8d77f43f 619 'src/lxc/storage')
20b03401
SG
620
621# Early sub-directories.
622subdir('src/include')
623subdir('src/lxc')
24dcd86d 624subdir('src/lxc/pam')
20b03401
SG
625
626# Library.
627liblxc_dependencies = [
628 threads,
629 libseccomp,
630 libcap,
631 libopenssl,
632 libselinux,
633 libapparmor,
634]
635
7d8a38b2 636if want_io_uring
20b03401
SG
637 liblxc_dependencies += [liburing]
638endif
639
5055c73d
SG
640liblxc_link_whole = []
641if sanitize == 'none'
642 liblxc_link_whole = [liblxc_static]
643endif
644
20b03401
SG
645liblxc = shared_library(
646 'lxc',
647 version: liblxc_version,
648 include_directories: liblxc_includes,
649 link_args: ['-DPIC'],
650 c_args: ['-DPIC'],
5055c73d 651 link_whole: liblxc_link_whole,
20b03401
SG
652 dependencies: liblxc_dependencies,
653 install: true)
654
655liblxc_dep = declare_dependency(
656 link_with: liblxc,
657 dependencies: liblxc_dependencies)
658
659# Rest of sub-directories.
6105cc7f
SG
660subdir('config/apparmor')
661subdir('config/apparmor/abstractions')
662subdir('config/apparmor/profiles')
4a858b56 663subdir('config/bash')
9d18059b 664subdir('config/etc')
e4e52844
SG
665subdir('config/init/common')
666subdir('config/init/systemd')
8131bb44
SG
667subdir('config/init/sysvinit')
668subdir('config/init/upstart')
7c927048 669subdir('config/selinux')
36a53f30 670subdir('config/sysconfig')
c2931f74
SG
671subdir('config/templates')
672subdir('config/templates/common.conf.d')
d9121fff 673subdir('config/yum')
47c56c50
SG
674subdir('doc')
675subdir('doc/ja')
676subdir('doc/ko')
b3da01d7 677subdir('doc/examples')
6dfabed1 678subdir('doc/rootfs')
20b03401
SG
679subdir('hooks')
680subdir('src/lxc/cmd')
681subdir('src/lxc/tools')
682subdir('src/lxc/tools/include')
683subdir('src/tests')
684subdir('templates')
685
0860988e
SG
686# Pkg-config.
687pkg_config_file = pkgconfig.generate(liblxc,
688 description: 'linux container tools',
689 version: version_data.get('LXC_VERSION'),
690 url: 'http://linuxcontainers.org',
691 libraries: '-lutil -lpthread -ldl',
692 libraries_private: pkgconfig_libs,
0860988e
SG
693)
694
1404fcb8
SG
695# Empty dirs.
696install_emptydir(join_paths(localstatedir, 'cache', 'lxc'))
697install_emptydir(join_paths(localstatedir, 'lib', 'lxc'))
698
9c562440 699# RPM spec file.
e18dbec7
SG
700specconf = configuration_data()
701specconf.set('LXC_VERSION_BASE', meson.project_version())
702specconf.set('LXC_VERSION_BETA', version_data.get('LXC_VERSION_BETA'))
703specconf.set('PACKAGE', meson.project_name())
704specconf.set('LXC_DISTRO_SYSCONF', conf.get('LXC_DISTRO_SYSCONF'))
705
9c562440 706configure_file(
e18dbec7 707 configuration: specconf,
9c562440
SG
708 input: 'lxc.spec.in',
709 output: 'lxc.spec',
710 install: false)
711
20b03401 712# Build overview.
bf1f3470 713status = [
20b03401
SG
714 '@0@ @1@'.format(meson.project_name(), meson.project_version()),
715
716 'Meson version: @0@'.format(meson.version()),
717
718 'prefix directory: @0@'.format(prefixdir),
719 'bin directory: @0@'.format(bindir),
720 'data directory: @0@'.format(datadir),
721 'doc directory: @0@'.format(docdir),
722 'include directory: @0@'.format(includedir),
723 'lib directory: @0@'.format(libdir),
724 'libexec directory: @0@'.format(libexecdir),
725 'local state directory: @0@'.format(localstatedir),
726 'sbin directory: @0@'.format(sbindir),
727 'sysconf directory: @0@'.format(sysconfdir),
728
729 'lxc cgroup pattern: @0@'.format(cgrouppattern),
730 'lxc init directory: @0@'.format(libexecdir),
731 'runtime path: @0@'.format(runtimepath),
732
733 'lxc default config: @0@'.format(lxcdefaultconfig),
734 'lxc global config: @0@'.format(lxcglobalconfig),
735 'lxc hook directory: @0@'.format(lxchookdir),
736 'lxc hook bin directory: @0@'.format(lxchookbindir),
737 'lxc rootfs mount directory: @0@'.format(lxcrootfsmount),
738 'log path: @0@'.format(lxclogpath),
739 'lxc path: @0@'.format(lxcpath),
51f90ad9 740 'lxc template config: @0@'.format(lxctemplateconfdir),
20b03401
SG
741 'lxc template directory: @0@'.format(lxctemplatedir),
742 'lxc user network config: @0@'.format(lxc_user_network_conf),
743 'lxc user network database: @0@'.format(lxc_user_network_db)]
bf1f3470 744
ea6da257 745alt_time_epoch = run_command('date', '-Is', '-u', '-d',
aa326e18 746 '@@0@'.format(time_epoch), check: true).stdout().strip()
ea6da257 747status += [
20b03401 748 'time epoch: @0@ (@1@)'.format(time_epoch, alt_time_epoch)]
ea6da257
CB
749
750status += [
20b03401
SG
751 '',
752 'supported dependencies: @0@'.format(', '.join(found_deps)),
753 '',
754 'unsupported dependencies: @0@'.format(', '.join(missing_deps)),
755 '']
ea6da257
CB
756
757status += [
20b03401
SG
758 '',
759 'supported headers: @0@'.format(', '.join(found_headers)),
760 '',
761 'unsupported headers: @0@'.format(', '.join(missing_headers)),
762 '']
ea6da257
CB
763
764status += [
20b03401
SG
765 '',
766 'supported calls: @0@'.format(', '.join(found_syscalls)),
767 '',
768 'unsupported calls: @0@'.format(', '.join(missing_syscalls)),
769 '']
ea6da257
CB
770
771status += [
20b03401
SG
772 '',
773 'supported types: @0@'.format(', '.join(found_types)),
774 '',
775 'unsupported types: @0@'.format(', '.join(missing_types)),
776 '']
ea6da257 777
20b03401 778message('\n '.join(status))