]> git.proxmox.com Git - mirror_lxcfs.git/blame - meson.build
Release LXCFS 6.0.0
[mirror_lxcfs.git] / meson.build
CommitLineData
1fbf5591
CB
1# SPDX-License-Identifier: LGPL-2.1-or-later
2
3c34a198
SG
3# Project.
4project(
5 'lxcfs',
6 'c',
d837e798 7 version: '6.0.0',
3c34a198
SG
8 license: 'LGPLv2+',
9 default_options: [
10 'b_colorout=always',
11 'b_asneeded=true',
12 'b_pie=true',
13 'c_std=gnu11',
14 'warning_level=2',
15 ],
16 meson_version: '>= 0.50')
1fbf5591 17
3c34a198
SG
18cc = meson.get_compiler('c')
19
20# Templater.
776b8594
SG
21if run_command(
22 'python3', '-c', 'import jinja2',
23 check: false).returncode() != 0
3c34a198
SG
24 error('python3 jinja2 missing')
25endif
26
27meson_build_sh = find_program('tools/meson-build.sh')
28meson_render_jinja2 = find_program('tools/meson-render-jinja2.py')
29
30# Configuration options.
1fbf5591 31conf = configuration_data()
e5af758b 32conf.set_quoted('PROJECT', meson.project_name())
3c34a198
SG
33conf.set_quoted('PROJECT_URL', 'https://linuxcontainers.org/lxcfs/')
34conf.set_quoted('PROJECT_VERSION', meson.project_version())
35conf.set_quoted('PACKAGE_VERSION', meson.project_version())
915700c3
CB
36conf.set('_GNU_SOURCE', true)
37conf.set('_FILE_OFFSET_BITS', 64)
38conf.set('__STDC_FORMAT_MACROS', true)
39
1fbf5591
CB
40project_source_root = meson.current_source_dir()
41project_build_root = meson.current_build_dir()
42
3c34a198 43# Path handling.
1fbf5591 44prefixdir = get_option('prefix')
1fbf5591
CB
45bindir = join_paths(prefixdir, get_option('bindir'))
46libdir = join_paths(prefixdir, get_option('libdir'))
47lxcfsdir = join_paths(libdir, 'lxcfs')
48sysconfdir = join_paths(prefixdir, get_option('sysconfdir'))
49runtimepath = join_paths(prefixdir, get_option('runtime-path'))
50localstatedir = join_paths('/', get_option('localstatedir'))
0d2038cd 51datadir = join_paths(prefixdir, get_option('datadir'))
1fbf5591 52
0d2038cd 53lxcfssharedir = join_paths(datadir, 'lxcfs')
0d2038cd 54lxcconfdir = join_paths(datadir, 'lxc/config/common.conf.d')
83d9dee7 55lxcmandir = join_paths(datadir, 'man')
0d2038cd 56
3c34a198
SG
57conf.set_quoted('BINDIR', bindir)
58conf.set_quoted('LIBDIR', libdir)
59conf.set_quoted('LOCALSTATEDIR', localstatedir)
60conf.set_quoted('RUNTIME_PATH', runtimepath)
61conf.set_quoted('SYSCONFDIR', sysconfdir)
1fbf5591 62
3c34a198
SG
63conf.set_quoted('LXCCONFDIR', lxcconfdir)
64conf.set_quoted('LXCFS_BUILD_ROOT', project_build_root)
65conf.set_quoted('LXCFSSHAREDIR', lxcfssharedir)
66conf.set_quoted('LXCFS_SOURCE_ROOT', project_source_root)
67conf.set_quoted('LXCFSTARGETDIR', join_paths(localstatedir, 'lib/lxcfs'))
e5af758b 68
3c34a198
SG
69# Custom configuration.
70init_script = get_option('init-script')
1fbf5591 71want_tests = get_option('tests')
bc6251be 72want_docs = get_option('docs')
1fbf5591 73
3c34a198 74# Build flags.
1fbf5591 75possible_cc_flags = [
3c34a198
SG
76 '-Wvla',
77 '-Wimplicit-fallthrough=5',
78 '-Wcast-align',
79 '-Wstrict-prototypes',
80 '-fno-strict-aliasing',
81 '-fstack-clash-protection',
82 '-fstack-protector-strong',
83 '--param=ssp-buffer-size=4',
84 '--mcet -fcf-protection',
85 '-Werror=implicit-function-declaration',
86 '-Wlogical-op',
87 '-Wmissing-include-dirs',
88 '-Wold-style-definition',
89 '-Winit-self',
90 '-Wunused-but-set-variable',
91 '-Wno-unused-parameter',
92 '-Wfloat-equal',
93 '-Wsuggest-attribute=noreturn',
94 '-Werror=return-type',
95 '-Werror=incompatible-pointer-types',
96 '-Wformat=2',
97 '-Wshadow',
98 '-Wendif-labels',
99 '-Werror=overflow',
100 '-fdiagnostics-show-option',
101 '-Werror=shift-count-overflow',
102 '-Werror=shift-overflow=2',
103 '-Wdate-time',
104 '-Wnested-externs',
105 '-fasynchronous-unwind-tables',
106 '-fexceptions',
107 '-Warray-bounds',
108 '-Wrestrict',
109 '-Wreturn-local-addr',
110 '-fsanitize=cfi',
111 '-Wstringop-overflow',
1fbf5591
CB
112]
113
114possible_link_flags = [
3c34a198
SG
115 '-Wl,--gc-sections',
116 '-Wl,-z,relro',
117 '-Wl,-z,now',
118 '-Wl,-fuse-ld=gold',
1fbf5591
CB
119]
120
121if meson.version().version_compare('>=0.46')
3c34a198 122 add_project_link_arguments(cc.get_supported_link_arguments(possible_link_flags), language: 'c')
1fbf5591 123else
3c34a198 124 add_project_link_arguments(possible_link_flags, language: 'c')
1fbf5591
CB
125endif
126
3c34a198
SG
127add_project_arguments(cc.get_supported_arguments(possible_cc_flags), language: 'c')
128
129# Feature detection.
130foreach ident: [
131 ['strlcpy', '''#include <string.h>'''],
132 ['strlcat', '''#include <string.h>'''],
133 ['pidfd_send_signal',
134 '''#include <stdlib.h>
135 #include <unistd.h>
136 #include <signal.h>
137 #include <sys/wait.h>'''],
138 ['pidfd_open',
139 '''#include <stdlib.h>
140 #include <unistd.h>
141 #include <signal.h>
142 #include <sys/wait.h>'''],
1fbf5591 143]
3c34a198
SG
144 have = cc.has_function(ident[0], prefix: ident[1], args: '-D_GNU_SOURCE')
145 conf.set10('HAVE_' + ident[0].to_upper(), have)
1fbf5591
CB
146endforeach
147
a3a42a5d
WB
148fuse_version = get_option('fuse-version')
149if fuse_version == '3' or fuse_version == 'auto'
150 libfuse = dependency('fuse3', required: false)
151 if libfuse.found()
152 conf.set10('HAVE_FUSE3', true)
153 conf.set('FUSE_USE_VERSION', 35)
154 if libfuse.version().version_compare('>=3.10.3')
155 conf.set10('HAVE_FUSE_RETURNS_DT_TYPE', true)
156 else
157 conf.set10('HAVE_FUSE_RETURNS_DT_TYPE', false)
158 endif
888ab80a 159 endif
a3a42a5d
WB
160endif
161
162if fuse_version == '2' or (not libfuse.found() and fuse_version == 'auto')
3c34a198
SG
163 libfuse = dependency('fuse', version: '>= 2.6')
164 if libfuse.found()
165 conf.set10('HAVE_FUSE', true)
166 conf.set('FUSE_USE_VERSION', 26)
a3a42a5d 167 conf.set10('HAVE_FUSE_RETURNS_DT_TYPE', true)
3c34a198 168 endif
1fbf5591
CB
169endif
170
a3a42a5d
WB
171if not libfuse.found()
172 error('no usable fuse version found')
173endif
174
1fbf5591
CB
175libdl = cc.find_library('dl')
176threads = dependency('threads')
177
178config_h = configure_file(
3c34a198
SG
179 output: 'config.h',
180 configuration: conf)
1fbf5591 181config_include = include_directories('.')
3c34a198 182add_project_arguments('-include', 'config.h', language: 'c')
1fbf5591 183
3c34a198 184# Binary.
1fbf5591 185lxcfs_sources = files('src/lxcfs.c')
83d9dee7 186lxcfs = executable(
3c34a198
SG
187 'lxcfs',
188 lxcfs_sources,
189 dependencies: [
190 threads,
191 libdl,
192 libfuse,
193 ],
194 install: true,
195 install_dir: bindir)
196
197# Library.
1fbf5591 198liblxcfs_sources = files(
3c34a198
SG
199 'src/api_extensions.h',
200 'src/bindings.c',
201 'src/bindings.h',
202 'src/cgroups/cgfsng.c',
203 'src/cgroups/cgroup.c',
204 'src/cgroups/cgroup.h',
3c34a198
SG
205 'src/cgroups/cgroup_utils.c',
206 'src/cgroups/cgroup_utils.h',
207 'src/cgroup_fuse.c',
208 'src/cgroup_fuse.h',
209 'src/cpuset_parse.c',
210 'src/cpuset_parse.h',
211 'src/lxcfs.c',
212 'src/lxcfs_fuse.h',
213 'src/lxcfs_fuse_compat.h',
214 'src/macro.h',
215 'src/memory_utils.h',
216 'src/proc_cpuview.c',
217 'src/proc_cpuview.h',
218 'src/proc_fuse.c',
219 'src/proc_fuse.h',
220 'src/proc_loadavg.c',
221 'src/proc_loadavg.h',
222 'src/syscall_numbers.h',
223 'src/sysfs_fuse.c',
224 'src/sysfs_fuse.h',
225 'src/utils.c',
226 'src/utils.h')
1fbf5591 227
1314b3b8 228liblxcfs_common_dependencies = declare_dependency(
3c34a198
SG
229 sources: liblxcfs_sources,
230 dependencies: [
231 threads,
232 libfuse,
233 ])
1314b3b8 234
a962e7a1 235liblxcfs = shared_module(
3c34a198
SG
236 'lxcfs',
237 liblxcfs_sources,
238 dependencies: liblxcfs_common_dependencies,
239 install: true,
240 install_dir: lxcfsdir)
1fbf5591 241
3c34a198
SG
242# Tests.
243test_programs = []
1fbf5591 244if want_tests == true
3c34a198
SG
245 liblxcfs_test = shared_module(
246 'lxcfstest',
247 liblxcfs_sources,
248 dependencies: liblxcfs_common_dependencies,
249 install: false,
250 install_dir: lxcfsdir,
251 c_args: '-DRELOADTEST -DDEBUG')
1fbf5591
CB
252endif
253
3c34a198 254# RPM spec.
e5af758b 255lxcfs_spec = custom_target(
3c34a198
SG
256 'lxcfs.spec',
257 build_by_default: true,
258 input: 'lxcfs.spec.in',
259 output: 'lxcfs.spec',
260 command: [
261 meson_render_jinja2,
262 config_h,
263 '@INPUT@',
264 '@OUTPUT@',
265 ])
266
83d9dee7
ML
267# Man pages
268if want_docs == true
269 help2man = find_program('help2man')
270 help2man_opts = [
271 '--name="System virtualization filesystem for containers"',
272 '--no-discard-stderr',
273 '--section=1',
274 '--opt-include=docs/lxcfs.man.add',
275 '--no-info',
276 ]
277 custom_target('lxcfs.1',
278 output: 'lxcfs.1',
279 command: [help2man, help2man_opts, '--output=@OUTPUT@', lxcfs],
280 install: true,
281 install_dir: join_paths(lxcmandir, 'man1'))
282endif
283
284
3c34a198 285# Include sub-directories.
e5af758b 286subdir('config/init')
3c34a198
SG
287subdir('share')
288subdir('tests')
d90ab57e 289
3c34a198 290# Build overview.
1fbf5591 291status = [
3c34a198
SG
292 '@0@ @1@'.format(meson.project_name(), meson.project_version()),
293
294 'FUSE version: @0@'.format(libfuse.version()),
295 'bin directory: @0@'.format(bindir),
296 'lib directory: @0@'.format(libdir),
297 'data directory: @0@'.format(datadir),
298 'local state directory: @0@'.format(localstatedir),
299 'prefix directory: @0@'.format(prefixdir),
300 'runtime directory: @0@'.format(runtimepath),
301 'sysconf directory: @0@'.format(sysconfdir),
302 'lxc conf directory: @0@'.format(lxcconfdir),
303 'lxcfs directory: @0@'.format(lxcfsdir),
304 'lxcfs shared directory: @0@'.format(lxcfssharedir),
305 'lxcfs build root directory: @0@'.format(project_build_root),
306 'lxcfs source root directory: @0@'.format(project_source_root),
40e23aff 307 'init system(s): @0@'.format(init_script),
3c34a198 308 'tests: @0@'.format(want_tests),
83d9dee7 309 'documentation: @0@'.format(want_docs),
3c34a198 310]
1fbf5591 311message('\n '.join(status))