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