Skip to content

Commit

Permalink
meson: build using meson
Browse files Browse the repository at this point in the history
test-script.sh and test-nbd.sh are not included.
  • Loading branch information
keszybz committed May 23, 2017
1 parent d541233 commit 5ed9c0b
Show file tree
Hide file tree
Showing 5 changed files with 243 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .dir-locals.el
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@
(eval . (c-set-offset 'arglist-intro '++))
(eval . (c-set-offset 'arglist-close 0))))
(nxml-mode . ((nxml-child-indent . 2)
(fill-column . 119))))
(fill-column . 119)))
(meson-mode . ((meson-indent-basic . 8))))
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
/Makefile
/TAGS
/aclocal.m4
/build-aux
/build*/
/casync
/casync-*/
/casync-http
Expand Down
172 changes: 172 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
project('casync', 'c',
version : '0.1',
license : 'LGPLv2+',
default_options: [
'c_std=gnu99',
'prefix=/usr',
'sysconfdir=/etc',
'localstatedir=/var',
],
meson_version : '>= 0.37.1')

cc = meson.get_compiler('c')

c_args = '''
-Wextra
-Wundef
-Wformat=2 -Wformat-security -Wformat-nonliteral
-Wlogical-op
-Wmissing-include-dirs
-Wold-style-definition
-Wpointer-arith
-Winit-self
-Wdeclaration-after-statement
-Wfloat-equal
-Wsuggest-attribute=noreturn
-Werror=missing-prototypes
-Werror=implicit-function-declaration
-Werror=missing-declarations
-Werror=return-type
-Werror=shadow
-Wstrict-prototypes
-Wredundant-decls
-Wmissing-noreturn
-Wshadow
-Wendif-labels
-Wstrict-aliasing=2
-Wwrite-strings
-Wno-unused-parameter
-Wno-missing-field-initializers
-Wno-unused-result
-Wno-format-signedness
-Werror=overflow
-Wdate-time
-Wnested-externs
-ffast-math
-fno-common
-fdiagnostics-show-option
-fno-strict-aliasing
-fvisibility=hidden
-fstack-protector
-fstack-protector-strong
-fPIE
--param=ssp-buffer-size=4
'''.split()

add_project_arguments(c_args, language : 'c')

conf = configuration_data()
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', '''#include <stdio.h>'''],
['copy_file_range', '''#include <sys/syscall.h>
#include <unistd.h>'''],
]
have = cc.has_function(ident[0], prefix : ident[1])
conf.set10('HAVE_DECL_' + ident[0].to_upper(), have)
endforeach

if cc.has_function('getrandom', prefix : '''#include <sys/random.h>''')
conf.set('USE_SYS_RANDOM_H', true)
conf.set10('HAVE_DECL_GETRANDOM', true)
else
have = cc.has_function('getrandom', prefix : '''#include <linux/random.h>''')
conf.set10('HAVE_DECL_GETRANDOM', have)
endif

conf.set('HAVE_STRUCT_FILE_CLONE_RANGE',
cc.has_header_symbol('linux/fs.h', 'struct file_clone_range'))

############################################################

prefixdir = get_option('prefix')
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)

config_h = configure_file(
output : 'config.h',
configuration : conf)
add_project_arguments('-include', 'config.h', language : 'c')

liblzma = dependency('liblzma',
version : '>= 5.1.0')
libcurl = dependency('libcurl',
version : '>= 7.32.0')
libgcrypt = cc.find_library('gcrypt')
libacl = cc.find_library('acl')

subdir('src')

includes = include_directories('src')

############################################################

executable(
'casync',
casync_sources,
link_with : libshared,
dependencies : [
liblzma,
libgcrypt,
libacl],
install : true)

executable(
'casync-http',
casync_http_sources,
link_with : libshared,
dependencies : [
liblzma,
libgcrypt,
libcurl],
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')))

############################################################

test_sources = '''
test-cachunk
test-cachunker
test-caencoder
test-camakebst
test-caorigin
test-casync
test-cautil
test-util
'''.split()

non_test_sources = '''
test-caformat
test-caindex
'''.split()

foreach test_name : test_sources + non_test_sources
exe = executable(
test_name,
'test/@[email protected]'.format(test_name),
link_with : libshared,
include_directories : includes,
dependencies : [
liblzma,
libgcrypt,
libacl])

if test_sources.contains(test_name)
test(test_name, exe)
endif
endforeach
64 changes: 64 additions & 0 deletions src/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
libshared_sources = files('''
cachunk.c
cachunk.h
cachunker.c
cachunker.h
cachunkid.c
cachunkid.h
cadecoder.c
cadecoder.h
caencoder.c
caencoder.h
cafileroot.c
cafileroot.h
caformat-util.c
caformat-util.h
caformat.h
caindex.c
caindex.h
calocation.c
calocation.h
camakebst.c
camakebst.h
canbd.c
canbd.h
caorigin.c
caorigin.h
caprotocol-util.c
caprotocol-util.h
caprotocol.h
caremote.c
caremote.h
caseed.c
caseed.h
castore.c
castore.h
casync.c
casync.h
cautil.c
cautil.h
def.h
fssize.c
fssize.h
gcrypt-util.c
gcrypt-util.h
parse-util.c
parse-util.h
realloc-buffer.c
realloc-buffer.h
reflink.c
reflink.h
rm-rf.c
rm-rf.h
siphash24.c
siphash24.h
util.c
util.h
'''.split())

libshared = static_library(
'shared',
libshared_sources)

casync_sources = files('casync-tool.c')
casync_http_sources = files('casync-http.c')
4 changes: 4 additions & 0 deletions src/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
#include <sys/wait.h>
#include <time.h>

#ifdef USE_SYS_RANDOM_H
# include <sys/random.h>
#endif

/* When we include libgen.h because we need dirname() we immediately
* undefine basename() since libgen.h defines it as a macro to the
* POSIX version which is really broken. We prefer GNU basename(). */
Expand Down

0 comments on commit 5ed9c0b

Please sign in to comment.