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