]> git.proxmox.com Git - mirror_lxcfs.git/blame - meson.build
build: remove -shared
[mirror_lxcfs.git] / meson.build
CommitLineData
1fbf5591
CB
1# SPDX-License-Identifier: LGPL-2.1-or-later
2
3project('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 ],
13 meson_version : '>= 0.45',
14 )
15
16conf = configuration_data()
17conf.set_quoted('PROJECT_URL', 'https://linuxcontainers.org/lxcfs/introduction/')
18conf.set('PROJECT_VERSION', meson.project_version(),
19 description : 'Numerical project version (used where a simple number is expected)')
20project_source_root = meson.current_source_dir()
21project_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.
26prefixdir = get_option('prefix')
27if not prefixdir.startswith('/')
28 error('Prefix is not absolute: "@0@"'.format(prefixdir))
29endif
30bindir = join_paths(prefixdir, get_option('bindir'))
31libdir = join_paths(prefixdir, get_option('libdir'))
32lxcfsdir = join_paths(libdir, 'lxcfs')
33sysconfdir = join_paths(prefixdir, get_option('sysconfdir'))
34runtimepath = join_paths(prefixdir, get_option('runtime-path'))
35localstatedir = join_paths('/', get_option('localstatedir'))
0d2038cd 36datadir = join_paths(prefixdir, get_option('datadir'))
1fbf5591 37
1fbf5591
CB
38conf.set_quoted('BINDIR', bindir)
39conf.set_quoted('LIBDIR', libdir)
40conf.set_quoted('LOCALSTATEDIR', localstatedir)
1fbf5591
CB
41conf.set_quoted('RUNTIME_PATH', runtimepath)
42conf.set_quoted('SYSCONFDIR', sysconfdir)
43
0d2038cd
CB
44conf.set_quoted('LXCFS_BUILD_ROOT', project_build_root)
45conf.set_quoted('LXCFS_SOURCE_ROOT', project_source_root)
46
47lxcfssharedir = join_paths(datadir, 'lxcfs')
48conf.set_quoted('LXCFSSHAREDIR', lxcfssharedir)
49
50lxcconfdir = join_paths(datadir, 'lxc/config/common.conf.d')
51conf.set_quoted('LXCCONFDIR', lxcconfdir)
52
1fbf5591
CB
53init_script = get_option('init-script')
54
55cc = meson.get_compiler('c')
56meson_build_sh = find_program('tools/meson-build.sh')
57
58want_tests = get_option('tests')
59
60possible_cc_flags = [
1fbf5591 61 '-Wvla',
1fbf5591
CB
62 '-Wimplicit-fallthrough=5',
63 '-Wcast-align',
64 '-Wstrict-prototypes',
65 '-fno-strict-aliasing',
66 '-fstack-clash-protection',
67 '-fstack-protector-strong',
68 '--param=ssp-buffer-size=4',
69 '--mcet -fcf-protection',
70 '-Werror=implicit-function-declaration',
71 '-Wlogical-op',
72 '-Wmissing-include-dirs',
73 '-Wold-style-definition',
74 '-Winit-self',
75 '-Wunused-but-set-variable',
76 '-Wno-unused-parameter',
77 '-Wfloat-equal',
78 '-Wsuggest-attribute=noreturn',
79 '-Werror=return-type',
80 '-Werror=incompatible-pointer-types',
81 '-Wformat=2',
82 '-Wshadow',
83 '-Wendif-labels',
84 '-Werror=overflow',
85 '-fdiagnostics-show-option',
86 '-Werror=shift-count-overflow',
87 '-Werror=shift-overflow=2',
88 '-Wdate-time',
89 '-Wnested-externs',
90 '-fasynchronous-unwind-tables',
91 '-fexceptions',
92 '-Warray-bounds',
93 '-Wrestrict',
94 '-Wreturn-local-addr',
95 '-fsanitize=cfi',
96 '-Wstringop-overflow',
97]
98
99possible_link_flags = [
1fbf5591
CB
100 '-Wl,--gc-sections',
101 '-Wl,-z,relro',
102 '-Wl,-z,now',
1fbf5591
CB
103 '-Wl,-fuse-ld=gold',
104]
105
106if meson.version().version_compare('>=0.46')
107 add_project_link_arguments(cc.get_supported_link_arguments(possible_link_flags), language : 'c')
108else
109 add_project_link_arguments(possible_link_flags, language : 'c')
110endif
111
112add_project_arguments(cc.get_supported_arguments(possible_cc_flags), language : 'c')
113
114foreach ident : [
115 ['strlcpy', '''#include <string.h>'''],
116 ['strlcat', '''#include <string.h>'''],
117 ['pidfd_send_signal', '''#include <stdlib.h>
118 #include <unistd.h>
119 #include <signal.h>
120 #include <sys/wait.h>'''],
121 ['pidfd_open', '''#include <stdlib.h>
122 #include <unistd.h>
123 #include <signal.h>
124 #include <sys/wait.h>'''],
125]
126
127 have = cc.has_function(ident[0], prefix : ident[1], args : '-D_GNU_SOURCE')
128 conf.set10('HAVE_' + ident[0].to_upper(), have)
129endforeach
130
131conf.set('_FILE_OFFSET_BITS', 64)
132
5f275367 133libfuse = dependency('fuse3', required : false)
1fbf5591 134if libfuse.found()
5f275367 135 conf.set10('HAVE_FUSE3', true)
1fbf5591
CB
136 conf.set('FUSE_USE_VERSION', 30)
137else
5f275367
CB
138 if dependency('fuse').found()
139 conf.set10('HAVE_FUSE', true)
140 conf.set('FUSE_USE_VERSION', 26)
141 endif
1fbf5591
CB
142endif
143
144libdl = cc.find_library('dl')
145threads = dependency('threads')
146
147config_h = configure_file(
148 output : 'config.h',
149 configuration : conf)
150config_include = include_directories('.')
151
152add_project_arguments('-include', 'config.h', language : 'c')
153
154subdir('tests')
155
156public_programs = []
157
158lxcfs_sources = files('src/lxcfs.c')
159
160public_programs += executable(
161 'lxcfs',
162 lxcfs_sources,
163 dependencies : [threads,
164 libdl,
165 libfuse],
166 install : true,
167 install_dir : bindir)
168
169liblxcfs_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
200liblxcfs = shared_library(
201 'lxcfs',
202 liblxcfs_sources,
1fbf5591
CB
203 dependencies : [threads,
204 libdl,
205 libfuse],
206 install : true,
207 install_dir : lxcfsdir)
208
209if want_tests == true
210 liblxcfs_test = shared_library(
211 'lxcfstest',
212 liblxcfs_sources,
1fbf5591
CB
213 dependencies : [threads,
214 libdl,
215 libfuse],
216 install : false,
217 install_dir : lxcfsdir,
218 c_args : '-DRELOADTEST -DDEBUG')
219endif
220
221if 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')
229elif init_script == 'upstart'
230 install_data('config/init/upstart/lxcfs.conf', install_dir : join_paths(sysconfdir, 'init'))
231elif init_script == 'openrc'
232 install_data('config/init/sysvinit/lxcfs', install_dir : join_paths(sysconfdir, 'rc.d/init.d/lxcfs'))
233elif init_script == 'sysvinit'
234 install_data('config/init/sysvinit/lxcfs', install_dir : join_paths(sysconfdir, 'rc.d/init.d/lxcfs'))
235endif
236
237status = [
238 '@0@ @1@'.format(meson.project_name(), meson.project_version()),
239
5f275367 240 'FUSE version: @0@'.format(libfuse.version()),
0d2038cd
CB
241 'bin directory: @0@'.format(bindir),
242 'lib directory: @0@'.format(libdir),
243 'data directory: @0@'.format(datadir),
244 'local state directory: @0@'.format(localstatedir),
1fbf5591 245 'prefix directory: @0@'.format(prefixdir),
0d2038cd 246 'runtime directory: @0@'.format(runtimepath),
1fbf5591 247 'sysconf directory: @0@'.format(sysconfdir),
0d2038cd 248 'lxc conf directory: @0@'.format(lxcconfdir),
1fbf5591 249 'lxcfs directory: @0@'.format(lxcfsdir),
0d2038cd 250 'lxcfs shared directory: @0@'.format(lxcfssharedir),
1fbf5591
CB
251 'lxcfs build root directory: @0@'.format(project_build_root),
252 'lxcfs source root directory: @0@'.format(project_source_root),
253 'init system: @0@'.format(init_script),
254 'tests: @0@'.format(want_tests)]
255
256message('\n '.join(status))