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