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