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