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