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