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