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