-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmeson.build
230 lines (204 loc) · 5.71 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
# SPDX-License-Identifier: LGPL-3.0-or-later
#meson setup --prefix=/usr -Dpkg=true build
#meson install --destdir=destdir -C build
project('nmutils', version: 'devel', license: 'GPL-3.0-or-later',
default_options: [ 'sysconfdir=/etc' ],
meson_version: '>=0.62.0') # test() verbose
# get options
nm_prefix = get_option('prefix')
nm_name = meson.project_name()
nm_sysconfdir = nm_prefix / get_option('sysconfdir')
nm_unitdir = get_option('unitdir')
nm_rundir = get_option('runstatedir')
nm_selinuxtype = get_option('selinuxtype')
nm_datadir = nm_prefix / get_option('datadir')
nm_nmlibdir = get_option('nmlibdir')
nm_ispkg = get_option('pkg')
# get auto SELinux from config
seconfig = '/etc/selinux/config'
semake = '/usr/share/selinux/devel/Makefile'
sed_cmd = find_program('sed')
fs = import('fs')
if nm_nmlibdir == ''
if fs.is_dir(nm_prefix / 'lib/NetworkManager/dispatcher.d')
nm_nmlibdir = nm_prefix / 'lib'
else
nm_nmlibdir = '/usr/lib'
endif
endif
if nm_ispkg
nm_pkgconfdir = nm_sysconfdir / nm_name
else
nm_pkgconfdir = nm_sysconfdir / nm_name / 'conf'
endif
# systemd units may be disabled with -Dunitdir=no
install_units = (nm_unitdir != '')
if install_units and nm_unitdir == 'auto'
if nm_ispkg
systemd_dep = dependency('systemd', method: 'pkg-config', required: false)
if systemd_dep.found()
nm_unitdir = systemd_dep.get_variable(pkgconfig: 'systemdsystemunitdir')
elif fs.is_dir('/usr/lib/systemd/system')
nm_unitdir = '/usr/lib/systemd/system'
endif
elif fs.is_dir('/etc/systemd/system')
nm_unitdir = '/etc/systemd/system'
endif
install_units = (nm_unitdir != 'auto')
endif
install_selinux = (nm_selinuxtype != '')
if install_selinux and nm_selinuxtype == 'auto'
nm_selinuxtype = ''
if fs.is_file(seconfig) and fs.is_file(semake)
seconfig_type = run_command(sed_cmd, '-E', '-n',
'/^SELINUXTYPE=(.*)$/{s//\\1/p;q;}', seconfig,
check: true)
nm_selinuxtype = seconfig_type.stdout().strip()
endif
install_selinux = (nm_selinuxtype != '')
endif
if install_selinux
if nm_ispkg
sepkgdir = nm_datadir / 'selinux/packages' / nm_selinuxtype
else
sepkgdir = '/etc/selinux' / nm_selinuxtype / 'packages'
endif
assert(fs.is_file(semake),
'selinuxtype set, but selinux-policy-devel package not installed')
endif
# packages have different locations for scripts
if nm_ispkg
nm_pkglibdir = nm_nmlibdir / 'NetworkManager/dispatcher.d'
nm_pkgdatadir = nm_datadir / nm_name
else
nm_pkglibdir = nm_sysconfdir / 'NetworkManager/dispatcher.d'
nm_pkgdatadir = nm_sysconfdir / nm_name
endif
install_sets = [
[
'etc/nmutils',
nm_pkgdatadir,
'rw-r--r--',
[
'general-functions',
'ddns-functions',
'ipv6_utils.sh',
'dispatcher_action',
]
],
[
'etc/NetworkManager/dispatcher.d',
nm_pkglibdir,
'rwxr-xr-x',
[
'08-ipv6-prefix',
'09-ddns',
'90-transmission',
'95-radvd-gen',
'96-interface-action',
]
],
]
if install_units
install_sets += [
[
'etc/systemd/system',
nm_unitdir,
'rw-r--r--',
[
'ddns-onboot@.service',
'ddns-onboot@.timer',
],
],
]
endif
patch_cmd = [
sed_cmd, '-e', 's|/etc/nmutils|' + nm_pkgdatadir + '|g',
'-e', 's|' + nm_pkgdatadir + '/conf|' + nm_pkgconfdir + '|g',
'-e', 's|/etc/NetworkManager|' + nm_sysconfdir + '/NetworkManager|g',
'-e', 's|' + nm_sysconfdir + '/NetworkManager/dispatcher.d|' +
nm_pkglibdir + '|g',
'-e', 's|' + nm_pkglibdir + '/##-ifd|' + nm_sysconfdir +
'/NetworkManager/dispatcher.d/##-ifd' + '|g',
'-e', 's|/run/|' + nm_rundir + '/|g',
'@INPUT@',
]
sepatch_cmd = [
sed_cmd,
'-e', 's|^/usr/lib/|' + nm_nmlibdir + '/|g',
'-e', 's|^/etc/|' + nm_sysconfdir + '/|g',
'@INPUT@',
]
selinux_files = [
'nmutils.fc',
'nmutils.te',
]
#
# INSTALL
#
foreach p: install_sets
foreach tgt: p[3]
custom_target(command: patch_cmd, capture: true, input: p[0] / tgt,
output: tgt, install: true, install_dir: p[1],
install_mode: p[2], install_tag: 'base')
endforeach
endforeach
install_emptydir(nm_pkgconfdir, install_tag: 'base')
predown_symlinks = [
'08-ipv6-prefix',
'96-interface-action',
]
foreach p: predown_symlinks
install_symlink(p, install_dir: nm_pkglibdir / 'pre-down.d',
install_tag: 'base', pointing_to: '..' / p)
endforeach
if install_selinux
sedeps = []
foreach p: selinux_files
sedeps += custom_target(command: sepatch_cmd, capture: true,
input: 'selinux' / p, output: p)
endforeach
custom_target(command: [ find_program('make'), '-f',
meson.current_source_dir() / 'selinux/GNUmakefile',
'VPATH=.', 'nmutils.pp.bz2' ],
depends: sedeps, output: 'nmutils.pp.bz2', install: true,
install_dir: sepkgdir, install_tag: 'selinux')
meson.add_install_script(find_program('semodule'), '-s', nm_selinuxtype,
'-i', sepkgdir / 'nmutils.pp.bz2',
install_tag: 'selinux', skip_if_destdir: true)
endif
#
# TESTS
#
testdir = meson.current_source_dir() / 'test'
builddir = meson.current_build_dir()
test_files = [
'general-test',
'ddns-test',
'nm-ddns-test',
'ipv6-prefix-addr-test',
'ipv6-prefix-nm-test',
'ipv6-prefix-dhclient-test',
'ipv6-prefix-dhcpcd-test',
]
test_env = [
'TEST_NMUTILS=' + builddir,
'TEST_NMDIR=' + builddir,
'TEST_OUT=' + builddir / 'results',
'TEST_RUNDIR=' + builddir / 'run/nmutils',
]
foreach p: test_files
test(p, find_program(p, dirs: testdir), args: [ 'strict', 'verbose' ],
env: test_env, is_parallel: false, verbose: true, workdir: testdir)
endforeach
radvd_tests = [
'radvd-test-1',
'radvd-test-2',
'radvd-test-3',
'radvd-test-4',
]
make_cmd = find_program('make')
foreach p: radvd_tests
test(p, make_cmd, args: [ p ], env: test_env, is_parallel: false,
workdir: testdir)
endforeach