]> git.proxmox.com Git - mirror_lxcfs.git/blame - meson.build
init: Fix install paths for sysvinit and openrc
[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',
64045b1c 7 version: '5.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')
83d9dee7 72want_docs= get_option('docs')
1fbf5591 73
3c34a198
SG
74
75# Build flags.
1fbf5591 76possible_cc_flags = [
3c34a198
SG
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',
1fbf5591
CB
113]
114
115possible_link_flags = [
3c34a198
SG
116 '-Wl,--gc-sections',
117 '-Wl,-z,relro',
118 '-Wl,-z,now',
119 '-Wl,-fuse-ld=gold',
1fbf5591
CB
120]
121
122if meson.version().version_compare('>=0.46')
3c34a198 123 add_project_link_arguments(cc.get_supported_link_arguments(possible_link_flags), language: 'c')
1fbf5591 124else
3c34a198 125 add_project_link_arguments(possible_link_flags, language: 'c')
1fbf5591
CB
126endif
127
3c34a198
SG
128add_project_arguments(cc.get_supported_arguments(possible_cc_flags), language: 'c')
129
130# Feature detection.
131foreach 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>'''],
1fbf5591 144]
3c34a198
SG
145 have = cc.has_function(ident[0], prefix: ident[1], args: '-D_GNU_SOURCE')
146 conf.set10('HAVE_' + ident[0].to_upper(), have)
1fbf5591
CB
147endforeach
148
a3a42a5d
WB
149fuse_version = get_option('fuse-version')
150if fuse_version == '3' or fuse_version == 'auto'
151 libfuse = dependency('fuse3', required: false)
152 if libfuse.found()
153 conf.set10('HAVE_FUSE3', true)
154 conf.set('FUSE_USE_VERSION', 35)
155 if libfuse.version().version_compare('>=3.10.3')
156 conf.set10('HAVE_FUSE_RETURNS_DT_TYPE', true)
157 else
158 conf.set10('HAVE_FUSE_RETURNS_DT_TYPE', false)
159 endif
888ab80a 160 endif
a3a42a5d
WB
161endif
162
163if fuse_version == '2' or (not libfuse.found() and fuse_version == 'auto')
3c34a198
SG
164 libfuse = dependency('fuse', version: '>= 2.6')
165 if libfuse.found()
166 conf.set10('HAVE_FUSE', true)
167 conf.set('FUSE_USE_VERSION', 26)
a3a42a5d 168 conf.set10('HAVE_FUSE_RETURNS_DT_TYPE', true)
3c34a198 169 endif
1fbf5591
CB
170endif
171
a3a42a5d
WB
172if not libfuse.found()
173 error('no usable fuse version found')
174endif
175
1fbf5591
CB
176libdl = cc.find_library('dl')
177threads = dependency('threads')
178
179config_h = configure_file(
3c34a198
SG
180 output: 'config.h',
181 configuration: conf)
1fbf5591 182config_include = include_directories('.')
3c34a198 183add_project_arguments('-include', 'config.h', language: 'c')
1fbf5591 184
3c34a198 185# Binary.
1fbf5591 186lxcfs_sources = files('src/lxcfs.c')
83d9dee7 187lxcfs = executable(
3c34a198
SG
188 'lxcfs',
189 lxcfs_sources,
190 dependencies: [
191 threads,
192 libdl,
193 libfuse,
194 ],
195 install: true,
196 install_dir: bindir)
197
198# Library.
1fbf5591 199liblxcfs_sources = files(
3c34a198
SG
200 'src/api_extensions.h',
201 'src/bindings.c',
202 'src/bindings.h',
203 'src/cgroups/cgfsng.c',
204 'src/cgroups/cgroup.c',
205 'src/cgroups/cgroup.h',
206 'src/cgroups/cgroup2_devices.c',
207 'src/cgroups/cgroup2_devices.h',
208 'src/cgroups/cgroup_utils.c',
209 'src/cgroups/cgroup_utils.h',
210 'src/cgroup_fuse.c',
211 'src/cgroup_fuse.h',
212 'src/cpuset_parse.c',
213 'src/cpuset_parse.h',
214 'src/lxcfs.c',
215 'src/lxcfs_fuse.h',
216 'src/lxcfs_fuse_compat.h',
217 'src/macro.h',
218 'src/memory_utils.h',
219 'src/proc_cpuview.c',
220 'src/proc_cpuview.h',
221 'src/proc_fuse.c',
222 'src/proc_fuse.h',
223 'src/proc_loadavg.c',
224 'src/proc_loadavg.h',
225 'src/syscall_numbers.h',
226 'src/sysfs_fuse.c',
227 'src/sysfs_fuse.h',
228 'src/utils.c',
229 'src/utils.h')
1fbf5591 230
1314b3b8 231liblxcfs_common_dependencies = declare_dependency(
3c34a198
SG
232 sources: liblxcfs_sources,
233 dependencies: [
234 threads,
235 libfuse,
236 ])
1314b3b8 237
a962e7a1 238liblxcfs = shared_module(
3c34a198
SG
239 'lxcfs',
240 liblxcfs_sources,
241 dependencies: liblxcfs_common_dependencies,
242 install: true,
243 install_dir: lxcfsdir)
1fbf5591 244
3c34a198
SG
245# Tests.
246test_programs = []
1fbf5591 247if want_tests == true
3c34a198
SG
248 liblxcfs_test = shared_module(
249 'lxcfstest',
250 liblxcfs_sources,
251 dependencies: liblxcfs_common_dependencies,
252 install: false,
253 install_dir: lxcfsdir,
254 c_args: '-DRELOADTEST -DDEBUG')
1fbf5591
CB
255endif
256
3c34a198 257# RPM spec.
e5af758b 258lxcfs_spec = custom_target(
3c34a198
SG
259 'lxcfs.spec',
260 build_by_default: true,
261 input: 'lxcfs.spec.in',
262 output: 'lxcfs.spec',
263 command: [
264 meson_render_jinja2,
265 config_h,
266 '@INPUT@',
267 '@OUTPUT@',
268 ])
269
83d9dee7
ML
270# Man pages
271if want_docs == true
272 help2man = find_program('help2man')
273 help2man_opts = [
274 '--name="System virtualization filesystem for containers"',
275 '--no-discard-stderr',
276 '--section=1',
277 '--opt-include=docs/lxcfs.man.add',
278 '--no-info',
279 ]
280 custom_target('lxcfs.1',
281 output: 'lxcfs.1',
282 command: [help2man, help2man_opts, '--output=@OUTPUT@', lxcfs],
283 install: true,
284 install_dir: join_paths(lxcmandir, 'man1'))
285endif
286
287
3c34a198 288# Include sub-directories.
e5af758b 289subdir('config/init')
3c34a198
SG
290subdir('share')
291subdir('tests')
d90ab57e 292
3c34a198 293# Build overview.
1fbf5591 294status = [
3c34a198
SG
295 '@0@ @1@'.format(meson.project_name(), meson.project_version()),
296
297 'FUSE version: @0@'.format(libfuse.version()),
298 'bin directory: @0@'.format(bindir),
299 'lib directory: @0@'.format(libdir),
300 'data directory: @0@'.format(datadir),
301 'local state directory: @0@'.format(localstatedir),
302 'prefix directory: @0@'.format(prefixdir),
303 'runtime directory: @0@'.format(runtimepath),
304 'sysconf directory: @0@'.format(sysconfdir),
305 'lxc conf directory: @0@'.format(lxcconfdir),
306 'lxcfs directory: @0@'.format(lxcfsdir),
307 'lxcfs shared directory: @0@'.format(lxcfssharedir),
308 'lxcfs build root directory: @0@'.format(project_build_root),
309 'lxcfs source root directory: @0@'.format(project_source_root),
310 'init system: @0@'.format(init_script),
311 'tests: @0@'.format(want_tests),
83d9dee7 312 'documentation: @0@'.format(want_docs),
3c34a198 313]
1fbf5591 314message('\n '.join(status))