summaryrefslogtreecommitdiff
path: root/meson.build
blob: 01fcc197c58d651711c3d674a6c2451043c8f2b2 (plain)
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
project(
  'bubblewrap',
  'c',
  version : '0.5.0',
  meson_version : '>=0.49.0',
  default_options : [
    'warning_level=2',
  ],
)

cc = meson.get_compiler('c')
add_project_arguments('-D_GNU_SOURCE', language : 'c')
common_include_directories = include_directories('.')

# Keep this in sync with ostree, except remove -Wall (part of Meson
# warning_level 2) and -Werror=declaration-after-statement
add_project_arguments(
  cc.get_supported_arguments([
    '-Werror=shadow',
    '-Werror=empty-body',
    '-Werror=strict-prototypes',
    '-Werror=missing-prototypes',
    '-Werror=implicit-function-declaration',
    '-Werror=pointer-arith',
    '-Werror=init-self',
    '-Werror=missing-declarations',
    '-Werror=return-type',
    '-Werror=overflow',
    '-Werror=int-conversion',
    '-Werror=parenthesis',
    '-Werror=incompatible-pointer-types',
    '-Werror=misleading-indentation',
    '-Werror=missing-include-dirs',
    '-Werror=aggregate-return',

    # Extra warnings specific to bubblewrap
    '-Werror=switch-default',
    '-Wswitch-enum',

    # Meson warning_level=2 would do this, but we are not fully
    # signedness-safe yet
    '-Wno-sign-compare',
    '-Wno-error=sign-compare',

    # Deliberately not warning about these, ability to zero-initialize
    # a struct is a feature
    '-Wno-missing-field-initializers',
    '-Wno-error=missing-field-initializers',
  ]),
  language : 'c',
)

if (
  cc.has_argument('-Werror=format=2')
  and cc.has_argument('-Werror=format-security')
  and cc.has_argument('-Werror=format-nonliteral')
)
  add_project_arguments([
    '-Werror=format=2',
    '-Werror=format-security',
    '-Werror=format-nonliteral',
  ], language : 'c')
endif

bash = find_program('bash', required : false)

libcap_dep = dependency('libcap', required : true)

selinux_dep = dependency(
  'libselinux',
  version : '>=2.1.9',
  # if disabled, Meson will behave as though libselinux was not found
  required : get_option('selinux'),
)

cdata = configuration_data()
cdata.set_quoted(
  'PACKAGE_STRING',
  '@0@ @1@'.format(meson.project_name(), meson.project_version()),
)

if selinux_dep.found()
  cdata.set('HAVE_SELINUX', 1)
  if selinux_dep.version().version_compare('>=2.3')
    cdata.set('HAVE_SELINUX_2_3', 1)
  endif
endif

if get_option('require_userns')
  cdata.set('ENABLE_REQUIRE_USERNS', 1)
endif

configure_file(
  output : 'config.h',
  configuration : cdata,
)

if meson.is_subproject()
  bwrapdir = get_option('libexecdir')

  if get_option('program_prefix') == ''
    error('program_prefix option must be set when bwrap is a subproject')
  endif
else
  bwrapdir = get_option('bindir')
endif

bwrap = executable(
  get_option('program_prefix') + 'bwrap',
  [
    'bubblewrap.c',
    'bind-mount.c',
    'network.c',
    'utils.c',
  ],
  install : true,
  install_dir : bwrapdir,
  dependencies : [selinux_dep, libcap_dep],
)

xsltproc = find_program('xsltproc', required : get_option('man'))

if xsltproc.found() and not meson.is_subproject()
  custom_target(
    'bwrap.1',
    output : 'bwrap.1',
    input : 'bwrap.xml',
    command : [
      xsltproc,
      '--nonet',
      '--stringparam', 'man.output.quietly', '1',
      '--stringparam', 'funcsynopsis.style', 'ansi',
      '--stringparam', 'man.th.extra1.suppress', '1',
      '--stringparam', 'man.authors.section.enabled', '0',
      '--stringparam', 'man.copyright.section.enabled', '0',
      '-o', '@OUTPUT@',
      'http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl',
      '@INPUT@',
    ],
    install : true,
    install_dir : get_option('mandir') / 'man1',
  )
endif

if not meson.is_subproject()
  subdir('completions')
endif