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