forked from systemd/casync
-
Notifications
You must be signed in to change notification settings - Fork 0
/
meson.build
424 lines (361 loc) · 12.2 KB
/
meson.build
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
# SPDX-License-Identifier: LGPL-2.1+
project('casync', 'c',
version : '2',
license : 'LGPLv2+',
default_options: [
'c_std=gnu99',
'prefix=/usr',
'sysconfdir=/etc',
'localstatedir=/var',
'auto_features=enabled',
],
meson_version : '>= 0.47')
cc = meson.get_compiler('c')
c_args = '''
-Wextra
-Werror=undef
-Werror=format=2
-Wformat-security
-Wformat-nonliteral
-Wlogical-op
-Wmissing-include-dirs
-Werror=old-style-definition
-Werror=pointer-arith
-Winit-self
-Wfloat-equal
-Wsuggest-attribute=noreturn
-Werror=missing-prototypes
-Werror=implicit-function-declaration
-Werror=missing-declarations
-Werror=return-type
-Werror=incompatible-pointer-types
-Werror=shadow
-Werror=int-conversion
-Wstrict-prototypes
-Wredundant-decls
-Wmissing-noreturn
-Wendif-labels
-Wstrict-aliasing=2
-Wwrite-strings
-Wno-unused-parameter
-Wno-missing-field-initializers
-Wno-unused-result
-Werror=overflow
-Werror=sign-compare
-Wdate-time
-Wnested-externs
-fno-common
-fdiagnostics-show-option
-fno-strict-aliasing
-fvisibility=hidden
-fstack-protector
-fstack-protector-strong
-fPIE
--param=ssp-buffer-size=4
'''.split()
foreach arg : c_args
if cc.has_argument(arg)
add_project_arguments(arg, language : 'c')
endif
endforeach
want_ossfuzz = get_option('oss-fuzz')
want_libfuzzer = get_option('llvm-fuzz')
if want_ossfuzz and want_libfuzzer
error('only one of oss-fuzz and llvm-fuzz can be specified')
endif
fuzzer_build = want_ossfuzz or want_libfuzzer
add_languages('cpp', required : fuzzer_build)
conf = configuration_data()
conf.set_quoted('PACKAGE_VERSION', meson.project_version())
conf.set('_GNU_SOURCE', true)
conf.set('__SANE_USERSPACE_TYPES__', true)
conf.set('SIZEOF_PID_T', cc.sizeof('pid_t', prefix : '#include <sys/types.h>'))
conf.set('SIZEOF_UID_T', cc.sizeof('uid_t', prefix : '#include <sys/types.h>'))
conf.set('SIZEOF_GID_T', cc.sizeof('gid_t', prefix : '#include <sys/types.h>'))
foreach ident : [
['renameat2', '''#define _GNU_SOURCE
#include <stdio.h>'''],
['copy_file_range', '''#define _GNU_SOURCE
#include <sys/syscall.h>
#include <unistd.h>'''],
]
have = cc.has_function(ident[0], args : '-D_GNU_SOURCE', prefix : ident[1])
conf.set10('HAVE_' + ident[0].to_upper(), have)
endforeach
if cc.has_function('getrandom', prefix : '''#include <sys/random.h>''')
conf.set10('USE_SYS_RANDOM_H', true)
conf.set10('HAVE_GETRANDOM', true)
else
conf.set10('USE_SYS_RANDOM_H', false)
have = cc.has_function('getrandom', prefix : '''#include <linux/random.h>''')
conf.set10('HAVE_GETRANDOM', have)
endif
############################################################
prefixdir = get_option('prefix')
bindir = join_paths(prefixdir, get_option('bindir'))
datadir = join_paths(prefixdir, get_option('datadir'))
docdir = join_paths(datadir, 'doc/casync')
protocoldir = join_paths(prefixdir, 'lib/casync/protocols')
conf.set_quoted('CASYNC_PROTOCOL_PATH', protocoldir)
liblzma = dependency(
'liblzma',
version : '>= 5.1.0',
required : get_option('liblzma'))
conf.set10('HAVE_LIBLZMA', liblzma.found())
libz = dependency(
'zlib',
required : get_option('libz'))
conf.set10('HAVE_LIBZ', libz.found())
libzstd = dependency(
'libzstd',
version : '>= 0.8.1',
required : get_option('libzstd'))
conf.set10('HAVE_LIBZSTD', libzstd.found())
libcurl = dependency('libcurl',
version : '>= 7.29.0')
openssl = dependency('openssl',
version : '>= 1.0')
libacl = cc.find_library('acl')
if get_option('fuse')
libfuse = dependency('fuse',
version : '>= 2.6')
else
libfuse = []
endif
conf.set10('HAVE_FUSE', get_option('fuse'))
if get_option('selinux')
libselinux = dependency('libselinux')
else
libselinux = []
endif
conf.set10('HAVE_SELINUX', get_option('selinux'))
if get_option('udev')
libudev = dependency('libudev')
else
libudev = []
endif
conf.set10('HAVE_UDEV', get_option('udev'))
threads = dependency('threads')
math = cc.find_library('m')
if want_libfuzzer
fuzzing_engine = meson.get_compiler('cpp').find_library('Fuzzer')
elif want_ossfuzz
fuzzing_engine = meson.get_compiler('cpp').find_library('FuzzingEngine')
endif
config_h = configure_file(
output : 'config.h',
configuration : conf)
add_project_arguments('-include', 'config.h', language : 'c')
subdir('src')
subdir('test')
includes = include_directories('src')
udevrulesdir = get_option('udevrulesdir')
if udevrulesdir == ''
udev = dependency('udev', required : false)
udevrulesdir = join_paths(udev.get_pkgconfig_variable('udevdir'), 'rules.d')
endif
subdir('shell-completion/bash')
subdir('doc')
############################################################
casync = executable(
'casync',
casync_sources,
link_with : libshared,
dependencies : [
libacl,
libfuse,
liblzma,
libselinux,
libudev,
libz,
libzstd,
math,
openssl],
install : true)
casync_http = executable(
'casync-http',
casync_http_sources,
link_with : libshared,
dependencies : [
libcurl,
liblzma,
libz,
libzstd,
math,
openssl],
install : true,
install_dir : protocoldir)
meson.add_install_script('sh', '-c',
'ln -svf casync-http $DESTDIR@0@'.format(
join_paths(protocoldir, 'casync-https')))
meson.add_install_script('sh', '-c',
'ln -svf casync-http $DESTDIR@0@'.format(
join_paths(protocoldir, 'casync-ftp')))
meson.add_install_script('sh', '-c',
'ln -svf casync-http $DESTDIR@0@'.format(
join_paths(protocoldir, 'casync-sftp')))
meson.add_postconf_script('sh', '-c',
'ln -svf casync-http $MESON_BUILD_ROOT/casync-https')
meson.add_postconf_script('sh', '-c',
'ln -svf casync-http $MESON_BUILD_ROOT/casync-ftp')
meson.add_postconf_script('sh', '-c',
'ln -svf casync-http $MESON_BUILD_ROOT/casync-sftp')
############################################################
executable('notify-wait',
notify_wait_sources,
include_directories : includes,
install : false)
############################################################
test_files_sh = find_program('test-files/test-files.sh')
run_target(
'test-files',
command : [test_files_sh, 'create'])
run_target(
'clean-test-files',
command : [test_files_sh, 'clean'])
substs = configuration_data()
substs.set_quoted('top_builddir', meson.build_root())
substs.set_quoted('top_srcdir', meson.source_root())
substs.set('bindir_unquoted', bindir)
substs.set10('HAVE_LIBLZMA', liblzma.found())
substs.set10('HAVE_LIBZ', libz.found())
substs.set10('HAVE_LIBZSTD', libzstd.found())
test_script_sh = configure_file(
output : 'test-script.sh',
input : 'test/test-script.sh.in',
configuration : substs)
test_script = find_program(test_script_sh)
test('test-script.sh', test_script,
timeout : 30 * 60)
test_script_sha256_sh = configure_file(
output : 'test-script-sha256.sh',
input : 'test/test-script-sha256.sh.in',
configuration : substs)
test_script_sha256 = find_program(test_script_sha256_sh)
test('test-script-sha256.sh', test_script_sha256,
timeout : 30 * 60)
test_script_gzip_sh = configure_file(
output : 'test-script-gzip.sh',
input : 'test/test-script-gzip.sh.in',
configuration : substs)
test_script_gzip = find_program(test_script_gzip_sh)
test('test-script-gzip.sh', test_script_gzip,
timeout : 30 * 60)
test_script_xz_sh = configure_file(
output : 'test-script-xz.sh',
input : 'test/test-script-xz.sh.in',
configuration : substs)
test_script_xz = find_program(test_script_xz_sh)
test('test-script-xz.sh', test_script_xz,
timeout : 30 * 60)
test_nbd_sh = configure_file(
output : 'test-nbd.sh',
input : 'test/test-nbd.sh.in',
configuration : substs)
test_nbd = find_program(test_nbd_sh)
test('test-nbd.sh', test_nbd,
timeout : 30 * 60)
test_fuse_sh = configure_file(
output : 'test-fuse.sh',
input : 'test/test-fuse.sh.in',
configuration : substs)
test_fuse = find_program(test_fuse_sh)
test('test-fuse.sh', test_fuse,
timeout : 30 * 60)
test_cache_sh = configure_file(
output : 'test-cache.sh',
input : 'test/test-cache.sh.in',
configuration : substs)
test_cache = find_program(test_cache_sh)
test('test-cache.sh', test_cache,
timeout : 30 * 60)
udev_rule = configure_file(
output : '75-casync.rules',
input : 'src/75-casync.rules.in',
configuration : substs)
install_data(udev_rule, install_dir : udevrulesdir)
############################################################
test_sources = '''
test-cachunk
test-cachunker
test-cachunker-histogram
test-cadigest
test-caencoder
test-calocation
test-camakebst
test-camatch
test-caorigin
test-casync
test-cautil
test-feature-flags
test-util
'''.split()
non_test_sources = '''
test-caformat
test-caindex
test-calc-digest
'''.split()
test_dependencies = [
libacl,
liblzma,
libselinux,
libz,
libzstd,
math,
openssl,
threads]
foreach test_name : test_sources + non_test_sources
exe = executable(
test_name,
'test/@[email protected]'.format(test_name),
include_directories : includes,
link_with : libshared,
dependencies : test_dependencies)
if test_sources.contains(test_name)
test(test_name, exe,
timeout : 3 * 60)
endif
endforeach
fuzzer_exes = []
foreach tuple : fuzzers
sources = tuple[0]
deps = test_dependencies
if fuzzer_build
deps += fuzzing_engine
else
sources += fuzz_main_c
endif
name = sources[0].split('/')[-1].split('.')[0]
fuzzer_exes += executable(
name,
sources,
include_directories : [includes, include_directories('test/fuzz')],
link_with : libshared,
dependencies : deps,
install : false)
endforeach
run_target('fuzzers',
depends : fuzzer_exes,
command : ['true'])
############################################################
meson_check_help = find_program('test/meson-check-help.sh')
foreach exec : [casync, casync_http]
name = exec.full_path().split('/')[-1]
test('check-help-' + name,
meson_check_help,
args : [exec.full_path()])
endforeach
############################################################
git = find_program('git', required : false)
if git.found()
all_files = run_command(
git,
['--git-dir=@0@/.git'.format(meson.source_root()),
'ls-files',
':/*.[ch]'])
all_files = files(all_files.stdout().split())
run_target('tags',
command : ['env', 'etags', '-o', '@0@/@1@'.format(meson.source_root(), 'TAGS')] + all_files)
run_target('ctags',
command : ['env', 'ctags', '-o', '@0@/@1@'.format(meson.source_root(), 'tags')] + all_files)
endif