]> git.proxmox.com Git - mirror_lxc.git/blame - meson.build
build: add meson skeleton
[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: [
7 'c_std=gnu11',
8 'warning_level=2',
9 ],
10 meson_version : '>= 0.45',
11 )
12
13liblxc_version = '4.0.0'
14
15conf = configuration_data()
16conf.set_quoted('PROJECT_URL', 'https://linuxcontainers.org/lxc/introduction/')
17conf.set('PROJECT_VERSION', meson.project_version(),
18 description : 'Numerical project version (used where a simple number is expected)')
19
20version_data = configuration_data()
21version_data.set('LXC_VERSION_MAJOR', '4')
22version_data.set('LXC_VERSION_MINOR', '0')
23version_data.set('LXC_VERSION_MICRO', '7')
24version_data.set('LXC_ABI', '4.0.7')
25version_data.set('LXC_DEVEL', '1')
26version_data.set('LXC_VERSION', '4.0.7-devel')
27
28project_source_root = meson.current_source_dir()
29project_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.
34prefixdir = get_option('prefix')
35if not prefixdir.startswith('/')
36 error('Prefix is not absolute: "@0@"'.format(prefixdir))
37endif
38datadir = join_paths(prefixdir, get_option('datadir'))
39bindir = join_paths(prefixdir, get_option('bindir'))
40sbindir = join_paths(prefixdir, get_option('sbindir'))
41includedir = join_paths(prefixdir, get_option('includedir'))
42libdir = join_paths(prefixdir, get_option('libdir'))
43libexecdir = join_paths(prefixdir, get_option('libexecdir'))
44sysconfdir = join_paths(prefixdir, get_option('sysconfdir'))
45runtimepath = join_paths(prefixdir, get_option('runtime-path'))
46localstatedir = join_paths('/', get_option('localstatedir'))
47apparmorcachedir = get_option('apparmor-cache-dir')
48rootfsmount = get_option('rootfs-mount-dir')
49cgrouppattern = get_option('cgroup-pattern')
50logpath = get_option('log-path')
51lxcpath = get_option('config-path')
52globalconfig = get_option('global-config')
53
54conf.set_quoted('BINDIR', bindir)
55conf.set_quoted('SBINDIR', sbindir)
56conf.set_quoted('INCLUDEDIR', includedir)
57conf.set_quoted('LIBDIR', libdir)
58conf.set_quoted('LIBEXECDIR', libexecdir)
59conf.set_quoted('SYSCONFDIR', sysconfdir)
60conf.set_quoted('LXC_DEFAULT_CONFIG', join_paths(sysconfdir, 'lxc/default.conf'))
61conf.set_quoted('APPARMOR_CACHE_DIR', join_paths(localstatedir, apparmorcachedir))
62conf.set_quoted('LXCROOTFSMOUNT', join_paths(prefixdir, rootfsmount))
63conf.set_quoted('DEFAULT_CGROUP_PATTERN', cgrouppattern)
64conf.set_quoted('RUNTIME_PATH', runtimepath)
65conf.set_quoted('LOGPATH', join_paths(localstatedir, logpath))
66conf.set_quoted('LXCPATH', join_paths(localstatedir, lxcpath))
67conf.set_quoted('LXC_GLOBAL_CONF', join_paths(sysconfdir, globalconfig))
68conf.set_quoted('DATADIR', datadir)
69conf.set_quoted('LXCTEMPLATECONFIG', join_paths(datadir, 'lxc/config'))
70conf.set_quoted('LXCTEMPLATEDIR', join_paths(datadir, 'lxc/templates'))
71conf.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
89cc = meson.get_compiler('c')
90pkgconfig = import('pkgconfig')
91
92possible_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
133possible_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
142if meson.version().version_compare('>=0.46')
143 add_project_link_arguments(cc.get_supported_link_arguments(possible_link_flags), language : 'c')
144else
145 add_project_link_arguments(possible_link_flags, language : 'c')
146endif
147
148add_project_arguments(cc.get_supported_arguments(possible_cc_flags), language : 'c')
149
150foreach 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))
161endforeach
162
163decl_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
173foreach 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
186endforeach
187
188foreach 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
234endforeach
235
236threads = dependency('threads')
237libseccomp = cc.find_library('seccomp', required : false)
238if 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
266endif
267
268libselinux = cc.find_library('selinux', required : false)
269if libselinux.found()
270 conf.set10('HAVE_SELINUX', libselinux.found())
271endif
272
273libapparmor = cc.find_library('apparmor', required : false)
274if libapparmor.found()
275 conf.set10('HAVE_APPARMOR', libapparmor.found())
276endif
277
278libopenssl = dependency('openssl', required : false)
279if libopenssl.found()
280 conf.set10('HAVE_OPENSSL', libopenssl.found())
281endif
282
283libcap = dependency('libcap', required : false)
284if not libcap.found()
285 # Compat with Ubuntu 14.04 which ships libcap w/o .pc file
286 libcap = cc.find_library('cap')
287endif
288
289if libcap.found()
290 conf.set10('HAVE_LIBCAP', libcap.found())
291endif
292
293basic_includes = include_directories(
294 'src',
295 'src/include',
296 '.')
297
298liblxc_includes = [basic_includes, include_directories(
299 'src/lxc/cgroups',
300 'src/lxc/lsm',
301 'src/lxc/storage')]
302
303add_project_arguments('-include', 'config.h', language : 'c')
304
305subdir('src/include')
306subdir('src/lxc')
307
308config_h = configure_file(
309 output : 'config.h',
310 configuration : conf)
311
312liblxc = 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)