]>
Commit | Line | Data |
---|---|---|
9b9d56e6 CB |
1 | # SPDX-License-Identifier: LGPL-2.1-or-later |
2 | ||
20b03401 SG |
3 | # Project. |
4 | project( | |
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 |
21 | cc = meson.get_compiler('c') |
22 | pkgconfig = import('pkgconfig') | |
0860988e | 23 | pkgconfig_libs = [] |
9b9d56e6 | 24 | |
20b03401 | 25 | # Version. |
eba7f7a6 | 26 | liblxc_version = '1.7.0' |
9b9d56e6 CB |
27 | version_data = configuration_data() |
28 | version_data.set('LXC_VERSION_MAJOR', '4') | |
29 | version_data.set('LXC_VERSION_MINOR', '0') | |
eba7f7a6 | 30 | version_data.set('LXC_VERSION_MICRO', '0') |
e18dbec7 | 31 | version_data.set('LXC_VERSION_BETA', '') |
eba7f7a6 | 32 | version_data.set('LXC_ABI', liblxc_version) |
9b9d56e6 | 33 | version_data.set('LXC_DEVEL', '1') |
eba7f7a6 | 34 | version_data.set('LXC_VERSION', meson.project_version()) |
9b9d56e6 | 35 | |
eba7f7a6 | 36 | # Path handling. |
9b9d56e6 CB |
37 | project_source_root = meson.current_source_dir() |
38 | project_build_root = meson.current_build_dir() | |
9b9d56e6 | 39 | prefixdir = get_option('prefix') |
20b03401 | 40 | |
7609de18 SG |
41 | apparmorcachedir = get_option('apparmor-cache-path') |
42 | globalconfig = get_option('global-config-path') | |
20b03401 SG |
43 | localstatedir = join_paths('/', get_option('localstatedir')) |
44 | logpath = get_option('log-path') | |
7609de18 SG |
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') | |
20b03401 | 49 | |
4a858b56 | 50 | bashcompletiondir = join_paths('/', 'usr', 'share', 'bash-completion', 'completions') |
9b9d56e6 | 51 | bindir = join_paths(prefixdir, get_option('bindir')) |
bf1f3470 | 52 | datadir = join_paths(prefixdir, get_option('datadir')) |
47c56c50 | 53 | mandir = join_paths(prefixdir, get_option('mandir')) |
7609de18 | 54 | docdir = join_paths(datadir, get_option('doc-path')) |
9b9d56e6 CB |
55 | includedir = join_paths(prefixdir, get_option('includedir')) |
56 | libdir = join_paths(prefixdir, get_option('libdir')) | |
57 | libexecdir = join_paths(prefixdir, get_option('libexecdir')) | |
20b03401 | 58 | runtimepath = join_paths(prefixdir, get_option('runtime-path')) |
bf1f3470 CB |
59 | sbindir = join_paths(prefixdir, get_option('sbindir')) |
60 | sysconfdir = join_paths(prefixdir, get_option('sysconfdir')) | |
61 | ||
7609de18 | 62 | lxcapparmorcachedir = join_paths(localstatedir, apparmorcachedir) |
9d18059b SG |
63 | lxcconfdir = join_paths(sysconfdir, globalconfig) |
64 | lxcdefaultconfig = join_paths(lxcconfdir, 'default.conf') | |
65 | lxcglobalconfig = join_paths(lxcconfdir, 'lxc.conf') | |
7609de18 | 66 | lxcexamplesdir = join_paths(docdir, 'examples') |
7609de18 | 67 | lxchookbindir = join_paths(libexecdir, 'lxc/hooks') |
1a9afacc | 68 | lxcinclude = join_paths(includedir, 'lxc') |
2f1bf5f5 | 69 | lxclibexec = join_paths(libexecdir, 'lxc') |
bf1f3470 | 70 | lxclogpath = join_paths(localstatedir, logpath) |
bf1f3470 | 71 | lxcpath = join_paths(localstatedir, lxcpathprefix) |
7609de18 | 72 | lxcrootfsmount = join_paths(libdir, rootfsmount) |
51f90ad9 SG |
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') | |
72f1c44a | 79 | lxc_user_network_conf = join_paths(sysconfdir, user_network_conf_opt) |
72f1c44a | 80 | lxc_user_network_db = join_paths(runtimepath, user_network_db_opt) |
8c48813a | 81 | pam_security = join_paths(libdir, 'security') |
72f1c44a | 82 | |
eba7f7a6 SG |
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) | |
20b03401 | 117 | |
299f3f80 SG |
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 | ||
20b03401 SG |
130 | # Custom configuration. |
131 | cgrouppattern = get_option('cgroup-pattern') | |
4dd5e0cf | 132 | coverity = get_option('coverity-build') |
8131bb44 | 133 | init_script = get_option('init-script') |
5055c73d | 134 | sanitize = get_option('b_sanitize') |
7609de18 | 135 | want_examples = get_option('examples') |
7d8a38b2 | 136 | want_io_uring = get_option('io-uring-event-loop') |
8c48813a | 137 | want_pam_cgroup = get_option('pam-cgroup') |
7609de18 | 138 | want_mans = get_option('man') |
20b03401 | 139 | want_tests = get_option('tests') |
b3d18992 | 140 | want_tools = get_option('tools') |
20b03401 | 141 | |
eba7f7a6 | 142 | srcconf.set_quoted('DEFAULT_CGROUP_PATTERN', cgrouppattern) |
4dd5e0cf SG |
143 | if coverity |
144 | srcconf.set('ENABLE_COVERITY_BUILD', 1) | |
145 | endif | |
9b9d56e6 | 146 | |
20b03401 SG |
147 | dummy_config_data = configuration_data() |
148 | dummy_config_data.set_quoted('DUMMY_VARIABLE', '1') | |
9b9d56e6 | 149 | |
20b03401 | 150 | # Build flags. |
9b9d56e6 | 151 | possible_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 | ||
190 | possible_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 | ||
197 | if meson.version().version_compare('>=0.46') | |
20b03401 | 198 | add_project_link_arguments(cc.get_supported_link_arguments(possible_link_flags), language: 'c') |
9b9d56e6 | 199 | else |
20b03401 | 200 | add_project_link_arguments(possible_link_flags, language: 'c') |
9b9d56e6 CB |
201 | endif |
202 | ||
20b03401 | 203 | add_project_arguments(cc.get_supported_arguments(possible_cc_flags), language: 'c') |
9b9d56e6 | 204 | |
20b03401 SG |
205 | # Feature detection |
206 | ## I/O uring. | |
7d8a38b2 | 207 | if 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 |
214 | endif |
215 | ||
20b03401 | 216 | ## Time EPOCH. |
ea6da257 | 217 | sh = find_program('sh') |
23ba778f | 218 | date = find_program('date') |
20b03401 | 219 | git = find_program('git', required: false) |
aa326e18 SG |
220 | time_epoch = run_command(sh, '-c', 'echo "$SOURCE_DATE_EPOCH"', check: true).stdout().strip() |
221 | if 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 | 225 | else |
eba7f7a6 | 226 | # Fallback to current epoch. |
23ba778f | 227 | time_epoch = run_command(date, '+%s', check: true).stdout() |
ea6da257 | 228 | endif |
47c56c50 | 229 | generate_date = run_command(date, '--utc', '--date=@' + time_epoch, '+%Y-%m-%d', check: true).stdout().strip() |
ea6da257 | 230 | |
2bd9ab6f | 231 | ## Manpages. |
4412d151 | 232 | sgml2man = find_program('docbook2X2man', 'docbook2x-man', 'db2x_docbook2man', 'docbook2man', 'docbook-to-man', required: want_mans) |
2bd9ab6f SG |
233 | docbook2man = find_program('docbook2man', required: false) |
234 | ||
235 | docconf = configuration_data() | |
236 | docconf.set('builddir', '.') | |
f80af4e1 SG |
237 | docconf.set('BINDIR', bindir) |
238 | docconf.set('DATADIR', datadir) | |
239 | docconf.set('DOCDIR', docdir) | |
240 | docconf.set('LOGPATH', lxclogpath) | |
241 | docconf.set('LXC_DEFAULT_CONFIG', lxcdefaultconfig) | |
2bd9ab6f | 242 | docconf.set('LXC_GENERATE_DATE', generate_date) |
f80af4e1 SG |
243 | docconf.set('LXC_GLOBAL_CONF', lxcglobalconfig) |
244 | docconf.set('LXCPATH', lxcpath) | |
245 | docconf.set('LXCTEMPLATEDIR', lxctemplatedir) | |
246 | docconf.set('LXC_USERNIC_CONF', lxc_user_network_conf) | |
247 | docconf.set('LXC_USERNIC_DB', lxc_user_network_db) | |
2bd9ab6f SG |
248 | docconf.set('PACKAGE_VERSION', version_data.get('LXC_VERSION')) |
249 | if sgml2man.found() and docbook2man.found() and sgml2man.full_path() == docbook2man.full_path() | |
250 | docconf.set('docdtd', '"-//Davenport//DTD DocBook V3.0//EN"') | |
251 | else | |
252 | docconf.set('docdtd', '"-//OASIS//DTD DocBook XML" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd"') | |
253 | endif | |
254 | ||
20b03401 | 255 | ## Threads. |
9b9d56e6 | 256 | threads = dependency('threads') |
20b03401 SG |
257 | |
258 | ## Seccomp. | |
e4384f1c | 259 | libseccomp = dependency('libseccomp') |
eba7f7a6 | 260 | srcconf.set10('HAVE_SECCOMP', libseccomp.found()) |
181cd6dc | 261 | pkgconfig_libs += libseccomp |
9b9d56e6 | 262 | if 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 |
294 | endif |
295 | ||
20b03401 SG |
296 | ## SELinux. |
297 | libselinux = dependency('libselinux', required: false) | |
eba7f7a6 | 298 | srcconf.set10('HAVE_SELINUX', libselinux.found()) |
181cd6dc | 299 | pkgconfig_libs += libselinux |
9b9d56e6 | 300 | |
20b03401 SG |
301 | ## AppArmor. |
302 | libapparmor = dependency('libapparmor', required: false) | |
eba7f7a6 | 303 | srcconf.set10('HAVE_APPARMOR', libapparmor.found()) |
9b9d56e6 | 304 | |
20b03401 SG |
305 | ## OpenSSL. |
306 | libopenssl = dependency('openssl', required: false) | |
eba7f7a6 | 307 | srcconf.set10('HAVE_OPENSSL', libopenssl.found()) |
181cd6dc | 308 | pkgconfig_libs += libopenssl |
9b9d56e6 | 309 | |
20b03401 SG |
310 | ## Libcap.. |
311 | libcap = dependency('libcap', required: false) | |
9b9d56e6 | 312 | if 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 | 315 | endif |
eba7f7a6 | 316 | srcconf.set10('HAVE_LIBCAP', libcap.found()) |
181cd6dc | 317 | pkgconfig_libs += libcap |
9b9d56e6 | 318 | |
20b03401 | 319 | libcap_static = dependency('libcap', required: false, static: true) |
d0a16061 | 320 | if 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 | 323 | endif |
eba7f7a6 | 324 | srcconf.set10('HAVE_STATIC_LIBCAP', libcap_static.found()) |
d0a16061 | 325 | |
0860988e | 326 | ## PAM. |
8c48813a | 327 | pam = cc.find_library('pam', has_headers: 'security/pam_modules.h', required: want_pam_cgroup) |
eba7f7a6 | 328 | srcconf.set10('HAVE_PAM', pam.found()) |
181cd6dc | 329 | pkgconfig_libs += pam |
0860988e | 330 | |
20b03401 SG |
331 | ## Others. |
332 | have = cc.has_function('strchrnul', prefix: '#include <string.h>', args: '-D_GNU_SOURCE') | |
eba7f7a6 | 333 | srcconf.set10('HAVE_STRCHRNUL', have) |
db4af8c5 | 334 | |
20b03401 | 335 | have = cc.has_function('openpty', prefix: '#include <pty.h>', args: '-D_GNU_SOURCE') |
eba7f7a6 | 336 | srcconf.set10('HAVE_OPENPTY', have) |
db4af8c5 | 337 | |
20b03401 SG |
338 | ## Compiler attributes. |
339 | foreach 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 | 346 | endforeach |
5c26176d | 347 | |
20b03401 | 348 | ## Syscalls. |
ea6da257 CB |
349 | found_syscalls = [] |
350 | missing_syscalls = [] | |
20b03401 SG |
351 | foreach 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 | |
406 | endforeach | |
407 | ||
408 | ## Types. | |
409 | decl_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 |
419 | foreach 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 |
432 | endforeach |
433 | ||
434 | found_types = [] | |
435 | missing_types = [] | |
20b03401 SG |
436 | foreach 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 | |
458 | endforeach | |
459 | ||
460 | ## Headers. | |
461 | foreach 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 |
528 | endforeach |
529 | ||
530 | found_headers = [] | |
531 | missing_headers = [] | |
20b03401 SG |
532 | foreach 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 |
556 | endforeach |
557 | ||
20b03401 | 558 | ## Deps. |
ea6da257 CB |
559 | found_deps = [] |
560 | missing_deps = [] | |
20b03401 SG |
561 | foreach 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 |
585 | endforeach |
586 | ||
20b03401 SG |
587 | # Generate config.h |
588 | config_h = configure_file( | |
589 | output: 'config.h', | |
eba7f7a6 | 590 | configuration: srcconf) |
20b03401 SG |
591 | |
592 | add_project_arguments('-include', 'config.h', language: 'c') | |
593 | ||
594 | # Binaries. | |
595 | cmd_programs = [] | |
596 | hook_programs = [] | |
597 | public_programs = [] | |
598 | template_scripts = [] | |
599 | test_programs = [] | |
600 | ||
601 | # Includes. | |
8d77f43f | 602 | liblxc_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. | |
611 | subdir('src/include') | |
612 | subdir('src/lxc') | |
24dcd86d | 613 | subdir('src/lxc/pam') |
20b03401 SG |
614 | |
615 | # Library. | |
616 | liblxc_dependencies = [ | |
617 | threads, | |
618 | libseccomp, | |
619 | libcap, | |
620 | libopenssl, | |
621 | libselinux, | |
622 | libapparmor, | |
623 | ] | |
624 | ||
7d8a38b2 | 625 | if want_io_uring |
20b03401 SG |
626 | liblxc_dependencies += [liburing] |
627 | endif | |
628 | ||
5055c73d SG |
629 | liblxc_link_whole = [] |
630 | if sanitize == 'none' | |
631 | liblxc_link_whole = [liblxc_static] | |
632 | endif | |
633 | ||
20b03401 SG |
634 | liblxc = 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 | ||
644 | liblxc_dep = declare_dependency( | |
645 | link_with: liblxc, | |
646 | dependencies: liblxc_dependencies) | |
647 | ||
648 | # Rest of sub-directories. | |
6105cc7f SG |
649 | subdir('config/apparmor') |
650 | subdir('config/apparmor/abstractions') | |
651 | subdir('config/apparmor/profiles') | |
4a858b56 | 652 | subdir('config/bash') |
9d18059b | 653 | subdir('config/etc') |
e4e52844 SG |
654 | subdir('config/init/common') |
655 | subdir('config/init/systemd') | |
8131bb44 SG |
656 | subdir('config/init/sysvinit') |
657 | subdir('config/init/upstart') | |
7c927048 | 658 | subdir('config/selinux') |
36a53f30 | 659 | subdir('config/sysconfig') |
c2931f74 SG |
660 | subdir('config/templates') |
661 | subdir('config/templates/common.conf.d') | |
d9121fff | 662 | subdir('config/yum') |
47c56c50 SG |
663 | subdir('doc') |
664 | subdir('doc/ja') | |
665 | subdir('doc/ko') | |
b3da01d7 | 666 | subdir('doc/examples') |
6dfabed1 | 667 | subdir('doc/rootfs') |
20b03401 SG |
668 | subdir('hooks') |
669 | subdir('src/lxc/cmd') | |
670 | subdir('src/lxc/tools') | |
671 | subdir('src/lxc/tools/include') | |
672 | subdir('src/tests') | |
673 | subdir('templates') | |
674 | ||
0860988e SG |
675 | # Pkg-config. |
676 | pkg_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. |
685 | install_emptydir(join_paths(localstatedir, 'cache', 'lxc')) | |
686 | install_emptydir(join_paths(localstatedir, 'lib', 'lxc')) | |
687 | ||
9c562440 | 688 | # RPM spec file. |
e18dbec7 SG |
689 | specconf = configuration_data() |
690 | specconf.set('LXC_VERSION_BASE', meson.project_version()) | |
691 | specconf.set('LXC_VERSION_BETA', version_data.get('LXC_VERSION_BETA')) | |
692 | specconf.set('PACKAGE', meson.project_name()) | |
693 | specconf.set('LXC_DISTRO_SYSCONF', conf.get('LXC_DISTRO_SYSCONF')) | |
694 | ||
9c562440 | 695 | configure_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 | 702 | status = [ |
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 | 734 | alt_time_epoch = run_command('date', '-Is', '-u', '-d', |
aa326e18 | 735 | '@@0@'.format(time_epoch), check: true).stdout().strip() |
ea6da257 | 736 | status += [ |
20b03401 | 737 | 'time epoch: @0@ (@1@)'.format(time_epoch, alt_time_epoch)] |
ea6da257 CB |
738 | |
739 | status += [ | |
20b03401 SG |
740 | '', |
741 | 'supported dependencies: @0@'.format(', '.join(found_deps)), | |
742 | '', | |
743 | 'unsupported dependencies: @0@'.format(', '.join(missing_deps)), | |
744 | ''] | |
ea6da257 CB |
745 | |
746 | status += [ | |
20b03401 SG |
747 | '', |
748 | 'supported headers: @0@'.format(', '.join(found_headers)), | |
749 | '', | |
750 | 'unsupported headers: @0@'.format(', '.join(missing_headers)), | |
751 | ''] | |
ea6da257 CB |
752 | |
753 | status += [ | |
20b03401 SG |
754 | '', |
755 | 'supported calls: @0@'.format(', '.join(found_syscalls)), | |
756 | '', | |
757 | 'unsupported calls: @0@'.format(', '.join(missing_syscalls)), | |
758 | ''] | |
ea6da257 CB |
759 | |
760 | status += [ | |
20b03401 SG |
761 | '', |
762 | 'supported types: @0@'.format(', '.join(found_types)), | |
763 | '', | |
764 | 'unsupported types: @0@'.format(', '.join(missing_types)), | |
765 | ''] | |
ea6da257 | 766 | |
20b03401 | 767 | message('\n '.join(status)) |