]>
Commit | Line | Data |
---|---|---|
9b9d56e6 CB |
1 | # SPDX-License-Identifier: LGPL-2.1-or-later |
2 | ||
3 | project('lxc', 'c', | |
4 | version : '4.0.0', | |
5 | license : 'LGPLv2+', | |
6 | default_options: [ | |
7 | 'c_std=gnu11', | |
8 | 'warning_level=2', | |
9 | ], | |
10 | meson_version : '>= 0.45', | |
11 | ) | |
12 | ||
13 | liblxc_version = '4.0.0' | |
14 | ||
15 | conf = configuration_data() | |
16 | conf.set_quoted('PROJECT_URL', 'https://linuxcontainers.org/lxc/introduction/') | |
17 | conf.set('PROJECT_VERSION', meson.project_version(), | |
18 | description : 'Numerical project version (used where a simple number is expected)') | |
19 | ||
20 | version_data = configuration_data() | |
21 | version_data.set('LXC_VERSION_MAJOR', '4') | |
22 | version_data.set('LXC_VERSION_MINOR', '0') | |
23 | version_data.set('LXC_VERSION_MICRO', '7') | |
24 | version_data.set('LXC_ABI', '4.0.7') | |
25 | version_data.set('LXC_DEVEL', '1') | |
26 | version_data.set('LXC_VERSION', '4.0.7-devel') | |
27 | ||
28 | project_source_root = meson.current_source_dir() | |
29 | project_build_root = meson.current_build_dir() | |
30 | ||
31 | # join_paths ignores the preceding arguments if an absolute component is | |
32 | # encountered, so this should canonicalize various paths when they are | |
33 | # absolute or relative. | |
34 | prefixdir = get_option('prefix') | |
35 | if not prefixdir.startswith('/') | |
36 | error('Prefix is not absolute: "@0@"'.format(prefixdir)) | |
37 | endif | |
38 | datadir = join_paths(prefixdir, get_option('datadir')) | |
39 | bindir = join_paths(prefixdir, get_option('bindir')) | |
40 | sbindir = join_paths(prefixdir, get_option('sbindir')) | |
41 | includedir = join_paths(prefixdir, get_option('includedir')) | |
42 | libdir = join_paths(prefixdir, get_option('libdir')) | |
43 | libexecdir = join_paths(prefixdir, get_option('libexecdir')) | |
44 | sysconfdir = join_paths(prefixdir, get_option('sysconfdir')) | |
45 | runtimepath = join_paths(prefixdir, get_option('runtime-path')) | |
46 | localstatedir = join_paths('/', get_option('localstatedir')) | |
47 | apparmorcachedir = get_option('apparmor-cache-dir') | |
48 | rootfsmount = get_option('rootfs-mount-dir') | |
49 | cgrouppattern = get_option('cgroup-pattern') | |
50 | logpath = get_option('log-path') | |
51 | lxcpath = get_option('config-path') | |
52 | globalconfig = get_option('global-config') | |
53 | ||
54 | conf.set_quoted('BINDIR', bindir) | |
55 | conf.set_quoted('SBINDIR', sbindir) | |
56 | conf.set_quoted('INCLUDEDIR', includedir) | |
57 | conf.set_quoted('LIBDIR', libdir) | |
58 | conf.set_quoted('LIBEXECDIR', libexecdir) | |
59 | conf.set_quoted('SYSCONFDIR', sysconfdir) | |
60 | conf.set_quoted('LXC_DEFAULT_CONFIG', join_paths(sysconfdir, 'lxc/default.conf')) | |
61 | conf.set_quoted('APPARMOR_CACHE_DIR', join_paths(localstatedir, apparmorcachedir)) | |
62 | conf.set_quoted('LXCROOTFSMOUNT', join_paths(prefixdir, rootfsmount)) | |
63 | conf.set_quoted('DEFAULT_CGROUP_PATTERN', cgrouppattern) | |
64 | conf.set_quoted('RUNTIME_PATH', runtimepath) | |
65 | conf.set_quoted('LOGPATH', join_paths(localstatedir, logpath)) | |
66 | conf.set_quoted('LXCPATH', join_paths(localstatedir, lxcpath)) | |
67 | conf.set_quoted('LXC_GLOBAL_CONF', join_paths(sysconfdir, globalconfig)) | |
68 | conf.set_quoted('DATADIR', datadir) | |
69 | conf.set_quoted('LXCTEMPLATECONFIG', join_paths(datadir, 'lxc/config')) | |
70 | conf.set_quoted('LXCTEMPLATEDIR', join_paths(datadir, 'lxc/templates')) | |
71 | conf.set_quoted('LXCINITDIR', libexecdir) | |
72 | ||
73 | # AS_AC_EXPAND(DATADIR, "$datadir") | |
74 | # AS_AC_EXPAND(LOCALSTATEDIR, "$localstatedir") | |
75 | # AS_AC_EXPAND(DOCDIR, "$docdir") | |
76 | # AS_AC_EXPAND(LXC_GENERATE_DATE, "$(date --utc --date=@${SOURCE_DATE_EPOCH:-$(date +%s)} '+%Y-%m-%d')") | |
77 | # AS_AC_EXPAND(LXCPATH, "$with_config_path") | |
78 | # AS_AC_EXPAND(LXC_GLOBAL_CONF, "$with_global_conf") | |
79 | # AS_AC_EXPAND(LXC_USERNIC_CONF, "$with_usernic_conf") | |
80 | # AS_AC_EXPAND(LXC_USERNIC_DB, "$with_usernic_db") | |
81 | # AS_AC_EXPAND(LXC_DISTRO_SYSCONF, "$distrosysconf") | |
82 | # AS_AC_EXPAND(LXCHOOKDIR, "$datadir/lxc/hooks") | |
83 | # AS_AC_EXPAND(LXCBINHOOKDIR, "$libexecdir/lxc/hooks") | |
84 | # AS_AC_EXPAND(LXCINITDIR, "$libexecdir") | |
85 | # | |
86 | # # We need the install path so criu knows where to reference the hook scripts. | |
87 | # AC_DEFINE_UNQUOTED([DATADIR], "$DATADIR", ["Prefix for shared files."]) | |
88 | ||
89 | cc = meson.get_compiler('c') | |
90 | pkgconfig = import('pkgconfig') | |
91 | ||
92 | possible_cc_flags = [ | |
93 | '-fPIE', | |
94 | '-Wvla', | |
95 | '-fdiagnostics-color', | |
96 | '-Wimplicit-fallthrough=5', | |
97 | '-Wcast-align', | |
98 | '-Wstrict-prototypes', | |
99 | '-fno-strict-aliasing', | |
100 | '-fstack-clash-protection', | |
101 | '-fstack-protector-strong', | |
102 | '--param=ssp-buffer-size=4', | |
103 | '--mcet -fcf-protection', | |
104 | '-Werror=implicit-function-declaration', | |
105 | '-Wlogical-op', | |
106 | '-Wmissing-include-dirs', | |
107 | '-Wold-style-definition', | |
108 | '-Winit-self', | |
109 | '-Wunused-but-set-variable', | |
110 | '-Wno-unused-parameter', | |
111 | '-Wfloat-equal', | |
112 | '-Wsuggest-attribute=noreturn', | |
113 | '-Werror=return-type', | |
114 | '-Werror=incompatible-pointer-types', | |
115 | '-Wformat=2', | |
116 | '-Wshadow', | |
117 | '-Wendif-labels', | |
118 | '-Werror=overflow', | |
119 | '-fdiagnostics-show-option', | |
120 | '-Werror=shift-count-overflow', | |
121 | '-Werror=shift-overflow=2', | |
122 | '-Wdate-time', | |
123 | '-Wnested-externs', | |
124 | '-fasynchronous-unwind-tables', | |
125 | '-fexceptions', | |
126 | '-Warray-bounds', | |
127 | '-Wrestrict', | |
128 | '-Wreturn-local-addr', | |
129 | '-fsanitize=cfi', | |
130 | '-Wstringop-overflow', | |
131 | ] | |
132 | ||
133 | possible_link_flags = [ | |
134 | '-Wl,--as-needed', | |
135 | '-Wl,--gc-sections', | |
136 | '-Wl,-z,relro', | |
137 | '-Wl,-z,now', | |
138 | '-pie', | |
139 | '-Wl,-fuse-ld=gold', | |
140 | ] | |
141 | ||
142 | if meson.version().version_compare('>=0.46') | |
143 | add_project_link_arguments(cc.get_supported_link_arguments(possible_link_flags), language : 'c') | |
144 | else | |
145 | add_project_link_arguments(possible_link_flags, language : 'c') | |
146 | endif | |
147 | ||
148 | add_project_arguments(cc.get_supported_arguments(possible_cc_flags), language : 'c') | |
149 | ||
150 | foreach header : ['sys/resource.h', | |
151 | 'sys/memfd.h', | |
152 | 'sys/personality.h', | |
153 | 'sys/signalfd.h', | |
154 | 'sys/timerfd.h', | |
155 | 'pty.h', | |
156 | 'utmpx.h', | |
157 | ] | |
158 | ||
159 | conf.set10('HAVE_' + header.underscorify().to_upper(), | |
160 | cc.has_header(header)) | |
161 | endforeach | |
162 | ||
163 | decl_headers = ''' | |
164 | #include <uchar.h> | |
165 | #include <sys/mount.h> | |
166 | #include <sys/stat.h> | |
167 | #include <linux/fs.h> | |
168 | #include <linux/types.h> | |
169 | #include <linux/openat2.h> | |
170 | #include <linux/sched.h> | |
171 | ''' | |
172 | ||
173 | foreach decl : [ | |
174 | '__aligned_u64', | |
175 | 'struct mount_attr', | |
176 | 'struct open_how', | |
177 | 'struct clone_args', | |
178 | ] | |
179 | ||
180 | # We get -1 if the size cannot be determined | |
181 | have = cc.sizeof(decl, prefix : decl_headers, args : '-D_GNU_SOURCE') > 0 | |
182 | ||
183 | if have == true | |
184 | conf.set10('HAVE_' + decl.underscorify().to_upper(), have) | |
185 | endif | |
186 | endforeach | |
187 | ||
188 | foreach ident : [ | |
189 | ['memfd_create', '''#include <sys/mman.h>'''], | |
190 | ['gettid', '''#include <sys/types.h> | |
191 | #include <unistd.h>'''], | |
192 | ['pivot_root', '''#include <stdlib.h> | |
193 | #include <unistd.h>'''], # no known header declares pivot_root | |
194 | ['setns', '''#include <sched.h>'''], | |
195 | ['renameat2', '''#include <stdio.h> | |
196 | #include <fcntl.h>'''], | |
197 | ['kcmp', '''#include <linux/kcmp.h>'''], | |
198 | ['keyctl', '''#include <sys/types.h> | |
199 | #include <keyutils.h>'''], | |
200 | ['bpf', '''#include <sys/syscall.h> | |
201 | #include <unistd.h>'''], | |
202 | ['statx', '''#include <sys/types.h> | |
203 | #include <sys/stat.h> | |
204 | #include <unistd.h>'''], | |
205 | ['pidfd_send_signal', '''#include <stdlib.h> | |
206 | #include <unistd.h> | |
207 | #include <signal.h> | |
208 | #include <sys/wait.h>'''], | |
209 | ['pidfd_open', '''#include <stdlib.h> | |
210 | #include <unistd.h> | |
211 | #include <signal.h> | |
212 | #include <sys/wait.h>'''], | |
213 | ['execveat', '''#include <unistd.h>'''], | |
214 | ['close_range', '''#include <unistd.h>'''], | |
215 | ['mount_setattr', '''#include <sys/mount.h>'''], | |
216 | ['move_mount', '''#include <sys/mount.h>'''], | |
217 | ['open_tree', '''#include <sys/mount.h>'''], | |
218 | ['strlcpy', '''#include <string.h>'''], | |
219 | ['strlcat', '''#include <string.h>'''], | |
220 | ['sethostname', '''#include <unistd.h>'''], | |
221 | ['faccessat', '''#include <fcntl.h> | |
222 | #include <unistd.h>'''], | |
223 | ['unshare', '''#include <sched.h>'''], | |
224 | ['prlimit', '''#include <sys/time.h> | |
225 | #include <sys/resource.h>'''], | |
226 | ['prlimit64', '''#include <sys/time.h> | |
227 | #include <sys/resource.h>'''], | |
228 | ] | |
229 | ||
230 | have = cc.has_function(ident[0], prefix : ident[1], args : '-D_GNU_SOURCE') | |
231 | if have == true | |
232 | conf.set10('HAVE_' + ident[0].to_upper(), have) | |
233 | endif | |
234 | endforeach | |
235 | ||
236 | threads = dependency('threads') | |
237 | libseccomp = cc.find_library('seccomp', required : false) | |
238 | if libseccomp.found() | |
239 | conf.set10('HAVE_SECCOMP', libseccomp.found()) | |
240 | ||
241 | seccomp_headers = ''' | |
242 | #include <seccomp.h> | |
243 | ''' | |
244 | ||
245 | if cc.has_function('seccomp_notify_fd', prefix : seccomp_headers, args : '-D_GNU_SOURCE', dependencies: libseccomp) | |
246 | conf.set10('HAVE_DECL_SECCOMP_NOTIFY_FD', true) | |
247 | endif | |
248 | ||
249 | if cc.has_function('seccomp_syscall_resolve_name_arch', prefix : seccomp_headers, args : '-D_GNU_SOURCE', dependencies: libseccomp) | |
250 | conf.set10('HAVE_DECL_SECCOMP_SYSCALL_RESOLVE_NAME_ARCH', true) | |
251 | endif | |
252 | ||
253 | foreach decl : [ | |
254 | 'scmp_filter_ctx', | |
255 | 'struct seccomp_notif_sizes', | |
256 | 'struct clone_args', | |
257 | ] | |
258 | ||
259 | # We get -1 if the size cannot be determined | |
260 | have = cc.sizeof(decl, prefix : seccomp_headers, args : '-D_GNU_SOURCE') > 0 | |
261 | ||
262 | if have == true | |
263 | conf.set10('HAVE_' + decl.underscorify().to_upper(), have) | |
264 | endif | |
265 | endforeach | |
266 | endif | |
267 | ||
268 | libselinux = cc.find_library('selinux', required : false) | |
269 | if libselinux.found() | |
270 | conf.set10('HAVE_SELINUX', libselinux.found()) | |
271 | endif | |
272 | ||
273 | libapparmor = cc.find_library('apparmor', required : false) | |
274 | if libapparmor.found() | |
275 | conf.set10('HAVE_APPARMOR', libapparmor.found()) | |
276 | endif | |
277 | ||
278 | libopenssl = dependency('openssl', required : false) | |
279 | if libopenssl.found() | |
280 | conf.set10('HAVE_OPENSSL', libopenssl.found()) | |
281 | endif | |
282 | ||
283 | libcap = dependency('libcap', required : false) | |
284 | if not libcap.found() | |
285 | # Compat with Ubuntu 14.04 which ships libcap w/o .pc file | |
286 | libcap = cc.find_library('cap') | |
287 | endif | |
288 | ||
289 | if libcap.found() | |
290 | conf.set10('HAVE_LIBCAP', libcap.found()) | |
291 | endif | |
292 | ||
293 | basic_includes = include_directories( | |
294 | 'src', | |
295 | 'src/include', | |
296 | '.') | |
297 | ||
298 | liblxc_includes = [basic_includes, include_directories( | |
299 | 'src/lxc/cgroups', | |
300 | 'src/lxc/lsm', | |
301 | 'src/lxc/storage')] | |
302 | ||
303 | add_project_arguments('-include', 'config.h', language : 'c') | |
304 | ||
305 | subdir('src/include') | |
306 | subdir('src/lxc') | |
307 | ||
308 | config_h = configure_file( | |
309 | output : 'config.h', | |
310 | configuration : conf) | |
311 | ||
312 | liblxc = shared_library( | |
313 | 'lxc', | |
314 | version : liblxc_version, | |
315 | include_directories : liblxc_includes, | |
316 | link_args : ['-shared', '-fPIC', '-DPIC'], | |
317 | link_whole : [liblxc_static], | |
318 | dependencies : [threads, | |
319 | libseccomp, | |
320 | libcap, | |
321 | libopenssl, | |
322 | libselinux, | |
323 | libapparmor], | |
324 | install : true, | |
325 | install_dir : libdir) |