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