]>
Commit | Line | Data |
---|---|---|
1fbf5591 CB |
1 | # SPDX-License-Identifier: LGPL-2.1-or-later |
2 | ||
3c34a198 SG |
3 | # Project. |
4 | project( | |
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 |
18 | cc = meson.get_compiler('c') |
19 | ||
20 | # Templater. | |
21 | if run_command('python3', '-c', 'import jinja2').returncode() != 0 | |
22 | error('python3 jinja2 missing') | |
23 | endif | |
24 | ||
25 | meson_build_sh = find_program('tools/meson-build.sh') | |
26 | meson_render_jinja2 = find_program('tools/meson-render-jinja2.py') | |
27 | ||
28 | # Configuration options. | |
1fbf5591 | 29 | conf = configuration_data() |
e5af758b | 30 | conf.set_quoted('PROJECT', meson.project_name()) |
3c34a198 SG |
31 | conf.set_quoted('PROJECT_URL', 'https://linuxcontainers.org/lxcfs/') |
32 | conf.set_quoted('PROJECT_VERSION', meson.project_version()) | |
33 | conf.set_quoted('PACKAGE_VERSION', meson.project_version()) | |
915700c3 CB |
34 | conf.set('_GNU_SOURCE', true) |
35 | conf.set('_FILE_OFFSET_BITS', 64) | |
36 | conf.set('__STDC_FORMAT_MACROS', true) | |
37 | ||
1fbf5591 CB |
38 | project_source_root = meson.current_source_dir() |
39 | project_build_root = meson.current_build_dir() | |
40 | ||
3c34a198 | 41 | # Path handling. |
1fbf5591 | 42 | prefixdir = get_option('prefix') |
1fbf5591 CB |
43 | bindir = join_paths(prefixdir, get_option('bindir')) |
44 | libdir = join_paths(prefixdir, get_option('libdir')) | |
45 | lxcfsdir = join_paths(libdir, 'lxcfs') | |
46 | sysconfdir = join_paths(prefixdir, get_option('sysconfdir')) | |
47 | runtimepath = join_paths(prefixdir, get_option('runtime-path')) | |
48 | localstatedir = join_paths('/', get_option('localstatedir')) | |
0d2038cd | 49 | datadir = join_paths(prefixdir, get_option('datadir')) |
1fbf5591 | 50 | |
0d2038cd | 51 | lxcfssharedir = join_paths(datadir, 'lxcfs') |
0d2038cd | 52 | lxcconfdir = join_paths(datadir, 'lxc/config/common.conf.d') |
0d2038cd | 53 | |
3c34a198 SG |
54 | conf.set_quoted('BINDIR', bindir) |
55 | conf.set_quoted('LIBDIR', libdir) | |
56 | conf.set_quoted('LOCALSTATEDIR', localstatedir) | |
57 | conf.set_quoted('RUNTIME_PATH', runtimepath) | |
58 | conf.set_quoted('SYSCONFDIR', sysconfdir) | |
1fbf5591 | 59 | |
3c34a198 SG |
60 | conf.set_quoted('LXCCONFDIR', lxcconfdir) |
61 | conf.set_quoted('LXCFS_BUILD_ROOT', project_build_root) | |
62 | conf.set_quoted('LXCFSSHAREDIR', lxcfssharedir) | |
63 | conf.set_quoted('LXCFS_SOURCE_ROOT', project_source_root) | |
64 | conf.set_quoted('LXCFSTARGETDIR', join_paths(localstatedir, 'lib/lxcfs')) | |
e5af758b | 65 | |
3c34a198 SG |
66 | # Custom configuration. |
67 | init_script = get_option('init-script') | |
1fbf5591 CB |
68 | want_tests = get_option('tests') |
69 | ||
3c34a198 SG |
70 | |
71 | # Build flags. | |
1fbf5591 | 72 | possible_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 | ||
111 | possible_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 | ||
118 | if meson.version().version_compare('>=0.46') | |
3c34a198 | 119 | add_project_link_arguments(cc.get_supported_link_arguments(possible_link_flags), language: 'c') |
1fbf5591 | 120 | else |
3c34a198 | 121 | add_project_link_arguments(possible_link_flags, language: 'c') |
1fbf5591 CB |
122 | endif |
123 | ||
3c34a198 SG |
124 | add_project_arguments(cc.get_supported_arguments(possible_cc_flags), language: 'c') |
125 | ||
126 | # Feature detection. | |
127 | foreach 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 |
143 | endforeach |
144 | ||
3c34a198 | 145 | libfuse = dependency('fuse3', required: false) |
1fbf5591 | 146 | if libfuse.found() |
3c34a198 SG |
147 | conf.set10('HAVE_FUSE3', true) |
148 | conf.set('FUSE_USE_VERSION', 30) | |
1fbf5591 | 149 | else |
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 |
155 | endif |
156 | ||
157 | libdl = cc.find_library('dl') | |
158 | threads = dependency('threads') | |
159 | ||
160 | config_h = configure_file( | |
3c34a198 SG |
161 | output: 'config.h', |
162 | configuration: conf) | |
1fbf5591 | 163 | config_include = include_directories('.') |
3c34a198 | 164 | add_project_arguments('-include', 'config.h', language: 'c') |
1fbf5591 | 165 | |
3c34a198 | 166 | # Binary. |
1fbf5591 | 167 | lxcfs_sources = files('src/lxcfs.c') |
3c34a198 | 168 | public_programs = [] |
1fbf5591 | 169 | public_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 | 181 | liblxcfs_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 | 213 | liblxcfs_common_dependencies = declare_dependency( |
3c34a198 SG |
214 | sources: liblxcfs_sources, |
215 | dependencies: [ | |
216 | threads, | |
217 | libfuse, | |
218 | ]) | |
1314b3b8 | 219 | |
a962e7a1 | 220 | liblxcfs = 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. |
228 | test_programs = [] | |
1fbf5591 | 229 | if 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 |
237 | endif |
238 | ||
3c34a198 | 239 | # RPM spec. |
e5af758b | 240 | lxcfs_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 | 253 | subdir('config/init') |
3c34a198 SG |
254 | subdir('share') |
255 | subdir('tests') | |
d90ab57e | 256 | |
3c34a198 | 257 | # Build overview. |
1fbf5591 | 258 | status = [ |
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 | 277 | message('\n '.join(status)) |