]> git.proxmox.com Git - mirror_lxc.git/blame - meson.build
build: set as-needed in default_options
[mirror_lxc.git] / meson.build
CommitLineData
9b9d56e6
CB
1# SPDX-License-Identifier: LGPL-2.1-or-later
2
3project('lxc', 'c',
4 version : '4.0.0',
5 license : 'LGPLv2+',
6 default_options: [
5e0a302b 7 'b_asneeded=true',
98f3b527 8 'b_pie=true',
9b9d56e6
CB
9 'c_std=gnu11',
10 'warning_level=2',
11 ],
12 meson_version : '>= 0.45',
13 )
14
15liblxc_version = '4.0.0'
16
17conf = configuration_data()
18conf.set_quoted('PROJECT_URL', 'https://linuxcontainers.org/lxc/introduction/')
19conf.set('PROJECT_VERSION', meson.project_version(),
20 description : 'Numerical project version (used where a simple number is expected)')
297e5f96
CB
21conf.set('_GNU_SOURCE', true)
22conf.set('__STDC_FORMAT_MACROS', true)
9b9d56e6
CB
23
24version_data = configuration_data()
25version_data.set('LXC_VERSION_MAJOR', '4')
26version_data.set('LXC_VERSION_MINOR', '0')
27version_data.set('LXC_VERSION_MICRO', '7')
28version_data.set('LXC_ABI', '4.0.7')
29version_data.set('LXC_DEVEL', '1')
30version_data.set('LXC_VERSION', '4.0.7-devel')
31
32project_source_root = meson.current_source_dir()
33project_build_root = meson.current_build_dir()
34
35# join_paths ignores the preceding arguments if an absolute component is
36# encountered, so this should canonicalize various paths when they are
37# absolute or relative.
38prefixdir = get_option('prefix')
39if not prefixdir.startswith('/')
40 error('Prefix is not absolute: "@0@"'.format(prefixdir))
41endif
42datadir = join_paths(prefixdir, get_option('datadir'))
43bindir = join_paths(prefixdir, get_option('bindir'))
44sbindir = join_paths(prefixdir, get_option('sbindir'))
45includedir = join_paths(prefixdir, get_option('includedir'))
46libdir = join_paths(prefixdir, get_option('libdir'))
47libexecdir = join_paths(prefixdir, get_option('libexecdir'))
48sysconfdir = join_paths(prefixdir, get_option('sysconfdir'))
49runtimepath = join_paths(prefixdir, get_option('runtime-path'))
50localstatedir = join_paths('/', get_option('localstatedir'))
51apparmorcachedir = get_option('apparmor-cache-dir')
52rootfsmount = get_option('rootfs-mount-dir')
53cgrouppattern = get_option('cgroup-pattern')
54logpath = get_option('log-path')
55lxcpath = get_option('config-path')
56globalconfig = get_option('global-config')
57
58conf.set_quoted('BINDIR', bindir)
59conf.set_quoted('SBINDIR', sbindir)
60conf.set_quoted('INCLUDEDIR', includedir)
61conf.set_quoted('LIBDIR', libdir)
62conf.set_quoted('LIBEXECDIR', libexecdir)
63conf.set_quoted('SYSCONFDIR', sysconfdir)
64conf.set_quoted('LXC_DEFAULT_CONFIG', join_paths(sysconfdir, 'lxc/default.conf'))
65conf.set_quoted('APPARMOR_CACHE_DIR', join_paths(localstatedir, apparmorcachedir))
66conf.set_quoted('LXCROOTFSMOUNT', join_paths(prefixdir, rootfsmount))
67conf.set_quoted('DEFAULT_CGROUP_PATTERN', cgrouppattern)
68conf.set_quoted('RUNTIME_PATH', runtimepath)
69conf.set_quoted('LOGPATH', join_paths(localstatedir, logpath))
70conf.set_quoted('LXCPATH', join_paths(localstatedir, lxcpath))
71conf.set_quoted('LXC_GLOBAL_CONF', join_paths(sysconfdir, globalconfig))
72conf.set_quoted('DATADIR', datadir)
73conf.set_quoted('LXCTEMPLATECONFIG', join_paths(datadir, 'lxc/config'))
74conf.set_quoted('LXCTEMPLATEDIR', join_paths(datadir, 'lxc/templates'))
75conf.set_quoted('LXCINITDIR', libexecdir)
76
77# AS_AC_EXPAND(DATADIR, "$datadir")
78# AS_AC_EXPAND(LOCALSTATEDIR, "$localstatedir")
79# AS_AC_EXPAND(DOCDIR, "$docdir")
80# AS_AC_EXPAND(LXC_GENERATE_DATE, "$(date --utc --date=@${SOURCE_DATE_EPOCH:-$(date +%s)} '+%Y-%m-%d')")
81# AS_AC_EXPAND(LXCPATH, "$with_config_path")
82# AS_AC_EXPAND(LXC_GLOBAL_CONF, "$with_global_conf")
83# AS_AC_EXPAND(LXC_USERNIC_CONF, "$with_usernic_conf")
84# AS_AC_EXPAND(LXC_USERNIC_DB, "$with_usernic_db")
85# AS_AC_EXPAND(LXC_DISTRO_SYSCONF, "$distrosysconf")
86# AS_AC_EXPAND(LXCHOOKDIR, "$datadir/lxc/hooks")
87# AS_AC_EXPAND(LXCBINHOOKDIR, "$libexecdir/lxc/hooks")
88# AS_AC_EXPAND(LXCINITDIR, "$libexecdir")
89#
90# # We need the install path so criu knows where to reference the hook scripts.
91# AC_DEFINE_UNQUOTED([DATADIR], "$DATADIR", ["Prefix for shared files."])
92
93cc = meson.get_compiler('c')
94pkgconfig = import('pkgconfig')
95
96possible_cc_flags = [
9b9d56e6
CB
97 '-Wvla',
98 '-fdiagnostics-color',
99 '-Wimplicit-fallthrough=5',
100 '-Wcast-align',
101 '-Wstrict-prototypes',
102 '-fno-strict-aliasing',
103 '-fstack-clash-protection',
104 '-fstack-protector-strong',
105 '--param=ssp-buffer-size=4',
106 '--mcet -fcf-protection',
107 '-Werror=implicit-function-declaration',
108 '-Wlogical-op',
109 '-Wmissing-include-dirs',
110 '-Wold-style-definition',
111 '-Winit-self',
112 '-Wunused-but-set-variable',
113 '-Wno-unused-parameter',
114 '-Wfloat-equal',
115 '-Wsuggest-attribute=noreturn',
116 '-Werror=return-type',
117 '-Werror=incompatible-pointer-types',
118 '-Wformat=2',
119 '-Wshadow',
120 '-Wendif-labels',
121 '-Werror=overflow',
122 '-fdiagnostics-show-option',
123 '-Werror=shift-count-overflow',
124 '-Werror=shift-overflow=2',
125 '-Wdate-time',
126 '-Wnested-externs',
127 '-fasynchronous-unwind-tables',
128 '-fexceptions',
129 '-Warray-bounds',
130 '-Wrestrict',
131 '-Wreturn-local-addr',
132 '-fsanitize=cfi',
133 '-Wstringop-overflow',
134]
135
136possible_link_flags = [
9b9d56e6
CB
137 '-Wl,--gc-sections',
138 '-Wl,-z,relro',
139 '-Wl,-z,now',
9b9d56e6
CB
140 '-Wl,-fuse-ld=gold',
141]
142
143if meson.version().version_compare('>=0.46')
144 add_project_link_arguments(cc.get_supported_link_arguments(possible_link_flags), language : 'c')
145else
146 add_project_link_arguments(possible_link_flags, language : 'c')
147endif
148
149add_project_arguments(cc.get_supported_arguments(possible_cc_flags), language : 'c')
150
151foreach header : ['sys/resource.h',
152 'sys/memfd.h',
153 'sys/personality.h',
154 'sys/signalfd.h',
155 'sys/timerfd.h',
156 'pty.h',
157 'utmpx.h',
158 ]
159
160 conf.set10('HAVE_' + header.underscorify().to_upper(),
161 cc.has_header(header))
162endforeach
163
164decl_headers = '''
165#include <uchar.h>
166#include <sys/mount.h>
167#include <sys/stat.h>
168#include <linux/fs.h>
169#include <linux/types.h>
170#include <linux/openat2.h>
171#include <linux/sched.h>
172'''
173
174foreach decl : [
175 '__aligned_u64',
176 'struct mount_attr',
177 'struct open_how',
178 'struct clone_args',
179 ]
180
181 # We get -1 if the size cannot be determined
182 have = cc.sizeof(decl, prefix : decl_headers, args : '-D_GNU_SOURCE') > 0
183
184 if have == true
185 conf.set10('HAVE_' + decl.underscorify().to_upper(), have)
186 endif
187endforeach
188
189foreach ident : [
190 ['memfd_create', '''#include <sys/mman.h>'''],
191 ['gettid', '''#include <sys/types.h>
192 #include <unistd.h>'''],
193 ['pivot_root', '''#include <stdlib.h>
194 #include <unistd.h>'''], # no known header declares pivot_root
195 ['setns', '''#include <sched.h>'''],
196 ['renameat2', '''#include <stdio.h>
197 #include <fcntl.h>'''],
198 ['kcmp', '''#include <linux/kcmp.h>'''],
199 ['keyctl', '''#include <sys/types.h>
200 #include <keyutils.h>'''],
201 ['bpf', '''#include <sys/syscall.h>
202 #include <unistd.h>'''],
203 ['statx', '''#include <sys/types.h>
204 #include <sys/stat.h>
205 #include <unistd.h>'''],
206 ['pidfd_send_signal', '''#include <stdlib.h>
207 #include <unistd.h>
208 #include <signal.h>
209 #include <sys/wait.h>'''],
210 ['pidfd_open', '''#include <stdlib.h>
211 #include <unistd.h>
212 #include <signal.h>
213 #include <sys/wait.h>'''],
214 ['execveat', '''#include <unistd.h>'''],
215 ['close_range', '''#include <unistd.h>'''],
216 ['mount_setattr', '''#include <sys/mount.h>'''],
217 ['move_mount', '''#include <sys/mount.h>'''],
218 ['open_tree', '''#include <sys/mount.h>'''],
219 ['strlcpy', '''#include <string.h>'''],
220 ['strlcat', '''#include <string.h>'''],
221 ['sethostname', '''#include <unistd.h>'''],
222 ['faccessat', '''#include <fcntl.h>
223 #include <unistd.h>'''],
224 ['unshare', '''#include <sched.h>'''],
225 ['prlimit', '''#include <sys/time.h>
226 #include <sys/resource.h>'''],
227 ['prlimit64', '''#include <sys/time.h>
228 #include <sys/resource.h>'''],
229]
230
231 have = cc.has_function(ident[0], prefix : ident[1], args : '-D_GNU_SOURCE')
232 if have == true
233 conf.set10('HAVE_' + ident[0].to_upper(), have)
234 endif
235endforeach
236
237threads = dependency('threads')
238libseccomp = cc.find_library('seccomp', required : false)
239if libseccomp.found()
240 conf.set10('HAVE_SECCOMP', libseccomp.found())
241
242 seccomp_headers = '''
243 #include <seccomp.h>
244 '''
245
246 if cc.has_function('seccomp_notify_fd', prefix : seccomp_headers, args : '-D_GNU_SOURCE', dependencies: libseccomp)
247 conf.set10('HAVE_DECL_SECCOMP_NOTIFY_FD', true)
248 endif
249
250 if cc.has_function('seccomp_syscall_resolve_name_arch', prefix : seccomp_headers, args : '-D_GNU_SOURCE', dependencies: libseccomp)
251 conf.set10('HAVE_DECL_SECCOMP_SYSCALL_RESOLVE_NAME_ARCH', true)
252 endif
253
254 foreach decl : [
255 'scmp_filter_ctx',
256 'struct seccomp_notif_sizes',
257 'struct clone_args',
258 ]
259
260 # We get -1 if the size cannot be determined
261 have = cc.sizeof(decl, prefix : seccomp_headers, args : '-D_GNU_SOURCE') > 0
262
263 if have == true
264 conf.set10('HAVE_' + decl.underscorify().to_upper(), have)
265 endif
266 endforeach
267endif
268
269libselinux = cc.find_library('selinux', required : false)
270if libselinux.found()
271 conf.set10('HAVE_SELINUX', libselinux.found())
272endif
273
274libapparmor = cc.find_library('apparmor', required : false)
275if libapparmor.found()
276 conf.set10('HAVE_APPARMOR', libapparmor.found())
277endif
278
279libopenssl = dependency('openssl', required : false)
280if libopenssl.found()
281 conf.set10('HAVE_OPENSSL', libopenssl.found())
282endif
283
284libcap = dependency('libcap', required : false)
285if not libcap.found()
286 # Compat with Ubuntu 14.04 which ships libcap w/o .pc file
287 libcap = cc.find_library('cap')
288endif
289
290if libcap.found()
291 conf.set10('HAVE_LIBCAP', libcap.found())
292endif
293
294basic_includes = include_directories(
295 'src',
296 'src/include',
297 '.')
298
299liblxc_includes = [basic_includes, include_directories(
300 'src/lxc/cgroups',
301 'src/lxc/lsm',
302 'src/lxc/storage')]
303
304add_project_arguments('-include', 'config.h', language : 'c')
305
306subdir('src/include')
307subdir('src/lxc')
297e5f96 308subdir('src/lxc/tools')
9b9d56e6
CB
309
310config_h = configure_file(
311 output : 'config.h',
312 configuration : conf)
313
314liblxc = shared_library(
315 'lxc',
316 version : liblxc_version,
297e5f96 317 include_directories : tools_liblxc_includes,
9b9d56e6
CB
318 link_args : ['-shared', '-fPIC', '-DPIC'],
319 link_whole : [liblxc_static],
320 dependencies : [threads,
321 libseccomp,
322 libcap,
323 libopenssl,
324 libselinux,
325 libapparmor],
326 install : true,
327 install_dir : libdir)
297e5f96
CB
328
329public_programs = []
330
331public_programs += executable(
332 'lxc-autostart',
333 tools_lxc_autostart_sources,
334 include_directories : tools_liblxc_includes,
335 link_with : [liblxc],
336 dependencies : [threads,
337 libseccomp,
338 libcap,
339 libopenssl,
340 libselinux,
341 libapparmor],
342 install : true,
343 install_dir : bindir)
344
345public_programs += executable(
346 'lxc-cgroup',
347 tools_lxc_cgroup_sources,
348 include_directories : tools_liblxc_includes,
349 link_with : [liblxc],
350 dependencies : [threads,
351 libseccomp,
352 libcap,
353 libopenssl,
354 libselinux,
355 libapparmor],
356 install : true,
357 install_dir : bindir)
358
359public_programs += executable(
360 'lxc-checkpoint',
361 tools_lxc_checkpoint_sources,
362 include_directories : tools_liblxc_includes,
363 link_with : [liblxc],
364 dependencies : [threads,
365 libseccomp,
366 libcap,
367 libopenssl,
368 libselinux,
369 libapparmor],
370 install : true,
371 install_dir : bindir)
372
373public_programs += executable(
374 'lxc-config',
375 tools_lxc_config_sources,
376 include_directories : tools_liblxc_includes,
377 link_with : [liblxc],
378 dependencies : [threads,
379 libseccomp,
380 libcap,
381 libopenssl,
382 libselinux,
383 libapparmor],
384 install : true,
385 install_dir : bindir)
386
387public_programs += executable(
388 'lxc-console',
389 tools_lxc_console_sources,
390 include_directories : tools_liblxc_includes,
391 link_with : [liblxc],
392 dependencies : [threads,
393 libseccomp,
394 libcap,
395 libopenssl,
396 libselinux,
397 libapparmor],
398 install : true,
399 install_dir : bindir)
400
401public_programs += executable(
402 'lxc-copy',
403 tools_lxc_copy_sources,
404 include_directories : tools_liblxc_includes,
405 link_with : [liblxc],
406 dependencies : [threads,
407 libseccomp,
408 libcap,
409 libopenssl,
410 libselinux,
411 libapparmor],
412 install : true,
413 install_dir : bindir)
414
415public_programs += executable(
416 'lxc-create',
417 tools_lxc_create_sources,
418 include_directories : tools_liblxc_includes,
419 link_with : [liblxc],
420 dependencies : [threads,
421 libseccomp,
422 libcap,
423 libopenssl,
424 libselinux,
425 libapparmor],
426 install : true,
427 install_dir : bindir)
428
429public_programs += executable(
430 'lxc-destroy',
431 tools_lxc_destroy_sources,
432 include_directories : tools_liblxc_includes,
433 link_with : [liblxc],
434 dependencies : [threads,
435 libseccomp,
436 libcap,
437 libopenssl,
438 libselinux,
439 libapparmor],
440 install : true,
441 install_dir : bindir)
442
443public_programs += executable(
444 'lxc-device',
445 tools_lxc_device_sources,
446 include_directories : tools_liblxc_includes,
447 link_with : [liblxc],
448 dependencies : [threads,
449 libseccomp,
450 libcap,
451 libopenssl,
452 libselinux,
453 libapparmor],
454 install : true,
455 install_dir : bindir)
456
457public_programs += executable(
458 'lxc-execute',
459 tools_lxc_execute_sources,
460 include_directories : tools_liblxc_includes,
461 link_with : [liblxc],
462 dependencies : [threads,
463 libseccomp,
464 libcap,
465 libopenssl,
466 libselinux,
467 libapparmor],
468 install : true,
469 install_dir : bindir)
470
471public_programs += executable(
472 'lxc-freeze',
473 tools_lxc_freeze_sources,
474 include_directories : tools_liblxc_includes,
475 link_with : [liblxc],
476 dependencies : [threads,
477 libseccomp,
478 libcap,
479 libopenssl,
480 libselinux,
481 libapparmor],
482 install : true,
483 install_dir : bindir)
484
485public_programs += executable(
486 'lxc-info',
487 tools_lxc_info_sources,
488 include_directories : tools_liblxc_includes,
489 link_with : [liblxc],
490 dependencies : [threads,
491 libseccomp,
492 libcap,
493 libopenssl,
494 libselinux,
495 libapparmor],
496 install : true,
497 install_dir : bindir)
498
499public_programs += executable(
500 'lxc-ls',
501 tools_lxc_ls_sources,
502 include_directories : tools_liblxc_includes,
503 link_with : [liblxc],
504 dependencies : [threads,
505 libseccomp,
506 libcap,
507 libopenssl,
508 libselinux,
509 libapparmor],
510 install : true,
511 install_dir : bindir)
512
513public_programs += executable(
514 'lxc-monitor',
515 tools_lxc_monitor_sources,
516 include_directories : tools_liblxc_includes,
517 link_with : [liblxc],
518 dependencies : [threads,
519 libseccomp,
520 libcap,
521 libopenssl,
522 libselinux,
523 libapparmor],
524 install : true,
525 install_dir : bindir)
526
527public_programs += executable(
528 'lxc-snapshot',
529 tools_lxc_snapshot_sources,
530 include_directories : tools_liblxc_includes,
531 link_with : [liblxc],
532 dependencies : [threads,
533 libseccomp,
534 libcap,
535 libopenssl,
536 libselinux,
537 libapparmor],
538 install : true,
539 install_dir : bindir)
540
541public_programs += executable(
542 'lxc-start',
543 tools_lxc_start_sources,
544 include_directories : tools_liblxc_includes,
545 link_with : [liblxc],
546 dependencies : [threads,
547 libseccomp,
548 libcap,
549 libopenssl,
550 libselinux,
551 libapparmor],
552 install : true,
553 install_dir : bindir)
554
555public_programs += executable(
556 'lxc-stop',
557 tools_lxc_stop_sources,
558 include_directories : tools_liblxc_includes,
559 link_with : [liblxc],
560 dependencies : [threads,
561 libseccomp,
562 libcap,
563 libopenssl,
564 libselinux,
565 libapparmor],
566 install : true,
567 install_dir : bindir)
568
569public_programs += executable(
570 'lxc-top',
571 tools_lxc_top_sources,
572 include_directories : tools_liblxc_includes,
573 link_with : [liblxc],
574 dependencies : [threads,
575 libseccomp,
576 libcap,
577 libopenssl,
578 libselinux,
579 libapparmor],
580 install : true,
581 install_dir : bindir)
582
583public_programs += executable(
584 'lxc-unfreeze',
585 tools_lxc_unfreeze_sources,
586 include_directories : tools_liblxc_includes,
587 link_with : [liblxc],
588 dependencies : [threads,
589 libseccomp,
590 libcap,
591 libopenssl,
592 libselinux,
593 libapparmor],
594 install : true,
595 install_dir : bindir)
596
597public_programs += executable(
598 'lxc-unshare',
599 tools_lxc_unshare_sources,
600 include_directories : tools_liblxc_includes,
601 link_with : [liblxc],
602 dependencies : [threads,
603 libseccomp,
604 libcap,
605 libopenssl,
606 libselinux,
607 libapparmor],
608 install : true,
609 install_dir : bindir)
610
611public_programs += executable(
612 'lxc-wait',
613 tools_lxc_wait_sources,
614 include_directories : tools_liblxc_includes,
615 link_with : [liblxc],
616 dependencies : [threads,
617 libseccomp,
618 libcap,
619 libopenssl,
620 libselinux,
621 libapparmor],
622 install : true,
623 install_dir : bindir)