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