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