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