Skip to content

Commit

Permalink
build: switch to meson
Browse files Browse the repository at this point in the history
  • Loading branch information
Snaipe committed Sep 6, 2020
1 parent a6d5826 commit 6ab6809
Show file tree
Hide file tree
Showing 8 changed files with 140 additions and 105 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@ jobs:
command -v apk && apk add --no-cache linux-headers scdoc
command -v apt && apt-get update && apt-get install -y scdoc
command -v dnf && dnf install -y glibc-static scdoc
CPPFLAGS='-Wconversion -pedantic-errors' make
CPPFLAGS='-Wconversion -pedantic-errors' meson build
ninja -C build
104 changes: 0 additions & 104 deletions Makefile

This file was deleted.

14 changes: 14 additions & 0 deletions config.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/* Copyright © 2020 Arista Networks, Inc. All rights reserved.
*
* Use of this source code is governed by the MIT license that can be found
* in the LICENSE file.
*/

#ifndef CONFIG_H_
# define CONFIG_H_

# define PACKAGE "@package@"
# define BINDIR "@bindir@"
# define LIBEXECDIR "@libexecdir@"

#endif /* !CONFIG_H_ */
10 changes: 10 additions & 0 deletions generate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/sh

(echo "/* Copyright © 2020 Arista Networks, Inc. All rights reserved."; \
echo " *"; \
echo " * Use of this source code is governed by the MIT license that can be found" ;\
echo " * in the LICENSE file."; \
echo " */"; \
echo ""; \
echo "/* This file is generated from usage.txt. Do not edit. */"; \
xxd -i usage.txt) > usage.c
2 changes: 2 additions & 0 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

#include <asm/resource.h>

#include "config.h"

#include "bst_limits.h"
#include "capable.h"
#include "enter.h"
Expand Down
101 changes: 101 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
project('bst', 'c',
meson_version : '>= 0.51.0',
license : 'MIT',
version : '0.0.1',
default_options : ['c_std=c11', 'warning_level=3'])

prefix = get_option('prefix')
bindir = join_paths(prefix, get_option('bindir'))
libexecdir = join_paths(prefix, get_option('libexecdir'))

cc = meson.get_compiler('c')

add_project_arguments(
cc.get_supported_arguments([
'-Wno-unused-parameter',
'-Wno-unused-value',
'-fno-strict-aliasing',
]),
'-D_GNU_SOURCE',
language: ['c'])

config = configuration_data()
config.set('package', meson.project_name())
config.set('bindir', bindir)
config.set('libexecdir', libexecdir)

configure_file(input: 'config.h.in', output: 'config.h', configuration: config)

bst_init_sources = [
'init.c',
'sig.c',
]

init = executable('bst-init', bst_init_sources,
link_args: cc.get_supported_arguments([
'-static',
]),
install: true)

bst_unpersist_sources = [
'capable.c',
'ns.c',
'path.c',
'unpersist.c',
]

unpersist = executable('bst-unpersist', bst_unpersist_sources, install: true)

bst_sources = [
'bst_limits.c',
'capable.c',
'cp.c',
'enter.c',
'kvlist.c',
'main.c',
'mount.c',
'net.c',
'ns.c',
'outer.c',
'path.c',
'setarch.c',
'sig.c',
'timens.c',
'usage.c',
'userns.c',
]

executable('bst', bst_sources, install: true)

if not get_option('no-setcap-or-suid')
capabilities = {
'bst': [
'cap_dac_override',
'cap_net_admin',
'cap_setgid',
'cap_setuid',
'cap_sys_admin',
'cap_sys_chroot',
'cap_sys_ptrace',
],
'bst-unpersist': [
'cap_sys_admin',
],
}

setcap = find_program('setcap', '/usr/sbin/setcap', '/sbin/setcap', required: false)
if setcap.found()
foreach bin, caps : capabilities
meson.add_install_script('/bin/sh', '-c', '@0@ @1@ ${MESON_INSTALL_DESTDIR_PREFIX}/bin/@2@'.format(setcap.path(), ','.join(caps) + '=p', bin))
endforeach
else
chmod = find_program('chmod')
foreach bin, _ : capabilities
meson.add_install_script('/bin/sh', '-c', '@0@ u+s ${MESON_INSTALL_DESTDIR_PREFIX}/bin/@1@'.format(chmod.path(), bin))
endforeach
endif
endif

if get_option('tests')
subdir('test')
endif
2 changes: 2 additions & 0 deletions meson_options.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
option('tests', type: 'boolean', value: true)
option('no-setcap-or-suid', type: 'boolean', value: false)
9 changes: 9 additions & 0 deletions test/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
test_limits = executable('test_limits', ['test_limit_parsing.c', '../bst_limits.c'])

test('test_limits', test_limits)

cram_sh = find_program('cram.sh')

executable('print_limits', ['print_limits.c'])

test('cram tests', cram_sh, args: [meson.current_source_dir()])

0 comments on commit 6ab6809

Please sign in to comment.