]> git.ipfire.org Git - thirdparty/systemd.git/blame - meson.build
Merge pull request #31039 from AdrianVovk/slice-freeze-thaw
[thirdparty/systemd.git] / meson.build
CommitLineData
db9ecf05 1# SPDX-License-Identifier: LGPL-2.1-or-later
3a726fcd 2
5c23128d 3project('systemd', 'c',
e37f3a12 4 version : '255',
5c23128d
ZJS
5 license : 'LGPLv2+',
6 default_options: [
2b2dbcbb 7 'c_std=gnu11',
37efbbd8
ZJS
8 'prefix=/usr',
9 'sysconfdir=/etc',
10 'localstatedir=/var',
827ca909 11 'warning_level=2',
5c23128d 12 ],
35c035a1 13 meson_version : '>= 0.60.0',
5c23128d
ZJS
14 )
15
e37f3a12
LB
16libsystemd_version = '0.38.0'
17libudev_version = '1.7.8'
56d50ab1 18
5c23128d 19conf = configuration_data()
a8c03388 20conf.set_quoted('PROJECT_URL', 'https://systemd.io/')
d1b0d841 21conf.set('PROJECT_VERSION', meson.project_version(),
6ffeca8c 22 description : 'Numerical project version (used where a simple number is expected)')
5c23128d 23
1485aacb
DC
24# This is to be used instead of meson.source_root(), as the latter will return
25# the wrong result when systemd is being built as a meson subproject
26project_source_root = meson.current_source_dir()
81e06775 27project_build_root = meson.current_build_dir()
a0b15b41 28relative_source_path = run_command('realpath',
81e06775 29 '--relative-to=@0@'.format(project_build_root),
e92777d2
ZJS
30 project_source_root,
31 check : true).stdout().strip()
a0b15b41 32conf.set_quoted('RELATIVE_SOURCE_PATH', relative_source_path)
1485aacb 33
47350c5f
ZJS
34conf.set10('BUILD_MODE_DEVELOPER', get_option('mode') == 'developer',
35 description : 'tailor build to development or release builds')
2b84d628 36
1e73a64a
JJ
37feature = get_option('log-message-verification')
38if feature.auto()
39 have = conf.get('BUILD_MODE_DEVELOPER') == 1
011a03a3 40else
1e73a64a 41 have = feature.enabled()
011a03a3 42endif
1e73a64a 43conf.set10('LOG_MESSAGE_VERIFICATION', have)
839bdf25 44
c09edc79
ZJS
45want_ossfuzz = get_option('oss-fuzz')
46want_libfuzzer = get_option('llvm-fuzz')
c29537f3 47if want_ossfuzz and want_libfuzzer
6b8d32ea 48 error('only one of oss-fuzz or llvm-fuzz can be specified')
c09edc79 49endif
87ac55a1 50
6b8d32ea 51fuzzer_build = want_ossfuzz or want_libfuzzer
c09edc79 52
c4f883b7
ZJS
53# If we're building *not* for actual fuzzing, allow input samples of any size
54# (for testing and for reproduction of issues discovered with previously-higher
55# limits).
56conf.set10('FUZZ_USE_SIZE_LIMIT', fuzzer_build)
57
493cd503
ZJS
58# We'll set this to '1' for EFI builds in a different place.
59conf.set10('SD_BOOT', false)
60
3f871f12
ZJS
61# Create a title-less summary section early, so it ends up first in the output.
62# More items are added later after they have been detected.
63summary({'build mode' : get_option('mode')})
64
5c23128d
ZJS
65#####################################################################
66
003c8879 67# Try to install the git pre-commit hook
e2d612a8
ZJS
68add_git_hook_sh = find_program('tools/add-git-hook.sh', required : false)
69if add_git_hook_sh.found()
e92777d2 70 git_hook = run_command(add_git_hook_sh, check : false)
e2d612a8
ZJS
71 if git_hook.returncode() == 0
72 message(git_hook.stdout().strip())
73 endif
003c8879
ZJS
74endif
75
76#####################################################################
77
4cf8a609 78fs = import('fs')
157baa87 79if get_option('split-bin') == 'auto'
4cf8a609 80 split_bin = not fs.is_symlink('/usr/sbin')
157baa87
ZJS
81else
82 split_bin = get_option('split-bin') == 'true'
83endif
671f0f8d
ZJS
84conf.set10('HAVE_SPLIT_BIN', split_bin,
85 description : 'bin and sbin directories are separate')
157baa87 86
8ef8f3d5
FB
87have_standalone_binaries = get_option('standalone-binaries')
88
5c23128d
ZJS
89sysvinit_path = get_option('sysvinit-path')
90sysvrcnd_path = get_option('sysvrcnd-path')
348b4437 91conf.set10('HAVE_SYSV_COMPAT', sysvinit_path != '' and sysvrcnd_path != '',
349cc4a5 92 description : 'SysV init scripts and rcN.d links are supported')
6fe23ff3 93conf.set10('CREATE_LOG_DIRS', get_option('create-log-dirs'))
5c23128d 94
cdf7ad38
NL
95if get_option('hibernate') and not get_option('initrd')
96 error('hibernate depends on initrd')
97endif
98
a8b627aa
LP
99conf.set10('BUMP_PROC_SYS_FS_FILE_MAX', get_option('bump-proc-sys-fs-file-max'))
100conf.set10('BUMP_PROC_SYS_FS_NR_OPEN', get_option('bump-proc-sys-fs-nr-open'))
09dad04c 101conf.set('HIGH_RLIMIT_NOFILE', 512*1024)
a8b627aa 102
fce9abb2
ZJS
103# Meson ignores the preceding arguments when joining paths if an absolute
104# component is encountered, so this should canonicalize various paths when they
105# are absolute or relative.
5c23128d
ZJS
106prefixdir = get_option('prefix')
107if not prefixdir.startswith('/')
37efbbd8 108 error('Prefix is not absolute: "@0@"'.format(prefixdir))
5c23128d 109endif
d895e10a 110
b0d3095f 111prefixdir_noslash = '/' + prefixdir.strip('/')
fce9abb2 112bindir = prefixdir / get_option('bindir')
b0d3095f 113sbindir = prefixdir / (split_bin ? 'sbin' : 'bin')
9289e093 114sbin_to_bin = split_bin ? '../bin/' : ''
fce9abb2
ZJS
115libdir = prefixdir / get_option('libdir')
116sysconfdir = prefixdir / get_option('sysconfdir')
117includedir = prefixdir / get_option('includedir')
118datadir = prefixdir / get_option('datadir')
119localstatedir = '/' / get_option('localstatedir')
5c23128d 120
b0d3095f
LB
121libexecdir = prefixdir / 'lib/systemd'
122pkglibdir = libdir / 'systemd'
5c23128d 123
225d08b8
JT
124install_sysconfdir = get_option('install-sysconfdir') != 'false'
125install_sysconfdir_samples = get_option('install-sysconfdir') == 'true'
5c23128d 126# Dirs of external packages
fce9abb2
ZJS
127pkgconfigdatadir = get_option('pkgconfigdatadir') != '' ? get_option('pkgconfigdatadir') : datadir / 'pkgconfig'
128pkgconfiglibdir = get_option('pkgconfiglibdir') != '' ? get_option('pkgconfiglibdir') : libdir / 'pkgconfig'
129polkitpolicydir = datadir / 'polkit-1/actions'
130polkitrulesdir = datadir / 'polkit-1/rules.d'
131polkitpkladir = localstatedir / 'lib/polkit-1/localauthority/10-vendor.d'
132xinitrcdir = get_option('xinitrcdir') != '' ? get_option('xinitrcdir') : sysconfdir / 'X11/xinit/xinitrc.d'
8a38aac3
YW
133rpmmacrosdir = get_option('rpmmacrosdir')
134if rpmmacrosdir != 'no'
fce9abb2 135 rpmmacrosdir = prefixdir / rpmmacrosdir
8a38aac3 136endif
b0d3095f 137modprobedir = prefixdir / 'lib/modprobe.d'
5c23128d
ZJS
138
139# Our own paths
fce9abb2
ZJS
140pkgdatadir = datadir / 'systemd'
141environmentdir = prefixdir / 'lib/environment.d'
142pkgsysconfdir = sysconfdir / 'systemd'
143userunitdir = prefixdir / 'lib/systemd/user'
144userpresetdir = prefixdir / 'lib/systemd/user-preset'
145tmpfilesdir = prefixdir / 'lib/tmpfiles.d'
107795a7 146usertmpfilesdir = prefixdir / 'share/user-tmpfiles.d'
fce9abb2
ZJS
147sysusersdir = prefixdir / 'lib/sysusers.d'
148sysctldir = prefixdir / 'lib/sysctl.d'
149binfmtdir = prefixdir / 'lib/binfmt.d'
150modulesloaddir = prefixdir / 'lib/modules-load.d'
b0d3095f
LB
151networkdir = prefixdir / 'lib/systemd/network'
152systemgeneratordir = libexecdir / 'system-generators'
fce9abb2
ZJS
153usergeneratordir = prefixdir / 'lib/systemd/user-generators'
154systemenvgeneratordir = prefixdir / 'lib/systemd/system-environment-generators'
155userenvgeneratordir = prefixdir / 'lib/systemd/user-environment-generators'
b0d3095f
LB
156systemshutdowndir = libexecdir / 'system-shutdown'
157systemsleepdir = libexecdir / 'system-sleep'
158systemunitdir = prefixdir / 'lib/systemd/system'
159systempresetdir = prefixdir / 'lib/systemd/system-preset'
160udevlibexecdir = prefixdir / 'lib/udev'
fce9abb2
ZJS
161udevrulesdir = udevlibexecdir / 'rules.d'
162udevhwdbdir = udevlibexecdir / 'hwdb.d'
163catalogdir = prefixdir / 'lib/systemd/catalog'
641e2124 164kerneldir = prefixdir / 'lib/kernel'
165kernelinstalldir = kerneldir / 'install.d'
fce9abb2
ZJS
166factorydir = datadir / 'factory'
167bootlibdir = prefixdir / 'lib/systemd/boot/efi'
168testsdir = prefixdir / 'lib/systemd/tests'
26c2b302 169unittestsdir = testsdir / 'unit-tests'
539ee7ab 170testdata_dir = testsdir / 'testdata'
fce9abb2
ZJS
171systemdstatedir = localstatedir / 'lib/systemd'
172catalogstatedir = systemdstatedir / 'catalog'
173randomseeddir = localstatedir / 'lib/systemd'
b0d3095f 174profiledir = libexecdir / 'portable' / 'profile'
a121b331 175repartdefinitionsdir = libexecdir / 'repart/definitions'
b0d3095f 176ntpservicelistdir = prefixdir / 'lib/systemd/ntp-units.d'
24039e12 177credstoredir = prefixdir / 'lib/credstore'
8e35338d 178pcrlockdir = prefixdir / 'lib/pcrlock.d'
eb981a5b 179mimepackagesdir = prefixdir / 'share/mime/packages'
5c23128d 180
6495361c
FB
181configfiledir = get_option('configfiledir')
182if configfiledir == ''
183 configfiledir= sysconfdir
184endif
185pkgconfigfiledir = configfiledir / 'systemd'
186
75aaade1
TB
187docdir = get_option('docdir')
188if docdir == ''
fce9abb2 189 docdir = datadir / 'doc/systemd'
75aaade1
TB
190endif
191
5c23128d
ZJS
192pamlibdir = get_option('pamlibdir')
193if pamlibdir == ''
b0d3095f 194 pamlibdir = libdir / 'security'
5c23128d
ZJS
195endif
196
197pamconfdir = get_option('pamconfdir')
198if pamconfdir == ''
fce9abb2 199 pamconfdir = prefixdir / 'lib/pam.d'
5c23128d
ZJS
200endif
201
0abd510f
LP
202sshconfdir = get_option('sshconfdir')
203if sshconfdir == ''
204 sshconfdir = sysconfdir / 'ssh/ssh_config.d'
205endif
206
7e360799
LP
207sshdconfdir = get_option('sshdconfdir')
208if sshdconfdir == ''
209 sshdconfdir = sysconfdir / 'ssh/sshd_config.d'
210endif
211
d1ae38d8
OK
212libcryptsetup_plugins_dir = get_option('libcryptsetup-plugins-dir')
213if libcryptsetup_plugins_dir == ''
b0d3095f 214 libcryptsetup_plugins_dir = libdir / 'cryptsetup'
d1ae38d8
OK
215endif
216
444d5863 217memory_accounting_default = get_option('memory-accounting-default')
36cf4507 218status_unit_format_default = get_option('status-unit-format-default')
819c0dcb
ZJS
219if status_unit_format_default == 'auto'
220 status_unit_format_default = conf.get('BUILD_MODE_DEVELOPER') == 1 ? 'name' : 'description'
221endif
444d5863 222
b0d3095f 223conf.set_quoted('BINDIR', bindir)
491bf10c
ZJS
224conf.set_quoted('BINFMT_DIR', binfmtdir)
225conf.set_quoted('BOOTLIBDIR', bootlibdir)
fce9abb2 226conf.set_quoted('CATALOG_DATABASE', catalogstatedir / 'database')
491bf10c 227conf.set_quoted('CERTIFICATE_ROOT', get_option('certificate-root'))
6fe23ff3 228conf.set_quoted('DOC_DIR', docdir)
fce9abb2 229conf.set_quoted('DOCUMENT_ROOT', pkgdatadir / 'gatewayd')
491bf10c
ZJS
230conf.set_quoted('ENVIRONMENT_DIR', environmentdir)
231conf.set_quoted('INCLUDE_DIR', includedir)
232conf.set_quoted('LIBDIR', libdir)
b0d3095f 233conf.set_quoted('LIBEXECDIR', libexecdir)
491bf10c
ZJS
234conf.set_quoted('MODPROBE_DIR', modprobedir)
235conf.set_quoted('MODULESLOAD_DIR', modulesloaddir)
5c23128d 236conf.set_quoted('PKGSYSCONFDIR', pkgsysconfdir)
fce9abb2 237conf.set_quoted('POLKIT_AGENT_BINARY_PATH', bindir / 'pkttyagent')
491bf10c 238conf.set_quoted('PREFIX', prefixdir)
b0d3095f 239conf.set_quoted('PREFIX_NOSLASH', prefixdir_noslash)
fce9abb2 240conf.set_quoted('RANDOM_SEED', randomseeddir / 'random-seed')
491bf10c 241conf.set_quoted('RANDOM_SEED_DIR', randomseeddir)
452d2dfd 242conf.set_quoted('RC_LOCAL_PATH', get_option('rc-local'))
0abd510f 243conf.set_quoted('SSHCONFDIR', sshconfdir)
7e360799 244conf.set_quoted('SSHDCONFDIR', sshdconfdir)
491bf10c
ZJS
245conf.set_quoted('SYSCONF_DIR', sysconfdir)
246conf.set_quoted('SYSCTL_DIR', sysctldir)
b0d3095f
LB
247conf.set_quoted('SYSTEMCTL_BINARY_PATH', bindir / 'systemctl')
248conf.set_quoted('SYSTEMD_BINARY_PATH', libexecdir / 'systemd')
bb5232b6 249conf.set_quoted('SYSTEMD_EXECUTOR_BINARY_PATH', libexecdir / 'systemd-executor')
491bf10c 250conf.set_quoted('SYSTEMD_CATALOG_DIR', catalogdir)
b0d3095f 251conf.set_quoted('SYSTEMD_CGROUPS_AGENT_PATH', libexecdir / 'systemd-cgroups-agent')
fb8d67cd 252conf.set_quoted('SYSTEMD_CRYPTSETUP_PATH', bindir / 'systemd-cryptsetup')
b0d3095f
LB
253conf.set_quoted('SYSTEMD_EXPORT_PATH', libexecdir / 'systemd-export')
254conf.set_quoted('SYSTEMD_FSCK_PATH', libexecdir / 'systemd-fsck')
255conf.set_quoted('SYSTEMD_GROWFS_PATH', libexecdir / 'systemd-growfs')
256conf.set_quoted('SYSTEMD_HOMEWORK_PATH', libexecdir / 'systemd-homework')
257conf.set_quoted('SYSTEMD_IMPORT_FS_PATH', libexecdir / 'systemd-import-fs')
258conf.set_quoted('SYSTEMD_IMPORT_PATH', libexecdir / 'systemd-import')
259conf.set_quoted('SYSTEMD_INTEGRITYSETUP_PATH', libexecdir / 'systemd-integritysetup')
fce9abb2
ZJS
260conf.set_quoted('SYSTEMD_KBD_MODEL_MAP', pkgdatadir / 'kbd-model-map')
261conf.set_quoted('SYSTEMD_LANGUAGE_FALLBACK_MAP', pkgdatadir / 'language-fallback-map')
b0d3095f
LB
262conf.set_quoted('SYSTEMD_MAKEFS_PATH', libexecdir / 'systemd-makefs')
263conf.set_quoted('SYSTEMD_PULL_PATH', libexecdir / 'systemd-pull')
264conf.set_quoted('SYSTEMD_SHUTDOWN_BINARY_PATH', libexecdir / 'systemd-shutdown')
539ee7ab 265conf.set_quoted('SYSTEMD_TEST_DATA', testdata_dir)
b0d3095f
LB
266conf.set_quoted('SYSTEMD_TTY_ASK_PASSWORD_AGENT_BINARY_PATH', bindir / 'systemd-tty-ask-password-agent')
267conf.set_quoted('SYSTEMD_UPDATE_HELPER_PATH', libexecdir / 'systemd-update-helper')
268conf.set_quoted('SYSTEMD_USERWORK_PATH', libexecdir / 'systemd-userwork')
269conf.set_quoted('SYSTEMD_VERITYSETUP_PATH', libexecdir / 'systemd-veritysetup')
fce9abb2 270conf.set_quoted('SYSTEM_CONFIG_UNIT_DIR', pkgsysconfdir / 'system')
491bf10c 271conf.set_quoted('SYSTEM_DATA_UNIT_DIR', systemunitdir)
96d33e4a 272conf.set_quoted('SYSTEM_ENV_GENERATOR_DIR', systemenvgeneratordir)
491bf10c
ZJS
273conf.set_quoted('SYSTEM_GENERATOR_DIR', systemgeneratordir)
274conf.set_quoted('SYSTEM_PRESET_DIR', systempresetdir)
5c23128d
ZJS
275conf.set_quoted('SYSTEM_SHUTDOWN_PATH', systemshutdowndir)
276conf.set_quoted('SYSTEM_SLEEP_PATH', systemsleepdir)
491bf10c
ZJS
277conf.set_quoted('SYSTEM_SYSVINIT_PATH', sysvinit_path)
278conf.set_quoted('SYSTEM_SYSVRCND_PATH', sysvrcnd_path)
835cf75a
ZJS
279conf.set_quoted('SYSUSERS_DIR', sysusersdir)
280conf.set_quoted('TMPFILES_DIR', tmpfilesdir)
107795a7 281conf.set_quoted('USER_TMPFILES_DIR', usertmpfilesdir)
5c23128d 282conf.set_quoted('UDEVLIBEXECDIR', udevlibexecdir)
491bf10c
ZJS
283conf.set_quoted('UDEV_HWDB_DIR', udevhwdbdir)
284conf.set_quoted('UDEV_RULES_DIR', udevrulesdir)
fce9abb2 285conf.set_quoted('USER_CONFIG_UNIT_DIR', pkgsysconfdir / 'user')
491bf10c
ZJS
286conf.set_quoted('USER_DATA_UNIT_DIR', userunitdir)
287conf.set_quoted('USER_ENV_GENERATOR_DIR', userenvgeneratordir)
288conf.set_quoted('USER_GENERATOR_DIR', usergeneratordir)
fce9abb2 289conf.set_quoted('USER_KEYRING_PATH', pkgsysconfdir / 'import-pubring.gpg')
491bf10c 290conf.set_quoted('USER_PRESET_DIR', userpresetdir)
b0d3095f 291conf.set_quoted('VENDOR_KEYRING_PATH', libexecdir / 'import-pubring.gpg')
491bf10c
ZJS
292
293conf.set('ANSI_OK_COLOR', 'ANSI_' + get_option('ok-color').underscorify().to_upper())
e5d86ebe 294conf.set10('ENABLE_URLIFY', get_option('urlify'))
491bf10c 295conf.set10('ENABLE_FEXECVE', get_option('fexecve'))
30538ff1 296conf.set10('MEMORY_ACCOUNTING_DEFAULT', memory_accounting_default)
36cf4507 297conf.set('STATUS_UNIT_FORMAT_DEFAULT', 'STATUS_UNIT_FORMAT_' + status_unit_format_default.to_upper())
e11a25ca 298conf.set_quoted('STATUS_UNIT_FORMAT_DEFAULT_STR', status_unit_format_default)
5c23128d 299
e4c7b5f5
ZJS
300conf.set('DEFAULT_TIMEOUT_SEC', get_option('default-timeout-sec'))
301conf.set('DEFAULT_USER_TIMEOUT_SEC', get_option('default-user-timeout-sec'))
302conf.set('UPDATE_HELPER_USER_TIMEOUT_SEC', get_option('update-helper-user-timeout-sec'))
303
22330352 304conf.set10('ENABLE_FIRST_BOOT_FULL_PRESET', get_option('first-boot-full-preset'))
93651582 305
5c23128d
ZJS
306#####################################################################
307
308cc = meson.get_compiler('c')
92148283
JJ
309userspace_c_args = []
310userspace_c_ld_args = []
b68dfb9e 311meson_build_sh = find_program('tools/meson-build.sh')
5c23128d 312
d3da291e
ZJS
313want_tests = get_option('tests')
314slow_tests = want_tests != 'false' and get_option('slow-tests')
c56463fd 315fuzz_tests = want_tests != 'false' and get_option('fuzz-tests')
d3da291e
ZJS
316install_tests = get_option('install-tests')
317
daf4e78e 318if add_languages('cpp', native : false, required : fuzzer_build)
3b2bdd62 319 # Used only for tests
e9f4f566
ZJS
320 cxx = meson.get_compiler('cpp')
321 cxx_cmd = ' '.join(cxx.cmd_array())
1b2acaa7 322else
9b0ca019 323 cxx_cmd = ''
94e2523b
ZJS
324endif
325
31e57a35 326if want_libfuzzer
9c5c4677
EV
327 fuzzing_engine = meson.get_compiler('cpp').find_library('Fuzzer', required : false)
328 if fuzzing_engine.found()
92148283 329 userspace_c_args += '-fsanitize-coverage=trace-pc-guard,trace-cmp'
9c5c4677 330 elif cc.has_argument('-fsanitize=fuzzer-no-link')
92148283 331 userspace_c_args += '-fsanitize=fuzzer-no-link'
9c5c4677
EV
332 else
333 error('Looks like neither libFuzzer nor -fsanitize=fuzzer-no-link is supported')
334 endif
c09edc79 335elif want_ossfuzz
7db7d5b7
JR
336 fuzzing_engine = meson.get_compiler('cpp').find_library('FuzzingEngine')
337endif
338
e9f4f566
ZJS
339# Those generate many false positives, and we do not want to change the code to
340# avoid them.
341basic_disabled_warnings = [
e9f4f566 342 '-Wno-missing-field-initializers',
505ab9dd 343 '-Wno-unused-parameter',
b59bce30 344 '-Wno-nonnull-compare',
e9f4f566 345]
e9f4f566 346
65267363 347possible_common_cc_flags = [
fc568837
ZJS
348 '-Warray-bounds', # clang
349 '-Warray-bounds=2',
505ab9dd
YW
350 '-Wdate-time',
351 '-Wendif-labels',
352 '-Werror=format=2',
a4ea5d19 353 '-Werror=format-signedness',
505ab9dd 354 '-Werror=implicit-function-declaration',
a0d613ec 355 '-Werror=implicit-int',
505ab9dd 356 '-Werror=incompatible-pointer-types',
ebbb1e36 357 '-Werror=int-conversion',
0b482b37
JJ
358 '-Werror=missing-declarations',
359 '-Werror=missing-prototypes',
505ab9dd 360 '-Werror=overflow',
48c67fdf 361 '-Werror=override-init',
505ab9dd
YW
362 '-Werror=return-type',
363 '-Werror=shift-count-overflow',
364 '-Werror=shift-overflow=2',
6405afda 365 '-Werror=strict-flex-arrays',
30a4ddff 366 '-Werror=undef',
505ab9dd 367 '-Wfloat-equal',
c0f5d58c
JJ
368 # gperf prevents us from enabling this because it does not emit fallthrough
369 # attribute with clang.
370 #'-Wimplicit-fallthrough',
505ab9dd
YW
371 '-Wimplicit-fallthrough=5',
372 '-Winit-self',
30a4ddff
YW
373 '-Wlogical-op',
374 '-Wmissing-include-dirs',
505ab9dd
YW
375 '-Wmissing-noreturn',
376 '-Wnested-externs',
30a4ddff
YW
377 '-Wold-style-definition',
378 '-Wpointer-arith',
30a4ddff 379 '-Wredundant-decls',
30a4ddff 380 '-Wshadow',
30a4ddff 381 '-Wstrict-aliasing=2',
505ab9dd
YW
382 '-Wstrict-prototypes',
383 '-Wsuggest-attribute=noreturn',
054ed430 384 '-Wunused-function',
30a4ddff 385 '-Wwrite-strings',
31560245 386 '-Wzero-length-bounds',
bf7efeb1
FB
387
388 # negative arguments are correctly detected starting with meson 0.46.
eed33623
ZJS
389 '-Wno-error=#warnings', # clang
390 '-Wno-string-plus-int', # clang
fc568837 391
0b482b37
JJ
392 '-fdiagnostics-show-option',
393 '-fno-common',
48e1b2c2
JJ
394 '-fstack-protector',
395 '-fstack-protector-strong',
fc568837 396 '-fstrict-flex-arrays',
48e1b2c2
JJ
397 '--param=ssp-buffer-size=4',
398]
399
400possible_common_link_flags = [
401 '-fstack-protector',
30a4ddff
YW
402]
403
b528a628
ZJS
404c_args = get_option('c_args')
405
60f97fee 406# Our json library does not support -ffinite-math-only, which is enabled by -Ofast or -ffast-math.
53403091 407if (('-Ofast' in c_args or '-ffast-math' in c_args or '-ffinite-math-only' in c_args) and '-fno-finite-math-only' not in c_args)
60f97fee
YW
408 error('-Ofast, -ffast-math, or -ffinite-math-only is specified in c_args.')
409endif
410
a17e5478 411# Disable -Wmaybe-uninitialized when compiling with -Os/-O1/-O3/etc. There are
68c98a41
ZJS
412# too many false positives with gcc >= 8. Effectively, we only test with -O0
413# and -O2; this should be enough to catch most important cases without too much
414# busywork. See https://github.com/systemd/systemd/pull/19226.
415if cc.get_id() == 'gcc' and (not '02'.contains(get_option('optimization')) or
b528a628
ZJS
416 cc.version().version_compare('<10') or
417 '-Os' in c_args or
418 '-O1' in c_args or
419 '-O3' in c_args or
420 '-Og' in c_args)
65267363 421 possible_common_cc_flags += '-Wno-maybe-uninitialized'
68c98a41
ZJS
422endif
423
bc2a4af2
ZJS
424# Disable -Wno-unused-result with gcc, see
425# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66425.
426if cc.get_id() == 'gcc'
427 possible_common_cc_flags += '-Wno-unused-result'
428endif
429
30a4ddff 430# --as-needed and --no-undefined are provided by meson by default,
9247df5a 431# run 'meson configure' to see what is enabled
30a4ddff 432possible_link_flags = [
42e3bb35 433 '-Wl,--fatal-warnings',
30a4ddff 434 '-Wl,-z,now',
42e3bb35 435 '-Wl,-z,relro',
30a4ddff 436]
5c23128d 437
42e3bb35
JJ
438if get_option('b_sanitize') == 'none'
439 possible_link_flags += '-Wl,--warn-common'
440endif
441
30a4ddff 442if cc.get_id() == 'clang'
65267363 443 possible_common_cc_flags += [
30a4ddff
YW
444 '-Wno-typedef-redefinition',
445 '-Wno-gnu-variable-sized-type-not-at-end',
446 ]
447endif
448
1a4e3927
JJ
449if get_option('mode') == 'release'
450 # We could enable 'pattern' for developer mode, but that can interfere with
451 # valgrind and sanitizer builds. Also, clang does not zero-initialize unions,
452 # breaking some of our code (https://reviews.llvm.org/D68115).
453 possible_common_cc_flags += '-ftrivial-auto-var-init=zero'
454endif
455
92148283 456possible_cc_flags = [
16e09d51 457 '-fno-strict-aliasing',
afd8e1d9 458 '-fstrict-flex-arrays=1',
16e09d51 459 '-fvisibility=hidden',
16e09d51
YW
460]
461
30a4ddff 462if get_option('buildtype') != 'debug'
16e09d51 463 possible_cc_flags += [
30a4ddff
YW
464 '-ffunction-sections',
465 '-fdata-sections',
466 ]
467
468 possible_link_flags += '-Wl,--gc-sections'
469endif
470
82390022
DDM
471if get_option('mode') == 'developer'
472 possible_cc_flags += '-fno-omit-frame-pointer'
473endif
474
92148283
JJ
475add_project_arguments(
476 cc.get_supported_arguments(
477 basic_disabled_warnings,
478 possible_common_cc_flags
479 ),
480 language : 'c')
481
48e1b2c2
JJ
482add_project_link_arguments(
483 cc.get_supported_link_arguments(possible_common_link_flags),
484 language : 'c')
485
92148283
JJ
486userspace_c_args += cc.get_supported_arguments(possible_cc_flags)
487userspace_c_ld_args += cc.get_supported_link_arguments(possible_link_flags)
30a4ddff 488
94c0c5b7
ZJS
489have = cc.has_argument('-Wzero-length-bounds')
490conf.set10('HAVE_ZERO_LENGTH_BOUNDS', have)
491
9e70f2f8 492if cc.compiles('''
5c23128d
ZJS
493 #include <time.h>
494 #include <inttypes.h>
495 typedef uint64_t usec_t;
496 usec_t now(clockid_t clock);
497 int main(void) {
498 struct timespec now;
499 return 0;
500 }
38c1c96d 501''', args: '-Werror=shadow', name : '-Werror=shadow with local shadowing')
37efbbd8 502 add_project_arguments('-Werror=shadow', language : 'c')
5c23128d
ZJS
503endif
504
e9f4f566
ZJS
505if cxx_cmd != ''
506 add_project_arguments(cxx.get_supported_arguments(basic_disabled_warnings), language : 'cpp')
507endif
508
465104b4 509cpp = ' '.join(cc.cmd_array() + get_option('c_args')) + ' -E'
9cc0e6e9 510
6695c200
ZJS
511has_wstringop_truncation = cc.has_argument('-Wstringop-truncation')
512
5c23128d
ZJS
513#####################################################################
514# compilation result tests
515
78103450 516conf.set('_GNU_SOURCE', 1)
2c201c21 517conf.set('__SANE_USERSPACE_TYPES__', true)
6695c200 518conf.set10('HAVE_WSTRINGOP_TRUNCATION', has_wstringop_truncation)
5c23128d 519
5c23128d
ZJS
520conf.set('SIZEOF_DEV_T', cc.sizeof('dev_t', prefix : '#include <sys/types.h>'))
521conf.set('SIZEOF_INO_T', cc.sizeof('ino_t', prefix : '#include <sys/types.h>'))
5c23128d 522conf.set('SIZEOF_RLIM_T', cc.sizeof('rlim_t', prefix : '#include <sys/resource.h>'))
84d953e8 523conf.set('SIZEOF_TIME_T', cc.sizeof('time_t', prefix : '#include <sys/time.h>'))
3112d756 524conf.set('SIZEOF_TIMEX_MEMBER', cc.sizeof('typeof(((struct timex *)0)->freq)', prefix : '#include <sys/timex.h>'))
5c23128d 525
2736a0c6 526long_max = cc.compute_int(
527 'LONG_MAX',
528 prefix : '#include <limits.h>',
529 guess : 0x7FFFFFFFFFFFFFFF,
530 high : 0x7FFFFFFFFFFFFFFF)
a5fac1df
ZJS
531assert(long_max > 100000)
532conf.set_quoted('LONG_MAX_STR', '@0@'.format(long_max))
533
5c23128d 534decl_headers = '''
eb292969 535#include <dirent.h>
5c23128d 536#include <uchar.h>
84e8edec 537#include <sys/mount.h>
4c2e1b39 538#include <sys/stat.h>
5c23128d 539'''
5c23128d
ZJS
540
541foreach decl : ['char16_t',
542 'char32_t',
84e8edec 543 'struct mount_attr',
4c2e1b39 544 'struct statx',
eb292969 545 'struct dirent64',
5c23128d 546 ]
2c201c21
ZJS
547
548 # We get -1 if the size cannot be determined
9c869d08
ZJS
549 have = cc.sizeof(decl, prefix : decl_headers, args : '-D_GNU_SOURCE') > 0
550
3657d3a0
RH
551 if decl == 'struct mount_attr'
552 if have
553 want_linux_fs_h = false
554 else
555 have = cc.sizeof(decl,
556 prefix : decl_headers + '#include <linux/fs.h>',
557 args : '-D_GNU_SOURCE') > 0
558 want_linux_fs_h = have
559 endif
560 endif
561
9c869d08
ZJS
562 if decl == 'struct statx'
563 if have
564 want_linux_stat_h = false
565 else
566 have = cc.sizeof(decl,
567 prefix : decl_headers + '#include <linux/stat.h>',
568 args : '-D_GNU_SOURCE') > 0
569 want_linux_stat_h = have
570 endif
571 endif
572
349cc4a5 573 conf.set10('HAVE_' + decl.underscorify().to_upper(), have)
5c23128d
ZJS
574endforeach
575
9c869d08 576conf.set10('WANT_LINUX_STAT_H', want_linux_stat_h)
3657d3a0 577conf.set10('WANT_LINUX_FS_H', want_linux_fs_h)
75720bff 578
5c23128d 579foreach ident : ['secure_getenv', '__secure_getenv']
349cc4a5 580 conf.set10('HAVE_' + ident.to_upper(), cc.has_function(ident))
5c23128d
ZJS
581endforeach
582
583foreach ident : [
85db59b7 584 ['memfd_create', '''#include <sys/mman.h>'''],
7b961e40
LP
585 ['gettid', '''#include <sys/types.h>
586 #include <unistd.h>'''],
c21566d9
AM
587 ['fchmodat2', '''#include <stdlib.h>
588 #include <fcntl.h>'''], # no known header declares fchmodat2
3c042add
LP
589 ['pivot_root', '''#include <stdlib.h>
590 #include <unistd.h>'''], # no known header declares pivot_root
51fe206f
ZJS
591 ['ioprio_get', '''#include <sched.h>'''], # no known header declares ioprio_get
592 ['ioprio_set', '''#include <sched.h>'''], # no known header declares ioprio_set
85db59b7 593 ['name_to_handle_at', '''#include <sys/types.h>
37efbbd8
ZJS
594 #include <sys/stat.h>
595 #include <fcntl.h>'''],
85db59b7 596 ['setns', '''#include <sched.h>'''],
2acfd0ff
LP
597 ['renameat2', '''#include <stdio.h>
598 #include <fcntl.h>'''],
37efbbd8
ZJS
599 ['kcmp', '''#include <linux/kcmp.h>'''],
600 ['keyctl', '''#include <sys/types.h>
601 #include <keyutils.h>'''],
85db59b7 602 ['copy_file_range', '''#include <sys/syscall.h>
37efbbd8 603 #include <unistd.h>'''],
71e5200f
DM
604 ['bpf', '''#include <sys/syscall.h>
605 #include <unistd.h>'''],
4c2e1b39
LP
606 ['statx', '''#include <sys/types.h>
607 #include <sys/stat.h>
608 #include <unistd.h>'''],
aa484f35 609 ['explicit_bzero' , '''#include <string.h>'''],
5bb20fd3 610 ['reallocarray', '''#include <stdlib.h>'''],
b070c7c0
MS
611 ['set_mempolicy', '''#include <stdlib.h>
612 #include <unistd.h>'''],
613 ['get_mempolicy', '''#include <stdlib.h>
614 #include <unistd.h>'''],
5f152f43
LP
615 ['pidfd_send_signal', '''#include <stdlib.h>
616 #include <unistd.h>
617 #include <signal.h>
618 #include <sys/wait.h>'''],
619 ['pidfd_open', '''#include <stdlib.h>
620 #include <unistd.h>
621 #include <signal.h>
622 #include <sys/wait.h>'''],
5ead4e85
LP
623 ['rt_sigqueueinfo', '''#include <stdlib.h>
624 #include <unistd.h>
625 #include <signal.h>
626 #include <sys/wait.h>'''],
a5421953
DDM
627 ['rt_tgsigqueueinfo', '''#include <stdlib.h>
628 #include <unistd.h>
629 #include <signal.h>
630 #include <sys/wait.h>'''],
4b6f74f5 631 ['mallinfo', '''#include <malloc.h>'''],
1885169c 632 ['mallinfo2', '''#include <malloc.h>'''],
8939eeae 633 ['execveat', '''#include <unistd.h>'''],
441e0fdb 634 ['close_range', '''#include <unistd.h>'''],
420297c9 635 ['epoll_pwait2', '''#include <sys/epoll.h>'''],
84e8edec
LP
636 ['mount_setattr', '''#include <sys/mount.h>'''],
637 ['move_mount', '''#include <sys/mount.h>'''],
638 ['open_tree', '''#include <sys/mount.h>'''],
1c265fcd
DDM
639 ['fsopen', '''#include <sys/mount.h>'''],
640 ['fsconfig', '''#include <sys/mount.h>'''],
34a9da0d 641 ['fsmount', '''#include <sys/mount.h>'''],
aab35b1e 642 ['getdents64', '''#include <dirent.h>'''],
37efbbd8
ZJS
643]
644
85db59b7 645 have = cc.has_function(ident[0], prefix : ident[1], args : '-D_GNU_SOURCE')
4b9545f1 646 conf.set10('HAVE_' + ident[0].to_upper(), have)
5c23128d
ZJS
647endforeach
648
85db59b7 649if cc.has_function('getrandom', prefix : '''#include <sys/random.h>''', args : '-D_GNU_SOURCE')
349cc4a5 650 conf.set10('USE_SYS_RANDOM_H', true)
4b9545f1 651 conf.set10('HAVE_GETRANDOM', true)
4984c8be
ZJS
652else
653 have = cc.has_function('getrandom', prefix : '''#include <linux/random.h>''')
349cc4a5 654 conf.set10('USE_SYS_RANDOM_H', false)
4b9545f1 655 conf.set10('HAVE_GETRANDOM', have)
4984c8be
ZJS
656endif
657
5c23128d
ZJS
658#####################################################################
659
0f4c4f38
ZJS
660sh = find_program('sh')
661echo = find_program('echo')
5c23128d 662sed = find_program('sed')
5c23128d 663awk = find_program('awk')
5c23128d 664stat = find_program('stat')
0f4c4f38 665ln = find_program('ln')
d68b342b 666git = find_program('git', required : false)
b68dfb9e 667env = find_program('env')
0f4c4f38 668rsync = find_program('rsync', required : false)
4d56d084 669diff = find_program('diff')
d9081eb0 670find = find_program('find')
5c23128d 671
9289e093 672ln_s = ln.full_path() + ' -frsT -- "${DESTDIR:-}@0@" "${DESTDIR:-}@1@"'
94e75a54 673
9247df5a 674# If -Dxxx-path option is found, use that. Otherwise, check in $PATH,
5c23128d 675# /usr/sbin, /sbin, and fall back to the default from middle column.
2fa645f1 676progs = [['quotaon', '/usr/sbin/quotaon' ],
5c23128d 677 ['quotacheck', '/usr/sbin/quotacheck' ],
5c23128d
ZJS
678 ['kmod', '/usr/bin/kmod' ],
679 ['kexec', '/usr/sbin/kexec' ],
680 ['sulogin', '/usr/sbin/sulogin' ],
681 ['mount', '/usr/bin/mount', 'MOUNT_PATH'],
682 ['umount', '/usr/bin/umount', 'UMOUNT_PATH'],
683 ['loadkeys', '/usr/bin/loadkeys', 'KBD_LOADKEYS'],
684 ['setfont', '/usr/bin/setfont', 'KBD_SETFONT'],
6db90462 685 ['nologin', '/usr/sbin/nologin', ],
5c23128d
ZJS
686 ]
687foreach prog : progs
37efbbd8
ZJS
688 path = get_option(prog[0] + '-path')
689 if path != ''
690 message('Using @1@ for @0@'.format(prog[0], path))
691 else
692 exe = find_program(prog[0],
693 '/usr/sbin/' + prog[0],
694 '/sbin/' + prog[0],
695 required: false)
573c0dc1 696 path = exe.found() ? exe.full_path() : prog[1]
37efbbd8
ZJS
697 endif
698 name = prog.length() > 2 ? prog[2] : prog[0].to_upper()
699 conf.set_quoted(name, path)
5c23128d
ZJS
700endforeach
701
2fa645f1
MG
702conf.set_quoted('TELINIT', get_option('telinit-path'))
703
e92777d2 704if run_command(ln, '--relative', '--help', check : false).returncode() != 0
cd001016 705 error('ln does not support --relative (added in coreutils 8.16)')
1276a9f6 706endif
5c23128d 707
e6267e83 708#####################################################################
5c23128d
ZJS
709
710gperf = find_program('gperf')
711
712gperf_test_format = '''
713#include <string.h>
714const char * in_word_set(const char *, @0@);
715@1@
716'''
ac3eda34 717gperf_snippet = run_command(sh, '-c', 'echo foo,bar | "$1" -L ANSI-C', '_', gperf,
e92777d2 718 check : true)
5c23128d
ZJS
719gperf_test = gperf_test_format.format('size_t', gperf_snippet.stdout())
720if cc.compiles(gperf_test)
37efbbd8 721 gperf_len_type = 'size_t'
5c23128d 722else
37efbbd8
ZJS
723 gperf_test = gperf_test_format.format('unsigned', gperf_snippet.stdout())
724 if cc.compiles(gperf_test)
725 gperf_len_type = 'unsigned'
726 else
727 error('unable to determine gperf len type')
728 endif
5c23128d
ZJS
729endif
730message('gperf len type is @0@'.format(gperf_len_type))
37efbbd8
ZJS
731conf.set('GPERF_LEN_TYPE', gperf_len_type,
732 description : 'The type of gperf "len" parameter')
5c23128d 733
e6267e83 734#####################################################################
5c23128d
ZJS
735
736if not cc.has_header('sys/capability.h')
37efbbd8 737 error('POSIX caps headers not found')
5c23128d 738endif
9f555bba 739foreach header : ['crypt.h',
5c23128d
ZJS
740 'linux/memfd.h',
741 'linux/vm_sockets.h',
af8786b1 742 'sys/auxv.h',
5545f336 743 'threads.h',
5c23128d
ZJS
744 'valgrind/memcheck.h',
745 'valgrind/valgrind.h',
420297c9 746 'linux/time_types.h',
b428efa5 747 'sys/sdt.h',
5c23128d 748 ]
2c201c21 749
349cc4a5
ZJS
750 conf.set10('HAVE_' + header.underscorify().to_upper(),
751 cc.has_header(header))
5c23128d
ZJS
752endforeach
753
e6267e83 754#####################################################################
5c23128d 755
eef4b800
ZJS
756fallback_hostname = get_option('fallback-hostname')
757if fallback_hostname == '' or fallback_hostname[0] == '.' or fallback_hostname[0] == '-'
758 error('Invalid fallback-hostname configuration')
759 # A more extensive test is done in test-hostname-util. Let's catch
760 # the most obvious errors here so we don't fail with an assert later.
761endif
762conf.set_quoted('FALLBACK_HOSTNAME', fallback_hostname)
763
5c23128d
ZJS
764default_hierarchy = get_option('default-hierarchy')
765conf.set_quoted('DEFAULT_HIERARCHY_NAME', default_hierarchy,
766 description : 'default cgroup hierarchy as string')
767if default_hierarchy == 'legacy'
37efbbd8 768 conf.set('DEFAULT_HIERARCHY', 'CGROUP_UNIFIED_NONE')
5c23128d 769elif default_hierarchy == 'hybrid'
37efbbd8 770 conf.set('DEFAULT_HIERARCHY', 'CGROUP_UNIFIED_SYSTEMD')
5c23128d 771else
37efbbd8 772 conf.set('DEFAULT_HIERARCHY', 'CGROUP_UNIFIED_ALL')
5c23128d
ZJS
773endif
774
681cb84a
ZJS
775extra_net_naming_schemes = []
776extra_net_naming_map = []
777foreach scheme: get_option('extra-net-naming-schemes').split(',')
778 if scheme != ''
779 name = scheme.split('=')[0]
780 value = scheme.split('=')[1]
781 NAME = name.underscorify().to_upper()
782 VALUE = []
783 foreach field: value.split('+')
784 VALUE += 'NAMING_' + field.underscorify().to_upper()
785 endforeach
786 extra_net_naming_schemes += 'NAMING_@0@ = @1@,'.format(NAME, '|'.join(VALUE))
787 extra_net_naming_map += '{ "@0@", NAMING_@1@ },'.format(name, NAME)
788 endif
789endforeach
790conf.set('EXTRA_NET_NAMING_SCHEMES', ' '.join(extra_net_naming_schemes))
791conf.set('EXTRA_NET_NAMING_MAP', ' '.join(extra_net_naming_map))
792
06da5c63 793default_net_naming_scheme = get_option('default-net-naming-scheme')
386256e6
ZJS
794conf.set_quoted('DEFAULT_NET_NAMING_SCHEME', default_net_naming_scheme,
795 description : 'Default naming scheme as a string')
77faadfd 796if default_net_naming_scheme != 'latest'
386256e6
ZJS
797 conf.set('_DEFAULT_NET_NAMING_SCHEME',
798 'NAMING_' + default_net_naming_scheme.underscorify().to_upper(),
799 description : 'Default naming scheme as a constant')
77faadfd 800endif
06da5c63 801
5c23128d 802time_epoch = get_option('time-epoch')
a36be3e5 803if time_epoch <= 0
e92777d2 804 time_epoch = run_command(sh, '-c', 'echo "$SOURCE_DATE_EPOCH"', check : true).stdout().strip()
edd84b8e 805 if time_epoch == '' and git.found() and fs.is_dir('.git')
bd190899 806 # If we're in a git repository, use the creation time of the latest git tag.
e92777d2
ZJS
807 latest_tag = run_command(git, 'describe', '--abbrev=0', '--tags',
808 check : false)
809 if latest_tag.returncode() == 0
810 time_epoch = run_command(
811 git, 'log', '--no-show-signature', '-1', '--format=%at',
812 latest_tag.stdout().strip(),
813 check : false).stdout()
814 endif
0390b094
ZJS
815 endif
816 if time_epoch == ''
6dbf352c 817 NEWS = files('NEWS')
e92777d2
ZJS
818 time_epoch = run_command(stat, '-c', '%Y', NEWS,
819 check : true).stdout()
6dbf352c 820 endif
89cdbe1f 821 time_epoch = time_epoch.strip().to_int()
5c23128d 822endif
5c23128d
ZJS
823conf.set('TIME_EPOCH', time_epoch)
824
b10abe4b
EI
825conf.set('CLOCK_VALID_RANGE_USEC_MAX', get_option('clock-valid-range-usec-max'))
826
53350c7b 827default_user_shell = get_option('default-user-shell')
828conf.set_quoted('DEFAULT_USER_SHELL', default_user_shell)
829conf.set_quoted('DEFAULT_USER_SHELL_NAME', fs.name(default_user_shell))
830
fc1a5d1a
ZJS
831foreach tuple : [['system-alloc-uid-min', 'SYS_UID_MIN', 1], # Also see login.defs(5).
832 ['system-uid-max', 'SYS_UID_MAX', 999],
833 ['system-alloc-gid-min', 'SYS_GID_MIN', 1],
834 ['system-gid-max', 'SYS_GID_MAX', 999]]
835 v = get_option(tuple[0])
a36be3e5 836 if v <= 0
fc1a5d1a
ZJS
837 v = run_command(
838 awk,
839 '/^\s*@0@\s+/ { uid=$2 } END { print uid }'.format(tuple[1]),
e92777d2
ZJS
840 '/etc/login.defs',
841 check : false).stdout().strip()
fc1a5d1a
ZJS
842 if v == ''
843 v = tuple[2]
844 else
845 v = v.to_int()
846 endif
2f62cf35 847 endif
fc1a5d1a 848 conf.set(tuple[0].underscorify().to_upper(), v)
fc1a5d1a
ZJS
849endforeach
850if conf.get('SYSTEM_ALLOC_UID_MIN') >= conf.get('SYSTEM_UID_MAX')
851 error('Invalid uid allocation range')
5c23128d 852endif
fc1a5d1a
ZJS
853if conf.get('SYSTEM_ALLOC_GID_MIN') >= conf.get('SYSTEM_GID_MAX')
854 error('Invalid gid allocation range')
5c23128d 855endif
5c23128d 856
ac09340e
YW
857dynamic_uid_min = get_option('dynamic-uid-min')
858dynamic_uid_max = get_option('dynamic-uid-max')
87d5e4f2
LP
859conf.set('DYNAMIC_UID_MIN', dynamic_uid_min)
860conf.set('DYNAMIC_UID_MAX', dynamic_uid_max)
87d5e4f2 861
ac09340e
YW
862container_uid_base_min = get_option('container-uid-base-min')
863container_uid_base_max = get_option('container-uid-base-max')
87d5e4f2
LP
864conf.set('CONTAINER_UID_BASE_MIN', container_uid_base_min)
865conf.set('CONTAINER_UID_BASE_MAX', container_uid_base_max)
87d5e4f2 866
afde4574
LP
867nobody_user = get_option('nobody-user')
868nobody_group = get_option('nobody-group')
869
2484bff3 870if not meson.is_cross_build()
e92777d2 871 getent_result = run_command('getent', 'passwd', '65534', check : false)
2484bff3
CQ
872 if getent_result.returncode() == 0
873 name = getent_result.stdout().split(':')[0]
874 if name != nobody_user
875 warning('\n' +
876 'The local user with the UID 65534 does not match the configured user name "@0@" of the nobody user (its name is @1@).\n'.format(nobody_user, name) +
877 'Your build will result in an user table setup that is incompatible with the local system.')
878 endif
afde4574 879 endif
e92777d2 880 id_result = run_command('id', '-u', nobody_user, check : false)
2484bff3 881 if id_result.returncode() == 0
89cdbe1f 882 id = id_result.stdout().strip().to_int()
2484bff3
CQ
883 if id != 65534
884 warning('\n' +
885 'The local user with the configured user name "@0@" of the nobody user does not have UID 65534 (it has @1@).\n'.format(nobody_user, id) +
886 'Your build will result in an user table setup that is incompatible with the local system.')
887 endif
afde4574 888 endif
afde4574 889
e92777d2 890 getent_result = run_command('getent', 'group', '65534', check : false)
2484bff3
CQ
891 if getent_result.returncode() == 0
892 name = getent_result.stdout().split(':')[0]
893 if name != nobody_group
894 warning('\n' +
895 'The local group with the GID 65534 does not match the configured group name "@0@" of the nobody group (its name is @1@).\n'.format(nobody_group, name) +
896 'Your build will result in an group table setup that is incompatible with the local system.')
897 endif
afde4574 898 endif
e92777d2 899 id_result = run_command('id', '-g', nobody_group, check : false)
2484bff3 900 if id_result.returncode() == 0
89cdbe1f 901 id = id_result.stdout().strip().to_int()
2484bff3
CQ
902 if id != 65534
903 warning('\n' +
d5b3e510 904 'The local group with the configured group name "@0@" of the nobody group does not have GID 65534 (it has @1@).\n'.format(nobody_group, id) +
2484bff3
CQ
905 'Your build will result in an group table setup that is incompatible with the local system.')
906 endif
afde4574
LP
907 endif
908endif
8374cc62 909if nobody_user != nobody_group and not (nobody_user == 'nobody' and nobody_group == 'nogroup')
8ea9fad7 910 warning('\n' +
79f48703 911 'The configured user name "@0@" and group name "@1@" of the nobody user/group are not equivalent.\n'.format(nobody_user, nobody_group) +
8ea9fad7 912 'Please re-check that both "nobody-user" and "nobody-group" options are correctly set.')
8374cc62 913endif
afde4574
LP
914
915conf.set_quoted('NOBODY_USER_NAME', nobody_user)
916conf.set_quoted('NOBODY_GROUP_NAME', nobody_group)
87d5e4f2 917
9a797ddc
ZJS
918static_ugids = []
919foreach option : ['adm-gid',
920 'audio-gid',
921 'cdrom-gid',
922 'dialout-gid',
923 'disk-gid',
924 'input-gid',
925 'kmem-gid',
926 'kvm-gid',
927 'lp-gid',
928 'render-gid',
929 'sgx-gid',
930 'tape-gid',
931 'tty-gid',
932 'users-gid',
933 'utmp-gid',
934 'video-gid',
935 'wheel-gid',
936 'systemd-journal-gid',
937 'systemd-network-uid',
938 'systemd-resolve-uid',
939 'systemd-timesync-uid']
940 name = option.underscorify().to_upper()
941 val = get_option(option)
942
943 # Ensure provided GID argument is numeric, otherwise fall back to default assignment
a36be3e5
YW
944 conf.set(name, val > 0 ? val : '-')
945 if val > 0
9a797ddc
ZJS
946 static_ugids += '@0@:@1@'.format(option, val)
947 endif
948endforeach
84786b8e 949
348b4437
YW
950conf.set10('ENABLE_ADM_GROUP', get_option('adm-group'))
951conf.set10('ENABLE_WHEEL_GROUP', get_option('wheel-group'))
5c23128d 952
ace5e311 953dev_kvm_mode = get_option('dev-kvm-mode')
d924a938 954conf.set_quoted('DEV_KVM_MODE', dev_kvm_mode) # FIXME: convert to 0o… notation
ace5e311 955conf.set10('DEV_KVM_UACCESS', dev_kvm_mode != '0666')
055a083a 956group_render_mode = get_option('group-render-mode')
8feaea5e 957conf.set_quoted('GROUP_RENDER_MODE', group_render_mode)
055a083a 958conf.set10('GROUP_RENDER_UACCESS', group_render_mode != '0666')
5c23128d 959
2a4c156d
ZJS
960kill_user_processes = get_option('default-kill-user-processes')
961conf.set10('KILL_USER_PROCESSES', kill_user_processes)
5c23128d 962
829257d1
ZJS
963dns_servers = get_option('dns-servers')
964conf.set_quoted('DNS_SERVERS', dns_servers)
5c23128d 965
829257d1
ZJS
966ntp_servers = get_option('ntp-servers')
967conf.set_quoted('NTP_SERVERS', ntp_servers)
5c23128d 968
8ca9e92c
DR
969default_locale = get_option('default-locale')
970conf.set_quoted('SYSTEMD_DEFAULT_LOCALE', default_locale)
971
a22f5186
DDM
972nspawn_locale = get_option('nspawn-locale')
973conf.set_quoted('SYSTEMD_NSPAWN_LOCALE', nspawn_locale)
974
f129d0e7 975default_keymap = get_option('default-keymap')
ef7f5baa 976if default_keymap == ''
bf77d597 977 # We canonicalize empty keymap to '@kernel', as it makes the default value
ef7f5baa 978 # in the factory provided /etc/vconsole.conf more obvious.
bf77d597 979 default_keymap = '@kernel'
ef7f5baa 980endif
f129d0e7
MY
981conf.set_quoted('SYSTEMD_DEFAULT_KEYMAP', default_keymap)
982
8f20232f 983localegen_path = get_option('localegen-path')
8f20232f
MK
984if localegen_path != ''
985 conf.set_quoted('LOCALEGEN_PATH', localegen_path)
8f20232f 986endif
71ae5ce5 987conf.set10('HAVE_LOCALEGEN', localegen_path != '')
8f20232f 988
5c23128d
ZJS
989conf.set_quoted('GETTEXT_PACKAGE', meson.project_name())
990
21d0dd5a 991service_watchdog = get_option('service-watchdog')
7bc9ea51 992watchdog_value = service_watchdog == '' ? '' : 'WatchdogSec=' + service_watchdog
059cc610 993conf.set_quoted('SERVICE_WATCHDOG', watchdog_value)
21d0dd5a 994
059cc610 995conf.set_quoted('SUSHELL', get_option('debug-shell'))
93912e87 996conf.set_quoted('DEBUGTTY', get_option('debug-tty'))
3131bfe3 997
349cc4a5
ZJS
998enable_debug_hashmap = false
999enable_debug_mmap_cache = false
d6601495 1000enable_debug_siphash = false
8f6b442a 1001foreach name : get_option('debug-extra')
ad7aa760
YW
1002 if name == 'hashmap'
1003 enable_debug_hashmap = true
1004 elif name == 'mmap-cache'
1005 enable_debug_mmap_cache = true
d6601495
YW
1006 elif name == 'siphash'
1007 enable_debug_siphash = true
ad7aa760
YW
1008 else
1009 message('unknown debug option "@0@", ignoring'.format(name))
1010 endif
1011endforeach
349cc4a5
ZJS
1012conf.set10('ENABLE_DEBUG_HASHMAP', enable_debug_hashmap)
1013conf.set10('ENABLE_DEBUG_MMAP_CACHE', enable_debug_mmap_cache)
d6601495 1014conf.set10('ENABLE_DEBUG_SIPHASH', enable_debug_siphash)
fd5dec9a 1015conf.set10('LOG_TRACE', get_option('log-trace'))
d18cb393 1016
3602ca6f
ZJS
1017default_user_path = get_option('user-path')
1018if default_user_path != ''
1019 conf.set_quoted('DEFAULT_USER_PATH', default_user_path)
1020endif
1021
5c23128d
ZJS
1022#####################################################################
1023
1024threads = dependency('threads')
1025librt = cc.find_library('rt')
1026libm = cc.find_library('m')
1027libdl = cc.find_library('dl')
55573787
YW
1028libcrypt = dependency('libcrypt', 'libxcrypt', required : false)
1029if not libcrypt.found()
1030 # fallback to use find_library() if libcrypt is provided by glibc, e.g. for LibreELEC.
1031 libcrypt = cc.find_library('crypt')
1032endif
d625f717 1033libcap = dependency('libcap')
5c23128d 1034
96f8c636
ZJS
1035# On some architectures, libatomic is required. But on some installations,
1036# it is found, but actual linking fails. So let's try to use it opportunistically.
1037# If it is installed, but not needed, it will be dropped because of --as-needed.
1038if cc.links('''int main(int argc, char **argv) { return 0; }''',
1039 args : '-latomic',
1040 name : 'libatomic')
1041 libatomic = declare_dependency(link_args : '-latomic')
1042else
1043 libatomic = []
1044endif
1045
06ca077b 1046crypt_header = conf.get('HAVE_CRYPT_H') == 1 ? '''#include <crypt.h>''' : '''#include <unistd.h>'''
e8644a41 1047foreach ident : [
feee7f62
LB
1048 ['crypt_ra', crypt_header],
1049 ['crypt_preferred_method', crypt_header],
1050 ['crypt_gensalt_ra', crypt_header]]
e8644a41
ZJS
1051
1052 have = cc.has_function(ident[0], prefix : ident[1], args : '-D_GNU_SOURCE',
1053 dependencies : libcrypt)
1054 conf.set10('HAVE_' + ident[0].to_upper(), have)
1055endforeach
1056
847e5585 1057bpf_framework = get_option('bpf-framework')
b88323e4 1058bpf_compiler = get_option('bpf-compiler')
847e5585
JJ
1059libbpf = dependency('libbpf',
1060 required : bpf_framework,
1061 version : bpf_compiler == 'gcc' ? '>= 1.0.0' : '>= 0.1.0')
7d861e12
JK
1062conf.set10('HAVE_LIBBPF', libbpf.found())
1063
847e5585 1064if not libbpf.found()
cf2dc690 1065 conf.set10('BPF_FRAMEWORK', false)
7d861e12 1066else
76abad4d
JH
1067 clang_found = false
1068 clang_supports_bpf = false
1069 bpf_gcc_found = false
b88323e4 1070 bpftool_strip = false
76abad4d
JH
1071 deps_found = false
1072
1073 if bpf_compiler == 'clang'
1074 # Support 'versioned' clang/llvm-strip binaries, as seen on Debian/Ubuntu
1075 # (like clang-10/llvm-strip-10)
1076 if meson.is_cross_build() or cc.get_id() != 'clang' or cc.cmd_array()[0].contains('afl-clang') or cc.cmd_array()[0].contains('hfuzz-clang')
847e5585
JJ
1077 r = find_program('clang',
1078 required : bpf_framework,
1079 version : '>= 10.0.0')
76abad4d
JH
1080 clang_found = r.found()
1081 if clang_found
573c0dc1 1082 clang = r.full_path()
76abad4d 1083 endif
76abad4d
JH
1084 else
1085 clang_found = true
1086 clang = cc.cmd_array()
dc7e9c1b 1087 endif
a6ac8b5a 1088
76abad4d
JH
1089 if clang_found
1090 # Check if 'clang -target bpf' is supported.
1091 clang_supports_bpf = run_command(clang, '-target', 'bpf', '--print-supported-cpus', check : false).returncode() == 0
1092 endif
1093 elif bpf_compiler == 'gcc'
76abad4d 1094 bpf_gcc = find_program('bpf-gcc',
e4086f7d 1095 'bpf-none-gcc',
76abad4d 1096 required : true,
4a7a13b5 1097 version : '>= 13.1.0')
76abad4d 1098 bpf_gcc_found = bpf_gcc.found()
a6ac8b5a
YW
1099 endif
1100
76abad4d
JH
1101 if clang_supports_bpf or bpf_gcc_found
1102 # Debian installs this in /usr/sbin/ which is not in $PATH.
1103 # We check for 'bpftool' first, honouring $PATH, and in /usr/sbin/ for Debian.
1104 # We use 'bpftool gen object' subcommand for bpftool strip, it was added by d80b2fcbe0a023619e0fc73112f2a02c2662f6ab (v5.13).
e3759ac4
JH
1105 bpftool = find_program('bpftool',
1106 '/usr/sbin/bpftool',
847e5585
JJ
1107 required : bpf_framework.enabled() and bpf_compiler == 'gcc',
1108 version : bpf_compiler == 'gcc' ? '>= 7.0.0' : '>= 5.13.0')
e3759ac4 1109
76abad4d
JH
1110 if bpftool.found()
1111 bpftool_strip = true
1112 deps_found = true
b88323e4 1113 elif bpf_compiler == 'clang'
76abad4d
JH
1114 # We require the 'bpftool gen skeleton' subcommand, it was added by 985ead416df39d6fe8e89580cc1db6aa273e0175 (v5.6).
1115 bpftool = find_program('bpftool',
1116 '/usr/sbin/bpftool',
847e5585 1117 required : bpf_framework,
76abad4d 1118 version : '>= 5.6.0')
e3759ac4 1119 endif
68e101da 1120
76abad4d
JH
1121 # We use `llvm-strip` as a fallback if `bpftool gen object` strip support is not available.
1122 if not bpftool_strip and bpftool.found() and clang_supports_bpf
1123 if not meson.is_cross_build()
1124 llvm_strip_bin = run_command(clang, '--print-prog-name', 'llvm-strip',
1125 check : true).stdout().strip()
1126 else
1127 llvm_strip_bin = 'llvm-strip'
1128 endif
847e5585
JJ
1129 llvm_strip = find_program(llvm_strip_bin,
1130 required : bpf_framework,
1131 version : '>= 10.0.0')
76abad4d
JH
1132 deps_found = llvm_strip.found()
1133 endif
1134 endif
68e101da 1135
7d861e12 1136 # Can build BPF program from source code in restricted C
d40ce018 1137 conf.set10('BPF_FRAMEWORK', deps_found)
7d861e12
JK
1138endif
1139
5c23128d 1140libmount = dependency('mount',
c0b4b0f8 1141 version : fuzzer_build ? '>= 0' : '>= 2.30')
5c23128d 1142
9ee80846
JJ
1143libfdisk = dependency('fdisk',
1144 version : '>= 2.32',
1145 disabler : true,
1146 required : get_option('fdisk'))
1147conf.set10('HAVE_LIBFDISK', libfdisk.found())
e594a3b1 1148
1e73a64a
JJ
1149# This prefers pwquality if both are enabled or auto.
1150feature = get_option('pwquality').disable_auto_if(get_option('passwdqc').enabled())
1151libpwquality = dependency('pwquality',
1152 version : '>= 1.4.1',
1153 required : feature)
1154have = libpwquality.found()
1155if not have
1156 # libpwquality is used for both features for simplicity
1157 libpwquality = dependency('passwdqc',
1158 required : get_option('passwdqc'))
70a5db58
LP
1159endif
1160conf.set10('HAVE_PWQUALITY', have)
1e73a64a 1161conf.set10('HAVE_PASSWDQC', not have and libpwquality.found())
70a5db58 1162
43abc59a
JJ
1163libseccomp = dependency('libseccomp',
1164 version : '>= 2.3.1',
1165 required : get_option('seccomp'))
1166conf.set10('HAVE_SECCOMP', libseccomp.found())
1d8aae43 1167
43abc59a
JJ
1168libselinux = dependency('libselinux',
1169 version : '>= 2.1.9',
1170 required : get_option('selinux'))
1171conf.set10('HAVE_SELINUX', libselinux.found())
5c23128d 1172
43abc59a
JJ
1173libapparmor = dependency('libapparmor',
1174 version : '>= 2.13',
1175 required : get_option('apparmor'))
1176conf.set10('HAVE_APPARMOR', libapparmor.found())
5c23128d 1177
07b382cc
ZJS
1178have = get_option('smack') and get_option('smack-run-label') != ''
1179conf.set10('HAVE_SMACK_RUN_LABEL', have)
1180if have
1181 conf.set_quoted('SMACK_RUN_LABEL', get_option('smack-run-label'))
1182endif
5c23128d 1183
aa5ae971
ŁS
1184have = get_option('smack') and get_option('smack-default-process-label') != ''
1185if have
1186 conf.set_quoted('SMACK_DEFAULT_PROCESS_LABEL', get_option('smack-default-process-label'))
1187endif
1188
a0c9ac9a
JJ
1189feature = get_option('polkit')
1190libpolkit = dependency('polkit-gobject-1',
1191 required : feature.disabled() ? feature : false)
1192install_polkit = feature.allowed()
1193install_polkit_pkla = libpolkit.found() and libpolkit.version().version_compare('< 0.106')
1194if install_polkit_pkla
1195 message('Old polkit detected, will install pkla files')
3ca0cb73 1196endif
349cc4a5 1197conf.set10('ENABLE_POLKIT', install_polkit)
3ca0cb73 1198
43abc59a
JJ
1199libacl = dependency('libacl',
1200 required : get_option('acl'))
1201conf.set10('HAVE_ACL', libacl.found())
36f0387e 1202
43abc59a
JJ
1203libaudit = dependency('audit',
1204 required : get_option('audit'))
1205conf.set10('HAVE_AUDIT', libaudit.found())
4fcc033b 1206
43abc59a
JJ
1207libblkid = dependency('blkid',
1208 required : get_option('blkid'))
1209conf.set10('HAVE_BLKID', libblkid.found())
1210conf.set10('HAVE_BLKID_PROBE_SET_HINT',
1211 libblkid.found() and cc.has_function('blkid_probe_set_hint', dependencies : libblkid))
5c23128d 1212
43abc59a
JJ
1213libkmod = dependency('libkmod',
1214 version : '>= 15',
1215 required : get_option('kmod'))
1216conf.set10('HAVE_KMOD', libkmod.found())
5c23128d 1217
43abc59a
JJ
1218libxenctrl = dependency('xencontrol',
1219 version : '>= 4.9',
1220 required : get_option('xenctrl'))
1221conf.set10('HAVE_XENCTRL', libxenctrl.found())
2bdd7a8a 1222libxenctrl_cflags = libxenctrl.partial_dependency(includes: true, compile_args: true)
ede5a78f 1223
a0c9ac9a
JJ
1224feature = get_option('pam')
1225libpam = dependency('pam',
1226 required : feature.disabled() ? feature : false)
1227if not libpam.found()
1228 # Debian older than bookworm and Ubuntu older than 22.10 do not provide the .pc file.
1229 libpam = cc.find_library('pam', required : feature)
1230endif
1231libpam_misc = dependency('pam_misc',
1232 required : feature.disabled() ? feature : false)
1233if not libpam_misc.found()
1234 libpam_misc = cc.find_library('pam_misc', required : feature)
5c23128d 1235endif
a0c9ac9a 1236conf.set10('HAVE_PAM', libpam.found() and libpam_misc.found())
5c23128d 1237
43abc59a
JJ
1238libmicrohttpd = dependency('libmicrohttpd',
1239 version : '>= 0.9.33',
1240 required : get_option('microhttpd'))
1241conf.set10('HAVE_MICROHTTPD', libmicrohttpd.found())
5c23128d 1242
1e73a64a
JJ
1243libcryptsetup = get_option('libcryptsetup')
1244libcryptsetup_plugins = get_option('libcryptsetup-plugins')
1245if libcryptsetup_plugins.enabled()
1246 if libcryptsetup.disabled()
cee60fc3 1247 error('libcryptsetup-plugins cannot be requested without libcryptsetup')
d625f717 1248 endif
1e73a64a
JJ
1249 libcryptsetup = libcryptsetup_plugins
1250endif
1251
1252libcryptsetup = dependency('libcryptsetup',
1253 version : libcryptsetup_plugins.enabled() ? '>= 2.4.0' : '>= 2.0.1',
1254 required : libcryptsetup)
1255
1256have = libcryptsetup.found()
1257foreach ident : ['crypt_set_metadata_size',
1258 'crypt_activate_by_signed_key',
1259 'crypt_token_max',
1260 'crypt_reencrypt_init_by_passphrase',
1261 'crypt_reencrypt',
1262 'crypt_set_data_offset']
1263 have_ident = have and cc.has_function(
1264 ident,
1265 prefix : '#include <libcryptsetup.h>',
1266 dependencies : libcryptsetup)
1267 conf.set10('HAVE_' + ident.to_upper(), have_ident)
1268endforeach
349cc4a5 1269conf.set10('HAVE_LIBCRYPTSETUP', have)
5c23128d 1270
1e73a64a
JJ
1271# TODO: Use has_function(required : libcryptsetup_plugins) with meson >= 1.3.0
1272if libcryptsetup_plugins.allowed()
aac80717
ZJS
1273 have = (cc.has_function(
1274 'crypt_activate_by_token_pin',
1275 prefix : '#include <libcryptsetup.h>',
1276 dependencies : libcryptsetup) and
1277 cc.has_function(
1278 'crypt_token_external_path',
1279 prefix : '#include <libcryptsetup.h>',
1280 dependencies : libcryptsetup))
d1ae38d8
OK
1281else
1282 have = false
1283endif
1284conf.set10('HAVE_LIBCRYPTSETUP_PLUGINS', have)
1285
43abc59a
JJ
1286libcurl = dependency('libcurl',
1287 version : '>= 7.32.0',
1288 required : get_option('libcurl'))
1289conf.set10('HAVE_LIBCURL', libcurl.found())
47350c5f 1290conf.set10('CURL_NO_OLDIES', conf.get('BUILD_MODE_DEVELOPER') == 1)
5c23128d 1291
1e73a64a
JJ
1292feature = get_option('libidn2').disable_auto_if(get_option('libidn').enabled())
1293libidn = dependency('libidn2',
1294 required : feature)
1295have = libidn.found()
1296if not have
7f7ab228 1297 # libidn is used for both libidn and libidn2 objects
1b931399 1298 libidn = dependency('libidn',
1e73a64a 1299 required : get_option('libidn'))
5c23128d 1300endif
1e73a64a
JJ
1301conf.set10('HAVE_LIBIDN', not have and libidn.found())
1302conf.set10('HAVE_LIBIDN2', have)
5c23128d 1303
43abc59a
JJ
1304libiptc = dependency('libiptc',
1305 required : get_option('libiptc'))
1306conf.set10('HAVE_LIBIPTC', libiptc.found())
5b5f8f8b 1307libiptc_cflags = libiptc.partial_dependency(includes: true, compile_args: true)
5c23128d 1308
43abc59a
JJ
1309libqrencode = dependency('libqrencode',
1310 version : '>= 3',
1311 required : get_option('qrencode'))
1312conf.set10('HAVE_QRENCODE', libqrencode.found())
5c23128d 1313
a0c9ac9a
JJ
1314feature = get_option('gcrypt')
1315libgcrypt = dependency('libgcrypt',
1316 required : feature)
1317libgpg_error = dependency('gpg-error',
1318 required : feature.disabled() ? feature : false)
1319if not libgpg_error.found()
1320 # CentOS 8 does not provide the .pc file.
1321 libgpg_error = cc.find_library('gpg-error', required : feature)
349cc4a5 1322endif
a0c9ac9a
JJ
1323
1324have = libgcrypt.found() and libgpg_error.found()
349cc4a5
ZJS
1325if not have
1326 # link to neither of the libs if one is not found
a44fb601
ZJS
1327 libgcrypt = []
1328 libgpg_error = []
1329endif
349cc4a5 1330conf.set10('HAVE_GCRYPT', have)
a44fb601 1331
43abc59a
JJ
1332libgnutls = dependency('gnutls',
1333 version : '>= 3.1.4',
1334 required : get_option('gnutls'))
1335conf.set10('HAVE_GNUTLS', libgnutls.found())
5c23128d 1336
43abc59a
JJ
1337libopenssl = dependency('openssl',
1338 version : '>= 1.1.0',
1339 required : get_option('openssl'))
1340conf.set10('HAVE_OPENSSL', libopenssl.found())
096cbdce 1341
43abc59a
JJ
1342libp11kit = dependency('p11-kit-1',
1343 version : '>= 0.23.3',
1344 required : get_option('p11kit'))
1345conf.set10('HAVE_P11KIT', libp11kit.found())
1346libp11kit_cflags = libp11kit.partial_dependency(includes: true, compile_args: true)
839fddbe 1347
40e9c4e4
JJ
1348feature = get_option('libfido2').require(
1349 conf.get('HAVE_OPENSSL') == 1,
1350 error_message : 'openssl required')
1351libfido2 = dependency('libfido2',
1352 required : feature)
1353conf.set10('HAVE_LIBFIDO2', libfido2.found())
af4fbd46 1354
43abc59a
JJ
1355tpm2 = dependency('tss2-esys tss2-rc tss2-mu tss2-tcti-device',
1356 required : get_option('tpm2'))
1357conf.set10('HAVE_TPM2', tpm2.found())
1358conf.set10('HAVE_TSS2_ESYS3', tpm2.found() and tpm2.version().version_compare('>= 3.0.0'))
5e521624 1359
43abc59a
JJ
1360libdw = dependency('libdw',
1361 required : get_option('elfutils'))
1362conf.set10('HAVE_ELFUTILS', libdw.found())
1363# New in elfutils 0.177
1364conf.set10('HAVE_DWELF_ELF_E_MACHINE_STRING',
1365 libdw.found() and cc.has_function('dwelf_elf_e_machine_string', dependencies : libdw))
d48c2721 1366
43abc59a
JJ
1367libz = dependency('zlib',
1368 required : get_option('zlib'))
1369conf.set10('HAVE_ZLIB', libz.found())
5c23128d 1370
a0c9ac9a
JJ
1371feature = get_option('bzip2')
1372libbzip2 = dependency('bzip2',
1373 required : feature.disabled() ? feature : false)
1374if not libbzip2.found()
1375 # Debian and Ubuntu do not provide the .pc file.
1376 libbzip2 = cc.find_library('bz2', required : feature)
5c23128d 1377endif
a0c9ac9a 1378conf.set10('HAVE_BZIP2', libbzip2.found())
5c23128d 1379
43abc59a
JJ
1380libxz = dependency('liblzma',
1381 required : get_option('xz'))
1382conf.set10('HAVE_XZ', libxz.found())
5c23128d 1383
43abc59a
JJ
1384liblz4 = dependency('liblz4',
1385 version : '>= 1.3.0',
1386 required : get_option('lz4'))
1387conf.set10('HAVE_LZ4', liblz4.found())
5c23128d 1388
43abc59a
JJ
1389libzstd = dependency('libzstd',
1390 version : '>= 1.4.0',
1391 required : get_option('zstd'))
1392conf.set10('HAVE_ZSTD', libzstd.found())
d80b051c 1393
43abc59a 1394conf.set10('HAVE_COMPRESSION', libxz.found() or liblz4.found() or libzstd.found())
ef5924aa 1395
cd3c6322
LB
1396compression = get_option('default-compression')
1397if compression == 'auto'
43abc59a 1398 if libzstd.found()
cd3c6322 1399 compression = 'zstd'
43abc59a 1400 elif liblz4.found()
cd3c6322 1401 compression = 'lz4'
43abc59a 1402 elif libxz.found()
cd3c6322
LB
1403 compression = 'xz'
1404 else
1405 compression = 'none'
1406 endif
43abc59a 1407elif compression == 'zstd' and not libzstd.found()
cd3c6322 1408 error('default-compression=zstd requires zstd')
43abc59a 1409elif compression == 'lz4' and not liblz4.found()
cd3c6322 1410 error('default-compression=lz4 requires lz4')
43abc59a 1411elif compression == 'xz' and not libxz.found()
cd3c6322
LB
1412 error('default-compression=xz requires xz')
1413endif
1788c6f3 1414conf.set('DEFAULT_COMPRESSION', 'COMPRESSION_@0@'.format(compression.to_upper()))
cd3c6322 1415
b68f4cad
LP
1416libarchive = dependency('libarchive',
1417 version : '>= 3.0',
1418 required : get_option('libarchive'))
1419conf.set10('HAVE_LIBARCHIVE', libarchive.found())
1420
43abc59a
JJ
1421libxkbcommon = dependency('xkbcommon',
1422 version : '>= 0.3.0',
1423 required : get_option('xkbcommon'))
1424conf.set10('HAVE_XKBCOMMON', libxkbcommon.found())
a44fb601 1425
43abc59a
JJ
1426libpcre2 = dependency('libpcre2-8',
1427 required : get_option('pcre2'))
1428conf.set10('HAVE_PCRE2', libpcre2.found())
69e96427 1429
43abc59a
JJ
1430libglib = dependency('glib-2.0',
1431 version : '>= 2.22.0',
1432 required : get_option('glib'))
1433libgobject = dependency('gobject-2.0',
1434 version : '>= 2.22.0',
1435 required : get_option('glib'))
1436libgio = dependency('gio-2.0',
1437 required : get_option('glib'))
1438conf.set10('HAVE_GLIB', libglib.found() and libgobject.found() and libgio.found())
69e96427 1439
101b5943
JJ
1440libdbus = dependency('dbus-1',
1441 version : '>= 1.3.2',
1442 required : get_option('dbus'))
1443conf.set10('HAVE_DBUS', libdbus.found())
69e96427 1444
101b5943 1445dbusdatadir = libdbus.get_variable(pkgconfig: 'datadir', default_value: datadir) / 'dbus-1'
1bd0cc45
YW
1446
1447dbuspolicydir = get_option('dbuspolicydir')
1448if dbuspolicydir == ''
1449 dbuspolicydir = dbusdatadir / 'system.d'
1450endif
1451
1452dbussessionservicedir = get_option('dbussessionservicedir')
1453if dbussessionservicedir == ''
101b5943 1454 dbussessionservicedir = libdbus.get_variable(pkgconfig: 'session_bus_services_dir', default_value: dbusdatadir / 'services')
1bd0cc45
YW
1455endif
1456
1457dbussystemservicedir = get_option('dbussystemservicedir')
1458if dbussystemservicedir == ''
101b5943 1459 dbussystemservicedir = libdbus.get_variable(pkgconfig: 'system_bus_services_dir', default_value: dbusdatadir / 'system-services')
1bd0cc45
YW
1460endif
1461
1462dbus_interfaces_dir = get_option('dbus-interfaces-dir')
1463if dbus_interfaces_dir == '' or dbus_interfaces_dir == 'yes'
1464 if meson.is_cross_build() and dbus_interfaces_dir != 'yes'
1465 dbus_interfaces_dir = 'no'
1466 warning('Exporting D-Bus interface XML files is disabled during cross build. Pass path or "yes" to force enable.')
1467 else
101b5943 1468 dbus_interfaces_dir = libdbus.get_variable(pkgconfig: 'interfaces_dir', default_value: dbusdatadir / 'interfaces')
1bd0cc45
YW
1469 endif
1470endif
1bd0cc45 1471
12b4cffd
YW
1472dmi_arches = ['x86', 'x86_64', 'aarch64', 'arm', 'ia64', 'loongarch64', 'mips']
1473conf.set10('HAVE_DMI', host_machine.cpu_family() in dmi_arches)
1474
e37ad765
ZJS
1475# We support one or the other. If gcrypt is available, we assume it's there to
1476# be used, and use it in preference.
1477opt = get_option('cryptolib')
1478if opt == 'openssl' and conf.get('HAVE_OPENSSL') == 0
1479 error('openssl requested as the default cryptolib, but not available')
1480endif
1481conf.set10('PREFER_OPENSSL',
1482 opt == 'openssl' or (opt == 'auto' and conf.get('HAVE_OPENSSL') == 1 and conf.get('HAVE_GCRYPT') == 0))
1483conf.set10('HAVE_OPENSSL_OR_GCRYPT',
1484 conf.get('HAVE_OPENSSL') == 1 or conf.get('HAVE_GCRYPT') == 1)
9bcf483b 1485lib_openssl_or_gcrypt = conf.get('PREFER_OPENSSL') == 1 ? [libopenssl] : [libgcrypt, libgpg_error]
42303dcb 1486
56ddbf10
YW
1487dns_over_tls = get_option('dns-over-tls')
1488if dns_over_tls != 'false'
e37ad765
ZJS
1489 if dns_over_tls == 'gnutls' and conf.get('PREFER_OPENSSL') == 1
1490 error('Sorry, -Ddns-over-tls=gnutls is not supported when openssl is used as the cryptolib')
1491 endif
1492
1f9aa3d2
LB
1493 if dns_over_tls == 'gnutls'
1494 have_openssl = false
096cbdce 1495 else
1f9aa3d2
LB
1496 have_openssl = conf.get('HAVE_OPENSSL') == 1
1497 if dns_over_tls == 'openssl' and not have_openssl
1498 error('DNS-over-TLS support was requested with openssl, but dependencies are not available')
096cbdce 1499 endif
56ddbf10 1500 endif
1f9aa3d2
LB
1501 if dns_over_tls == 'openssl' or have_openssl
1502 have_gnutls = false
096cbdce 1503 else
1f9aa3d2
LB
1504 have_gnutls = conf.get('HAVE_GNUTLS') == 1 and libgnutls.version().version_compare('>= 3.6.0')
1505 if dns_over_tls != 'auto' and not have_gnutls
1506 str = dns_over_tls == 'gnutls' ? ' with gnutls' : ''
b349bc59 1507 error('DNS-over-TLS support was requested@0@, but dependencies are not available'.format(str))
096cbdce
IT
1508 endif
1509 endif
1510 have = have_gnutls or have_openssl
56ddbf10 1511else
be5536a6
MO
1512 have = false
1513 have_gnutls = false
1514 have_openssl = false
56ddbf10
YW
1515endif
1516conf.set10('ENABLE_DNS_OVER_TLS', have)
096cbdce
IT
1517conf.set10('DNS_OVER_TLS_USE_GNUTLS', have_gnutls)
1518conf.set10('DNS_OVER_TLS_USE_OPENSSL', have_openssl)
56ddbf10 1519
c9299be2 1520default_dns_over_tls = get_option('default-dns-over-tls')
56ddbf10 1521if default_dns_over_tls != 'no' and conf.get('ENABLE_DNS_OVER_TLS') == 0
4310bfc2 1522 message('default-dns-over-tls cannot be enabled or set to opportunistic when DNS-over-TLS support is disabled. Setting default-dns-over-tls to no.')
c9299be2 1523 default_dns_over_tls = 'no'
5d67a7ae 1524endif
c9299be2
IT
1525conf.set('DEFAULT_DNS_OVER_TLS_MODE',
1526 'DNS_OVER_TLS_' + default_dns_over_tls.underscorify().to_upper())
411d1f4c 1527conf.set_quoted('DEFAULT_DNS_OVER_TLS_MODE_STR', default_dns_over_tls)
5d67a7ae 1528
3614df05
ZJS
1529default_mdns = get_option('default-mdns')
1530conf.set('DEFAULT_MDNS_MODE',
1531 'RESOLVE_SUPPORT_' + default_mdns.to_upper())
411d1f4c 1532conf.set_quoted('DEFAULT_MDNS_MODE_STR', default_mdns)
3614df05
ZJS
1533
1534default_llmnr = get_option('default-llmnr')
1535conf.set('DEFAULT_LLMNR_MODE',
1536 'RESOLVE_SUPPORT_' + default_llmnr.to_upper())
411d1f4c 1537conf.set_quoted('DEFAULT_LLMNR_MODE_STR', default_llmnr)
3614df05 1538
40e9c4e4
JJ
1539have = get_option('repart').require(
1540 conf.get('HAVE_LIBFDISK') == 1,
1541 error_message : 'fdisk required').allowed()
e594a3b1
LP
1542conf.set10('ENABLE_REPART', have)
1543
7e8facb3 1544default_dnssec = get_option('default-dnssec')
7e8facb3
ZJS
1545if default_dnssec != 'no' and conf.get('HAVE_OPENSSL_OR_GCRYPT') == 0
1546 message('default-dnssec cannot be set to yes or allow-downgrade openssl and gcrypt are disabled. Setting default-dnssec to no.')
1547 default_dnssec = 'no'
1548endif
1549conf.set('DEFAULT_DNSSEC_MODE',
1550 'DNSSEC_' + default_dnssec.underscorify().to_upper())
1551conf.set_quoted('DEFAULT_DNSSEC_MODE_STR', default_dnssec)
1552
40e9c4e4
JJ
1553have = get_option('sysupdate').require(
1554 conf.get('HAVE_OPENSSL') == 1 and
1555 conf.get('HAVE_LIBFDISK') == 1,
1556 error_message : 'fdisk and openssl required').allowed()
43cc7a3e
LP
1557conf.set10('ENABLE_SYSUPDATE', have)
1558
1761066b
LP
1559conf.set10('ENABLE_STORAGETM', get_option('storagetm'))
1560
40e9c4e4
JJ
1561have = get_option('importd').require(
1562 conf.get('HAVE_LIBCURL') == 1 and
1563 conf.get('HAVE_OPENSSL_OR_GCRYPT') == 1 and
1564 conf.get('HAVE_ZLIB') == 1 and
1565 conf.get('HAVE_XZ') == 1,
1566 error_message : 'curl, openssl/grypt, zlib and xz required').allowed()
349cc4a5 1567conf.set10('ENABLE_IMPORTD', have)
5c23128d 1568
40e9c4e4
JJ
1569have = get_option('homed').require(
1570 conf.get('HAVE_OPENSSL') == 1 and
1571 conf.get('HAVE_LIBFDISK') == 1 and
1572 conf.get('HAVE_LIBCRYPTSETUP') == 1,
1573 error_message : 'openssl, fdisk and libcryptsetup required').allowed()
70a5db58
LP
1574conf.set10('ENABLE_HOMED', have)
1575
af06ddf5
YW
1576have = have and conf.get('HAVE_PAM') == 1
1577conf.set10('ENABLE_PAM_HOME', have)
1578
1e73a64a
JJ
1579feature = get_option('remote')
1580have_deps = [conf.get('HAVE_MICROHTTPD') == 1,
1581 conf.get('HAVE_LIBCURL') == 1]
1582# sd-j-remote requires µhttpd, and sd-j-upload requires libcurl, so
1583# it's possible to build one without the other. Complain only if
1584# support was explicitly requested. The auxiliary files like sysusers
1585# config should be installed when any of the programs are built.
1586if feature.enabled() and not (have_deps[0] and have_deps[1])
1587 error('remote support was requested, but dependencies are not available')
1588endif
1589have = feature.allowed() and (have_deps[0] or have_deps[1])
349cc4a5 1590conf.set10('ENABLE_REMOTE', have)
5c23128d 1591
2b84d628
ZJS
1592feature = get_option('vmspawn').disable_auto_if(conf.get('BUILD_MODE_DEVELOPER') == 0)
1593conf.set10('ENABLE_VMSPAWN', feature.allowed())
1594
b3259a6e
ZJS
1595foreach term : ['analyze',
1596 'backlight',
a9149d87 1597 'binfmt',
dfca5587 1598 'compat-mutable-uid-boundaries',
a9149d87 1599 'coredump',
b3259a6e
ZJS
1600 'efi',
1601 'environment-d',
1602 'firstboot',
1603 'gshadow',
1604 'hibernate',
a9149d87 1605 'hostnamed',
b3259a6e
ZJS
1606 'hwdb',
1607 'idn',
1608 'ima',
1609 'initrd',
1782534b 1610 'kernel-install',
b3259a6e 1611 'ldconfig',
a9149d87 1612 'localed',
b3259a6e 1613 'logind',
a9149d87
ZJS
1614 'machined',
1615 'networkd',
dfca5587 1616 'nscd',
b3259a6e
ZJS
1617 'nss-myhostname',
1618 'nss-systemd',
1782534b 1619 'oomd',
b3259a6e
ZJS
1620 'portabled',
1621 'pstore',
a9149d87 1622 'quotacheck',
b3259a6e
ZJS
1623 'randomseed',
1624 'resolve',
1625 'rfkill',
1626 'smack',
dfca5587 1627 'sysext',
a9149d87 1628 'sysusers',
b3259a6e
ZJS
1629 'timedated',
1630 'timesyncd',
a9149d87 1631 'tmpfiles',
a9149d87 1632 'tpm',
b3259a6e
ZJS
1633 'userdb',
1634 'utmp',
1635 'vconsole',
1636 'xdg-autostart']
a9149d87
ZJS
1637 have = get_option(term)
1638 name = 'ENABLE_' + term.underscorify().to_upper()
1639 conf.set10(name, have)
5c23128d
ZJS
1640endforeach
1641
bd7e6aa7
ZJS
1642enable_sysusers = conf.get('ENABLE_SYSUSERS') == 1
1643
08540a95
YW
1644foreach tuple : [['nss-mymachines', 'machined'],
1645 ['nss-resolve', 'resolve']]
1646 want = get_option(tuple[0])
1e73a64a 1647 if want.allowed()
08540a95 1648 have = get_option(tuple[1])
1e73a64a 1649 if want.enabled() and not have
08540a95
YW
1650 error('@0@ is requested but @1@ is disabled'.format(tuple[0], tuple[1]))
1651 endif
1652 else
1653 have = false
1654 endif
1655 name = 'ENABLE_' + tuple[0].underscorify().to_upper()
1656 conf.set10(name, have)
1657endforeach
1658
1659enable_nss = false
1660foreach term : ['ENABLE_NSS_MYHOSTNAME',
1661 'ENABLE_NSS_MYMACHINES',
1662 'ENABLE_NSS_RESOLVE',
1663 'ENABLE_NSS_SYSTEMD']
1664 if conf.get(term) == 1
1665 enable_nss = true
1666 endif
1667endforeach
1668conf.set10('ENABLE_NSS', enable_nss)
1669
348b4437 1670conf.set10('ENABLE_TIMEDATECTL', get_option('timedated') or get_option('timesyncd'))
6129ec85 1671
62670a77
FS
1672conf.set10('ENABLE_SSH_PROXY_CONFIG', sshconfdir != 'no')
1673conf.set10('ENABLE_SSH_USERDB_CONFIG', conf.get('ENABLE_USERDB') == 1 and sshdconfdir != 'no')
1674
b68dfb9e 1675conf.set10('SYSTEMD_SLOW_TESTS_DEFAULT', slow_tests)
00d82c81 1676
e6267e83 1677#####################################################################
db7f5ab6 1678
9c45bfb2
FS
1679pymod = import('python')
1680python = pymod.find_installation('python3', required : true, modules : ['jinja2'])
1681python_39 = python.language_version().version_compare('>=3.9')
1682
e6267e83 1683#####################################################################
4d3ef2d1
LP
1684
1685if conf.get('BPF_FRAMEWORK') == 1
1686 bpf_clang_flags = [
1687 '-std=gnu11',
1688 '-Wno-compare-distinct-pointer-types',
1689 '-fno-stack-protector',
1690 '-O2',
1691 '-target',
1692 'bpf',
1693 '-g',
1694 '-c',
1695 ]
1696
1697 bpf_gcc_flags = [
1698 '-std=gnu11',
1699 '-fno-stack-protector',
1700 '-O2',
1701 '-mkernel=5.2',
1702 '-mcpu=v3',
1703 '-mco-re',
1704 '-gbtf',
1705 '-c',
1706 ]
1707
1708 # Generate defines that are appropriate to tell the compiler what architecture
1709 # we're compiling for. By default we just map meson's cpu_family to __<cpu_family>__.
1710 # This dictionary contains the exceptions where this doesn't work.
1711 #
1712 # C.f. https://mesonbuild.com/Reference-tables.html#cpu-families
1713 # and src/basic/missing_syscall_def.h.
1714 cpu_arch_defines = {
1715 'ppc' : ['-D__powerpc__'],
1716 'ppc64' : ['-D__powerpc64__', '-D_CALL_ELF=2'],
1717 'riscv32' : ['-D__riscv', '-D__riscv_xlen=32'],
1718 'riscv64' : ['-D__riscv', '-D__riscv_xlen=64'],
1719 'x86' : ['-D__i386__'],
1720
1721 # For arm, assume hardware fp is available.
1722 'arm' : ['-D__arm__', '-D__ARM_PCS_VFP'],
1723 }
1724
1725 bpf_arch_flags = cpu_arch_defines.get(host_machine.cpu_family(),
1726 ['-D__@0@__'.format(host_machine.cpu_family())])
1727 if bpf_compiler == 'gcc'
1728 bpf_arch_flags += ['-m' + host_machine.endian() + '-endian']
1729 endif
1730
1731 libbpf_include_dir = libbpf.get_variable(pkgconfig : 'includedir')
1732
1733 bpf_o_unstripped_cmd = []
1734 if bpf_compiler == 'clang'
1735 bpf_o_unstripped_cmd += [
1736 clang,
1737 bpf_clang_flags,
1738 bpf_arch_flags,
1739 ]
1740 elif bpf_compiler == 'gcc'
1741 bpf_o_unstripped_cmd += [
1742 bpf_gcc,
1743 bpf_gcc_flags,
1744 bpf_arch_flags,
1745 ]
1746 endif
1747
1748 bpf_o_unstripped_cmd += ['-I.']
1749
1750 if not meson.is_cross_build() and bpf_compiler == 'clang'
1751 target_triplet_cmd = run_command('gcc', '-dumpmachine', check: false)
1752 if target_triplet_cmd.returncode() == 0
1753 target_triplet = target_triplet_cmd.stdout().strip()
1754 bpf_o_unstripped_cmd += [
1755 '-isystem',
1756 '/usr/include/@0@'.format(target_triplet)
1757 ]
1758 endif
1759 endif
1760
1761 bpf_o_unstripped_cmd += [
1762 '-idirafter',
1763 libbpf_include_dir,
1764 '@INPUT@',
1765 '-o',
1766 '@OUTPUT@'
1767 ]
1768
1769 if bpftool_strip
1770 bpf_o_cmd = [
1771 bpftool,
1772 'gen',
1773 'object',
1774 '@OUTPUT@',
1775 '@INPUT@'
1776 ]
1777 elif bpf_compiler == 'clang'
1778 bpf_o_cmd = [
1779 llvm_strip,
1780 '-g',
1781 '@INPUT@',
1782 '-o',
1783 '@OUTPUT@'
1784 ]
1785 endif
1786
1787 skel_h_cmd = [
1788 bpftool,
1789 'gen',
1790 'skeleton',
1791 '@INPUT@'
1792 ]
1793endif
1794
dfca5587
JJ
1795#####################################################################
1796
1797efi_arch = {
31ffb6b1
JJ
1798 'aarch64' : 'aa64',
1799 'arm' : 'arm',
1800 'loongarch32' : 'loongarch32',
1801 'loongarch64' : 'loongarch64',
1802 'riscv32' : 'riscv32',
1803 'riscv64' : 'riscv64',
1804 'x86_64' : 'x64',
1805 'x86' : 'ia32',
dfca5587
JJ
1806}.get(host_machine.cpu_family(), '')
1807
40e9c4e4
JJ
1808pyelftools = pymod.find_installation('python3',
1809 required : get_option('bootloader'),
1810 modules : ['elftools'])
1811
1812have = get_option('bootloader').require(
1813 pyelftools.found() and get_option('efi') and efi_arch != '',
1814 error_message : 'unsupported EFI arch or EFI support is disabled').allowed()
1815conf.set10('ENABLE_BOOTLOADER', have)
1816conf.set_quoted('EFI_MACHINE_TYPE_NAME', have ? efi_arch : '')
2afeaf16
JJ
1817
1818efi_arch_alt = ''
7ea44f17 1819efi_cpu_family_alt = ''
40e9c4e4 1820if have and efi_arch == 'x64' and cc.links('''
2afeaf16
JJ
1821 #include <limits.h>
1822 int main(int argc, char *argv[]) {
1823 return __builtin_popcount(argc - CHAR_MAX);
1824 }''', args : ['-m32', '-march=i686'], name : '32bit build possible')
1825 efi_arch_alt = 'ia32'
7ea44f17 1826 efi_cpu_family_alt = 'x86'
2afeaf16
JJ
1827endif
1828
85915f31
LB
1829pefile = pymod.find_installation('python3', required: false, modules : ['pefile'])
1830
1831want_ukify = get_option('ukify').require(python_39 and (want_tests != 'true' or pefile.found()), error_message : 'Python >= 3.9 and pefile required').allowed()
9c45bfb2
FS
1832conf.set10('ENABLE_UKIFY', want_ukify)
1833
e6267e83 1834#####################################################################
b0bd2ae8 1835
3691e7fc 1836check_version_history_py = find_program('tools/check-version-history.py')
2afeaf16
JJ
1837elf2efi_py = find_program('tools/elf2efi.py')
1838export_dbus_interfaces_py = find_program('tools/dbus_exporter.py')
d3821a33 1839generate_gperfs = find_program('tools/generate-gperfs.py')
f6fe732f
YW
1840make_autosuspend_rules_py = find_program('tools/make-autosuspend-rules.py')
1841make_directive_index_py = find_program('tools/make-directive-index.py')
3c1f396f 1842sync_docs_py = find_program('tools/sync-docs.py')
f6fe732f 1843make_man_index_py = find_program('tools/make-man-index.py')
6b1aac3c 1844meson_render_jinja2 = find_program('tools/meson-render-jinja2.py')
d3821a33 1845update_dbus_docs_py = find_program('tools/update-dbus-docs.py')
d3821a33 1846update_hwdb_autosuspend_sh = find_program('tools/update-hwdb-autosuspend.sh')
2afeaf16
JJ
1847update_hwdb_sh = find_program('tools/update-hwdb.sh')
1848update_man_rules_py = find_program('tools/update-man-rules.py')
d3821a33
ZJS
1849update_syscall_tables_sh = find_program('tools/update-syscall-tables.sh')
1850xml_helper_py = find_program('tools/xml_helper.py')
f6fe732f 1851
e6267e83 1852#####################################################################
5c23128d 1853
e95acdfe 1854version_tag = get_option('version-tag')
1671799b
ZJS
1855version_h = vcs_tag(
1856 input : 'src/version/version.h.in',
1857 output : 'version.h',
1a71ac07 1858 command: [project_source_root / 'tools/meson-vcs-tag.sh',
1671799b 1859 project_source_root,
1a71ac07
ZJS
1860 meson.project_version(),
1861 version_tag,
1671799b 1862 ])
e95acdfe 1863
e95acdfe
YW
1864shared_lib_tag = get_option('shared-lib-tag')
1865if shared_lib_tag == ''
1866 shared_lib_tag = meson.project_version()
1867endif
1868
e6267e83 1869#####################################################################
e95acdfe 1870
7e43be7d 1871if get_option('b_coverage')
92148283 1872 userspace_c_args += ['-include', 'src/basic/coverage.h']
7e43be7d
FS
1873endif
1874
e6267e83 1875#####################################################################
7e43be7d 1876
5c23128d 1877config_h = configure_file(
37efbbd8
ZJS
1878 output : 'config.h',
1879 configuration : conf)
5c23128d 1880
92148283 1881userspace_c_args += ['-include', 'config.h']
f6fe732f 1882
8f04a1ca
ZJS
1883jinja2_cmdline = [meson_render_jinja2, config_h, version_h]
1884
92148283
JJ
1885userspace = declare_dependency(
1886 compile_args : userspace_c_args,
1887 link_args : userspace_c_ld_args,
56a0b906 1888 sources : version_h,
92148283
JJ
1889)
1890
c18dde32
ZJS
1891man_page_depends = []
1892
e6267e83 1893#####################################################################
348b4437 1894
1d21a7bd 1895simple_tests = []
130c87b1 1896libsystemd_tests = []
1d21a7bd
YW
1897simple_fuzzers = []
1898catalogs = []
c335921e
YW
1899modules = [] # nss, pam, and other plugins
1900executables = []
1901executables_by_name = {}
cbc55c4c 1902fuzzer_exes = []
1d21a7bd 1903
b61016f2
YW
1904# binaries that have --help and are intended for use by humans,
1905# usually, but not always, installed in /bin.
1906public_programs = []
1907
e3c68924 1908# D-Bus introspection XML export
1909dbus_programs = []
e3c68924 1910
3f80c139
ZJS
1911# A list of boot stubs. Required for testing of ukify.
1912boot_stubs = []
1913
3c1eee5b
ZJS
1914build_dir_include = include_directories('.')
1915
8d40961c
YW
1916basic_includes = include_directories(
1917 'src/basic',
e5bc5f1f 1918 'src/fundamental',
8d40961c
YW
1919 'src/systemd',
1920 '.')
1921
1922libsystemd_includes = [basic_includes, include_directories(
1923 'src/libsystemd/sd-bus',
1924 'src/libsystemd/sd-device',
1925 'src/libsystemd/sd-event',
1926 'src/libsystemd/sd-hwdb',
1927 'src/libsystemd/sd-id128',
1928 'src/libsystemd/sd-journal',
1929 'src/libsystemd/sd-netlink',
1930 'src/libsystemd/sd-network',
1931 'src/libsystemd/sd-resolve')]
1932
1933includes = [libsystemd_includes, include_directories('src/shared')]
5c23128d 1934
5c23128d
ZJS
1935subdir('po')
1936subdir('catalog')
dfca5587 1937subdir('src/fundamental')
5c23128d
ZJS
1938subdir('src/basic')
1939subdir('src/libsystemd')
3976f372 1940subdir('src/shared')
3976f372 1941subdir('src/libudev')
5c23128d 1942
5c23128d 1943libsystemd = shared_library(
37efbbd8 1944 'systemd',
56d50ab1 1945 version : libsystemd_version,
8d40961c 1946 include_directories : libsystemd_includes,
37efbbd8
ZJS
1947 link_args : ['-shared',
1948 '-Wl,--version-script=' + libsystemd_sym_path],
34e221a5 1949 link_with : [libbasic,
acc50c92
LP
1950 libbasic_gcrypt,
1951 libbasic_compress],
99b9f8fd 1952 link_whole : [libsystemd_static],
92148283
JJ
1953 dependencies : [librt,
1954 threads,
1955 userspace],
37efbbd8
ZJS
1956 link_depends : libsystemd_sym,
1957 install : true,
0a5e638c 1958 install_tag: 'libsystemd',
b0d3095f 1959 install_dir : libdir)
5c23128d 1960
039f1673
LB
1961alias_target('libsystemd', libsystemd)
1962
70848ecf
DC
1963install_libsystemd_static = static_library(
1964 'systemd',
1965 libsystemd_sources,
975464e0
ZJS
1966 basic_sources,
1967 basic_gcrypt_sources,
acc50c92 1968 basic_compress_sources,
e5bc5f1f 1969 fundamental_sources,
8d40961c 1970 include_directories : libsystemd_includes,
70848ecf
DC
1971 build_by_default : static_libsystemd != 'false',
1972 install : static_libsystemd != 'false',
0a5e638c 1973 install_tag: 'libsystemd',
b0d3095f 1974 install_dir : libdir,
40dbce36 1975 pic : static_libsystemd_pic,
92148283 1976 dependencies : [libblkid,
975464e0 1977 libcap,
92148283 1978 libdl,
011d129c 1979 libgcrypt,
92148283
JJ
1980 liblz4,
1981 libmount,
c47511da 1982 libopenssl,
92148283
JJ
1983 librt,
1984 libxz,
1985 libzstd,
1986 threads,
40c7d3c7 1987 userspace],
70848ecf
DC
1988 c_args : libsystemd_c_args + (static_libsystemd_pic ? [] : ['-fno-PIC']))
1989
3976f372
YW
1990libudev = shared_library(
1991 'udev',
3976f372
YW
1992 version : libudev_version,
1993 include_directories : includes,
1994 link_args : ['-shared',
1995 '-Wl,--version-script=' + libudev_sym_path],
1996 link_with : [libsystemd_static, libshared_static],
1997 link_whole : libudev_basic,
92148283
JJ
1998 dependencies : [threads,
1999 userspace],
3976f372
YW
2000 link_depends : libudev_sym,
2001 install : true,
0a5e638c 2002 install_tag: 'libudev',
b0d3095f 2003 install_dir : libdir)
3976f372 2004
039f1673
LB
2005alias_target('libudev', libudev)
2006
3976f372
YW
2007install_libudev_static = static_library(
2008 'udev',
2009 basic_sources,
e5bc5f1f 2010 fundamental_sources,
3976f372
YW
2011 shared_sources,
2012 libsystemd_sources,
2013 libudev_sources,
3976f372
YW
2014 include_directories : includes,
2015 build_by_default : static_libudev != 'false',
2016 install : static_libudev != 'false',
0a5e638c 2017 install_tag: 'libudev',
b0d3095f 2018 install_dir : libdir,
3976f372 2019 link_depends : libudev_sym,
92148283
JJ
2020 dependencies : [libmount,
2021 libshared_deps,
40c7d3c7 2022 userspace],
3976f372
YW
2023 c_args : static_libudev_pic ? [] : ['-fno-PIC'],
2024 pic : static_libudev_pic)
2025
e6267e83 2026#####################################################################
47354b44 2027
130c87b1
YW
2028runtest_env = custom_target(
2029 'systemd-runtest.env',
2030 output : 'systemd-runtest.env',
2031 command : [sh, '-c',
2032 '{ echo SYSTEMD_TEST_DATA=@0@; echo SYSTEMD_CATALOG_DIR=@1@; } >@OUTPUT@'.format(
2033 project_source_root / 'test',
2034 project_build_root / 'catalog')],
2035 depends : catalogs,
2036 build_by_default : true)
2037
2038test_cflags = ['-DTEST_CODE=1']
2039# We intentionally do not do inline initializations with definitions for a
2040# bunch of _cleanup_ variables in tests, to ensure valgrind is triggered if we
2041# use the variable unexpectedly. This triggers a lot of maybe-uninitialized
2042# false positives when the combination of -O2 and -flto is used. Suppress them.
2043if '-O2' in c_args and '-flto=auto' in c_args
2044 test_cflags += cc.first_supported_argument('-Wno-maybe-uninitialized')
2045endif
2046
e6267e83 2047#####################################################################
130c87b1 2048
c335921e
YW
2049executable_template = {
2050 'include_directories' : includes,
2051 'link_with' : libshared,
2052 'install_rpath' : pkglibdir,
2053 'install' : true,
2054}
2055
2056generator_template = executable_template + {
2057 'install_dir' : systemgeneratordir,
2058}
2059
2060libexec_template = executable_template + {
2061 'install_dir' : libexecdir,
2062}
2063
2064executable_additional_kwargs = {
2065 'dependencies' : userspace,
2066}
2067
130c87b1
YW
2068test_template = executable_template + {
2069 'build_by_default' : want_tests != 'false',
2070 'install' : install_tests,
2071 'install_dir' : unittestsdir,
2072}
2073
2074test_additional_kwargs = {
2075 'c_args' : test_cflags,
2076 'link_depends' : runtest_env,
2077}
2078
cbc55c4c
YW
2079fuzz_template = executable_template + {
2080 'build_by_default' : fuzzer_build,
2081 'install' : false,
2082}
2083
2084if want_ossfuzz or (want_libfuzzer and fuzzing_engine.found())
2085 fuzz_additional_kwargs = {
2086 'dependencies' : fuzzing_engine,
2087 }
2088elif want_libfuzzer and not fuzzing_engine.found()
2089 fuzz_additional_kwargs = {
2090 'link_args' : ['-fsanitize=fuzzer'],
2091 }
2092else
2093 fuzz_additional_kwargs = {
2094 'sources' : files('src/fuzz/fuzz-main.c'),
2095 }
2096endif
2097fuzz_additional_kwargs += {
2098 'include_directories' : include_directories('src/fuzz'),
2099 'c_args' : test_cflags,
2100}
2101
c335921e
YW
2102nss_template = {
2103 'version' : '2',
2104 'include_directories' : includes,
2105 # Note that we link NSS modules with '-z nodelete' so that mempools never get orphaned
2106 'link_args' : ['-z', 'nodelete'],
2107 'link_with' : [
2108 libsystemd_static,
2109 libshared_static,
2110 libbasic,
2111 ],
2112 'dependencies' : [
2113 librt,
2114 threads,
2115 ],
2116 'install' : true,
2117 'install_tag' : 'nss',
2118 'install_dir' : libdir,
2119}
2120
2121pam_template = {
2122 'name_prefix' : '',
2123 'include_directories' : includes,
2124 'link_with' : [
2125 libsystemd_static,
2126 libshared_static,
2127 ],
2128 'dependencies' : [
2129 libpam_misc,
2130 libpam,
2131 threads,
2132 ],
2133 'install' : true,
2134 'install_tag' : 'pam',
2135 'install_dir' : pamlibdir,
2136}
2137
2138module_additional_kwargs = {
2139 'link_args' : ['-shared'],
2140 'dependencies' : userspace,
2141}
2142
e6267e83 2143#####################################################################
c335921e 2144
b61016f2 2145# systemd-analyze requires 'libcore'
83b6af36 2146subdir('src/core')
b61016f2
YW
2147# systemd-networkd requires 'libsystemd_network'
2148subdir('src/libsystemd-network')
5371c269
YW
2149# hwdb requires 'udev_link_with' and 'udev_rpath'
2150subdir('src/udev')
83b6af36 2151
16b081d6 2152subdir('src/ac-power')
83b6af36 2153subdir('src/analyze')
cb935625 2154subdir('src/ask-password')
7e6ca26f 2155subdir('src/backlight')
98e39a55 2156subdir('src/battery-check')
2c2c3daa 2157subdir('src/binfmt')
cd4300f3 2158subdir('src/boot')
dfca5587 2159subdir('src/boot/efi')
f98df767 2160subdir('src/busctl')
9f907d30 2161subdir('src/cgls')
e2bdf00a 2162subdir('src/cgroups-agent')
9f907d30 2163subdir('src/cgtop')
b61016f2 2164subdir('src/coredump')
98e39a55 2165subdir('src/creds')
2ad279cf 2166subdir('src/cryptenroll')
b4d1892a 2167subdir('src/cryptsetup')
2a456620 2168subdir('src/debug-generator')
98e39a55 2169subdir('src/delta')
16b081d6 2170subdir('src/detect-virt')
ec57a4ea 2171subdir('src/dissect')
2a456620 2172subdir('src/environment-d-generator')
98e39a55 2173subdir('src/escape')
df490fc7
YW
2174subdir('src/firstboot')
2175subdir('src/fsck')
2a456620
YW
2176subdir('src/fstab-generator')
2177subdir('src/getty-generator')
ec57a4ea 2178subdir('src/gpt-auto-generator')
74093422 2179subdir('src/hibernate-resume')
b61016f2 2180subdir('src/home')
83b6af36 2181subdir('src/hostname')
6fab49e4 2182subdir('src/hwdb')
e2bdf00a 2183subdir('src/id128')
83b6af36 2184subdir('src/import')
9f907d30 2185subdir('src/initctl')
81fe141b 2186subdir('src/integritysetup')
f7b349e8 2187subdir('src/journal')
b61016f2 2188subdir('src/journal-remote')
83b6af36
ZJS
2189subdir('src/kernel-install')
2190subdir('src/locale')
b61016f2 2191subdir('src/login')
83b6af36 2192subdir('src/machine')
df490fc7 2193subdir('src/machine-id-setup')
eb51c09d 2194subdir('src/modules-load')
9f907d30 2195subdir('src/mount')
b61016f2 2196subdir('src/network')
98e39a55 2197subdir('src/notify')
83b6af36 2198subdir('src/nspawn')
2080c097
YW
2199subdir('src/nss-myhostname')
2200subdir('src/nss-mymachines')
2201subdir('src/nss-resolve')
2202subdir('src/nss-systemd')
b61016f2
YW
2203subdir('src/oom')
2204subdir('src/partition')
e2bdf00a 2205subdir('src/path')
32295fa0 2206subdir('src/pcrextend')
a4342701 2207subdir('src/pcrlock')
b61016f2
YW
2208subdir('src/portable')
2209subdir('src/pstore')
5371c269 2210subdir('src/quotacheck')
c8c78771 2211subdir('src/random-seed')
6c713961 2212subdir('src/rc-local-generator')
df490fc7 2213subdir('src/remount-fs')
cb935625 2214subdir('src/reply-password')
83b6af36 2215subdir('src/resolve')
7e6ca26f 2216subdir('src/rfkill')
2a9b4bbe 2217subdir('src/rpm')
5c707c8c 2218subdir('src/run')
2a456620 2219subdir('src/run-generator')
b61016f2 2220subdir('src/shutdown')
16b081d6 2221subdir('src/sleep')
22f37744 2222subdir('src/socket-activate')
5371c269 2223subdir('src/socket-proxy')
0e322068 2224subdir('src/ssh-generator')
5c707c8c 2225subdir('src/stdio-bridge')
87e7979d 2226subdir('src/sulogin-shell')
16b081d6 2227subdir('src/sysctl')
9bca4ae4 2228subdir('src/sysext')
7e6ca26f 2229subdir('src/system-update-generator')
c3512573 2230subdir('src/systemctl')
43cc7a3e 2231subdir('src/sysupdate')
6fab49e4 2232subdir('src/sysusers')
6c713961 2233subdir('src/sysv-generator')
1761066b 2234subdir('src/storagetm')
83b6af36
ZJS
2235subdir('src/timedate')
2236subdir('src/timesync')
db64ba81 2237subdir('src/tmpfiles')
1761066b 2238subdir('src/tpm2-setup')
cb935625 2239subdir('src/tty-ask-password-agent')
eb51c09d
YW
2240subdir('src/update-done')
2241subdir('src/update-utmp')
dbab4fb9 2242subdir('src/user-sessions')
b61016f2 2243subdir('src/userdb')
d408a53f 2244subdir('src/varlinkctl')
c8c78771 2245subdir('src/vconsole')
81fe141b 2246subdir('src/veritysetup')
9de3cc14 2247subdir('src/vmspawn')
e2bdf00a 2248subdir('src/volatile-root')
9e61ed11 2249subdir('src/vpick')
0275e918 2250subdir('src/xdg-autostart-generator')
83b6af36 2251
3976f372
YW
2252subdir('src/systemd')
2253
83b6af36 2254subdir('src/test')
7db7d5b7 2255subdir('src/fuzz')
a1d6dbb1 2256subdir('src/ukify/test') # needs to be last for test_env variable
cbc55c4c 2257subdir('test/fuzz')
83b6af36 2258
eb981a5b
LP
2259subdir('mime')
2260
d30d9bf0
LB
2261alias_target('devel', libsystemd_pc, libudev_pc, systemd_pc, udev_pc)
2262
e6267e83 2263#####################################################################
83b6af36 2264
130c87b1
YW
2265foreach test : simple_tests
2266 executables += test_template + { 'sources' : [test] }
2267endforeach
2268
2269foreach test : libsystemd_tests
2270 executables += test_template + test
2271endforeach
2272
cbc55c4c
YW
2273foreach fuzzer : simple_fuzzers
2274 executables += fuzz_template + { 'sources' : [fuzzer] }
2275endforeach
2276
c335921e 2277foreach dict : executables
130c87b1
YW
2278 name = dict.get('name', '')
2279 if name == ''
2280 name = fs.stem(dict.get('sources')[0])
cbc55c4c 2281 assert(name.split('-')[0] in ['test', 'fuzz'])
130c87b1
YW
2282 endif
2283
2284 is_test = name.startswith('test-')
cbc55c4c 2285 is_fuzz = name.startswith('fuzz-')
c335921e
YW
2286
2287 build = true
2288 foreach cond : dict.get('conditions', [])
2289 if conf.get(cond) != 1
2290 build = false
2291 break
2292 endif
2293 endforeach
2294 if not build
2295 continue
2296 endif
2297
2298 kwargs = {}
2299 foreach key, val : dict
130c87b1
YW
2300 if key in ['name', 'dbus', 'public', 'conditions',
2301 'type', 'suite', 'timeout', 'parallel']
c335921e
YW
2302 continue
2303 endif
130c87b1 2304
c335921e
YW
2305 kwargs += { key : val }
2306 endforeach
2307
2308 foreach key, val : executable_additional_kwargs
2309 kwargs += { key : [ kwargs.get(key, []), val ]}
2310 endforeach
2311
130c87b1
YW
2312 if is_test
2313 kwargs += { 'install_dir' : kwargs.get('install_dir') / dict.get('type', '') }
2314 foreach key, val : test_additional_kwargs
2315 kwargs += { key : [ kwargs.get(key, []), val ] }
2316 endforeach
2317 endif
2318
cbc55c4c
YW
2319 if is_fuzz
2320 foreach key, val : fuzz_additional_kwargs
2321 kwargs += { key : [ kwargs.get(key, []), val ] }
2322 endforeach
2323 endif
2324
c335921e
YW
2325 exe = executable(
2326 name,
2327 kwargs : kwargs,
2328 )
2329
2330 executables_by_name += { name : exe }
2331
2332 if dict.get('build_by_default', true)
2333 if dict.get('dbus', false)
2334 dbus_programs += exe
2335 endif
2336 if dict.get('public', false)
2337 public_programs += exe
2338 endif
2339 endif
130c87b1
YW
2340
2341 if is_test
2342 type = dict.get('type', '')
2343 suite = dict.get('suite', '')
2344 if suite == ''
2345 suite = fs.name(fs.parent(dict.get('sources')[0]))
2346 if suite.startswith('sd-')
2347 suite = 'libsystemd'
2348 endif
2349 endif
2350
2351 if type == 'manual'
2352 message('@0@/@1@ is a manual test'.format(suite, name))
2353 elif type == 'unsafe' and want_tests != 'unsafe'
2354 message('@0@/@1@ is an unsafe test'.format(suite, name))
2355 elif dict.get('build_by_default')
2356 test(name, exe,
2357 env : test_env,
2358 timeout : dict.get('timeout', 30),
2359 suite : suite,
2360 is_parallel : dict.get('parallel', true))
2361 endif
2362 endif
cbc55c4c
YW
2363
2364 if is_fuzz
2365 fuzzer_exes += exe
2366
2367 if want_tests != 'false'
2368 # Run the fuzz regression tests without any sanitizers enabled.
f933f752 2369 # Additional invocations with sanitizers may get added below.
cbc55c4c
YW
2370 fuzz_ins = fuzz_regression_tests.get(name, {})
2371 foreach directive : fuzz_ins.get('directives', [])
f933f752
ZJS
2372 tt = '@0@_@1@'.format(name, fs.name(directive.full_path()))
2373 if tt.substring(45) != ''
2374 error('Directive sample name is too long:', directive.full_path())
2375 endif
2376
2377 test(tt,
cbc55c4c
YW
2378 exe,
2379 suite : 'fuzz',
2380 args : directive.full_path(),
2381 depends : directive)
2382 endforeach
2383 foreach file : fuzz_ins.get('files', [])
f933f752
ZJS
2384 tt = '@0@_@1@'.format(name, fs.name(file))
2385 if tt.substring(45) != ''
2386 error('Fuzz sample name is too long:', fs.name(file))
2387 endif
2388
2389 test(tt,
cbc55c4c
YW
2390 exe,
2391 suite : 'fuzz',
2392 args : file)
2393 endforeach
2394 endif
2395 endif
c335921e
YW
2396endforeach
2397
cbc55c4c
YW
2398alias_target('fuzzers', fuzzer_exes)
2399
e6267e83 2400#####################################################################
c335921e 2401
130c87b1 2402test_dlopen = executables_by_name.get('test-dlopen')
83b6af36 2403
c335921e
YW
2404foreach dict : modules
2405 name = dict.get('name')
2406 is_nss = name.startswith('nss_')
2407 is_pam = name.startswith('pam_')
2408
2409 build = true
2410 foreach cond : dict.get('conditions', [])
2411 if conf.get(cond) != 1
2412 build = false
2413 break
2414 endif
2415 endforeach
2416 if not build
2417 continue
2418 endif
2419
2420 kwargs = {}
2421 foreach key, val : dict
90461ef5 2422 if key in ['name', 'conditions', 'version-script']
c335921e
YW
2423 continue
2424 endif
2425 kwargs += { key : val }
2426 endforeach
2427
c335921e
YW
2428 kwargs += {
2429 'link_args' : [
2430 kwargs.get('link_args', []),
90461ef5
JJ
2431 '-Wl,--version-script=' + dict.get('version-script'),
2432 ],
2433 'link_depends' : [
2434 kwargs.get('link_depends', []),
2435 dict.get('version-script'),
c335921e
YW
2436 ],
2437 }
2438 foreach key, val : module_additional_kwargs
2439 kwargs += { key : [ kwargs.get(key, []), val ]}
2440 endforeach
2441
2442 lib = shared_library(
2443 name,
2444 kwargs : kwargs,
2445 )
2446
2447 if is_nss
2448 # We cannot use shared_module because it does not support version suffix.
2449 # Unfortunately shared_library insists on creating the symlink…
c31ba5cf 2450 meson.add_install_script(sh, '-c', 'rm $DESTDIR@0@/lib@1@.so'.format(libdir, name),
c335921e
YW
2451 install_tag : 'nss')
2452 endif
2453
2454 if want_tests != 'false' and (is_nss or is_pam)
2455 test('dlopen-' + name,
2456 test_dlopen,
2457 # path to dlopen must include a slash
2458 args : lib.full_path(),
dc4a0055
YW
2459 depends : lib,
2460 suite : is_nss ? 'nss' : 'pam')
c335921e
YW
2461 endif
2462endforeach
2463
e6267e83 2464#####################################################################
5c23128d 2465
f9a6cb0e 2466ukify = custom_target(
30ec2eae
ZJS
2467 'ukify',
2468 input : 'src/ukify/ukify.py',
2469 output : 'ukify',
2470 command : [jinja2_cmdline, '@INPUT@', '@OUTPUT@'],
9a01fe39 2471 install : want_ukify,
30ec2eae 2472 install_mode : 'rwxr-xr-x',
f65aa477 2473 install_dir : bindir)
9a01fe39 2474if want_ukify
42551ea7 2475 public_programs += ukify
f65aa477 2476
a1ca52c2 2477 # symlink for backwards compatibility after rename
f65aa477
ZJS
2478 meson.add_install_script(sh, '-c',
2479 ln_s.format(bindir / 'ukify',
2480 libexecdir / 'ukify'))
f9a6cb0e
ZJS
2481endif
2482
e6267e83 2483#####################################################################
69e96427 2484
e5cc6d10
YW
2485subdir('rules.d')
2486subdir('test')
2487
e6267e83 2488#####################################################################
5c23128d 2489
10783aef
ZJS
2490subdir('docs/sysvinit')
2491subdir('docs/var-log')
2492subdir('hwdb.d')
2493subdir('man')
378e9d2b 2494subdir('modprobe.d')
10783aef
ZJS
2495subdir('network')
2496subdir('presets')
2497subdir('shell-completion/bash')
2498subdir('shell-completion/zsh')
5c23128d
ZJS
2499subdir('sysctl.d')
2500subdir('sysusers.d')
2501subdir('tmpfiles.d')
4f10b807 2502subdir('units')
5c23128d 2503
5c23128d
ZJS
2504install_subdir('factory/etc',
2505 install_dir : factorydir)
623370e6 2506subdir('factory/templates')
5c23128d 2507
d7aa78c3
JT
2508if install_sysconfdir
2509 install_data('xorg/50-systemd-user.sh',
2510 install_dir : xinitrcdir)
2511endif
f09eb768 2512install_data('LICENSE.GPL2',
5c23128d 2513 'LICENSE.LGPL2.1',
f09eb768
LP
2514 'NEWS',
2515 'README',
eea98402 2516 'docs/CODING_STYLE.md',
1d1cb168 2517 'docs/DISTRO_PORTING.md',
9e825ebf 2518 'docs/ENVIRONMENT.md',
5425f8a5 2519 'docs/HACKING.md',
9e825ebf 2520 'docs/TRANSIENT-SETTINGS.md',
b6dc0d7d 2521 'docs/TRANSLATORS.md',
9e825ebf 2522 'docs/UIDS-GIDS.md',
5c23128d 2523 install_dir : docdir)
d68b342b 2524
9c6e32a2
LB
2525install_subdir('LICENSES',
2526 install_dir : docdir)
2527
9289e093 2528install_emptydir(systemdstatedir)
94e75a54 2529
e6267e83 2530#####################################################################
d68b342b 2531
2d4efd1d
LB
2532# Ensure that changes to the docs/ directory do not break the
2533# basic Github pages build. But only run it in developer mode,
2534# as it might be fragile due to changes in the tooling, and it is
2535# not generally useful for users.
2536jekyll = find_program('jekyll', required : false)
2537if get_option('mode') == 'developer' and want_tests != 'false' and jekyll.found()
2538 test('github-pages',
2539 jekyll,
02e0f430 2540 suite : 'dist',
2d4efd1d 2541 args : ['build',
fce9abb2
ZJS
2542 '--source', project_source_root / 'docs',
2543 '--destination', project_build_root / '_site'])
2d4efd1d
LB
2544endif
2545
e6267e83 2546#####################################################################
2d4efd1d 2547
dd1e33c8 2548check_help = find_program('tools/check-help.sh')
ffb7406b 2549check_version = find_program('tools/check-version.sh')
005a29f2
ZJS
2550
2551foreach exec : public_programs
739a62bb 2552 name = fs.name(exec.full_path())
938be089
ZJS
2553 if want_tests != 'false'
2554 test('check-help-' + name,
dd1e33c8 2555 check_help,
02e0f430 2556 suite : 'dist',
e93ada98
DDM
2557 args : exec.full_path(),
2558 depends: exec)
ffb7406b
ZJS
2559
2560 test('check-version-' + name,
2561 check_version,
02e0f430 2562 suite : 'dist',
ffb7406b
ZJS
2563 args : [exec.full_path(),
2564 meson.project_version()],
2565 depends: exec)
938be089 2566 endif
005a29f2
ZJS
2567endforeach
2568
52d4d1d3 2569# Enable tests for all supported sanitizers
7db5761d 2570foreach tuple : fuzz_sanitizers
52d4d1d3
ZJS
2571 sanitizer = tuple[0]
2572 build = tuple[1]
b68dfb9e 2573
7a6397d2 2574 if cc.has_link_argument('-fsanitize=@0@'.format(sanitizer))
7db5761d
MK
2575 foreach fuzzer, fuzz_ins : fuzz_regression_tests
2576 name = '@0@:@1@'.format(fuzzer, sanitizer)
2577 if want_tests == 'false'
2578 message('Not compiling @0@ because tests is set to false'.format(name))
2579 continue
52d4d1d3 2580 endif
7db5761d
MK
2581 if not fuzz_tests
2582 message('Not compiling @0@ because fuzz-tests is set to false'.format(name))
2583 continue
2584 endif
2585 exe = custom_target(
2586 name,
2587 output : name,
cbc55c4c 2588 depends : build,
7db5761d
MK
2589 command : [ln, '-fs',
2590 build.full_path() / fuzzer,
2591 '@OUTPUT@'],
2592 build_by_default : true)
2593
cbc55c4c
YW
2594 foreach directive : fuzz_ins.get('directives', [])
2595 test('@0@_@1@_@2@'.format(fuzzer, fs.name(directive.full_path()), sanitizer),
2596 env,
2597 suite : 'fuzz+san',
2598 env : ['UBSAN_OPTIONS=print_stacktrace=1:print_summary=1:halt_on_error=1'],
2599 timeout : 60,
2600 args : [exe.full_path(), directive.full_path()],
2601 depends : directive)
2602 endforeach
2603 foreach file : fuzz_ins.get('files', [])
2604 test('@0@_@1@_@2@'.format(fuzzer, fs.name(file), sanitizer),
52d4d1d3 2605 env,
14056a52 2606 suite : 'fuzz+san',
89767158
EV
2607 env : ['UBSAN_OPTIONS=print_stacktrace=1:print_summary=1:halt_on_error=1'],
2608 timeout : 60,
cbc55c4c 2609 args : [exe.full_path(), file])
7db5761d 2610 endforeach
52d4d1d3 2611 endforeach
b68dfb9e
ZJS
2612 endif
2613endforeach
2614
e6267e83 2615#####################################################################
b68dfb9e 2616
0700e8ba 2617if git.found()
37efbbd8 2618 all_files = run_command(
0f4c4f38
ZJS
2619 env, '-u', 'GIT_WORK_TREE',
2620 git, '--git-dir=@0@/.git'.format(project_source_root),
ba9ca60a 2621 'ls-files', ':/*.[ch]', ':/*.cc',
e92777d2
ZJS
2622 check : false)
2623 if all_files.returncode() == 0
2624 all_files = files(all_files.stdout().split())
2625
2626 custom_target(
2627 'tags',
2628 output : 'tags',
2629 command : [env, 'etags', '-o', '@0@/TAGS'.format(project_source_root)] + all_files)
2630 run_target(
2631 'ctags',
691db9a7 2632 command : [env, 'ctags', '--tag-relative=never', '-o', '@0@/tags'.format(project_source_root)] + all_files)
60892358
ZJS
2633
2634 ############################################
2635
2636 if want_tests != 'false' and conf.get('BUILD_MODE_DEVELOPER') == 1
2637 test('check-includes',
2638 files('tools/check-includes.py'),
2639 args: all_files,
dc4a0055
YW
2640 env : ['PROJECT_SOURCE_ROOT=@0@'.format(project_source_root)],
2641 suite : 'headers')
60892358 2642 endif
e92777d2 2643 endif
177929c2 2644
60892358
ZJS
2645 ####################################################
2646
dd1e33c8 2647 git_contrib_sh = find_program('tools/git-contrib.sh')
a923e085 2648 run_target(
37efbbd8 2649 'git-contrib',
dd1e33c8 2650 command : [git_contrib_sh])
dd6ab3df 2651
60892358
ZJS
2652 ####################################################
2653
dd6ab3df 2654 git_head = run_command(
e92777d2
ZJS
2655 git, '--git-dir=@0@/.git'.format(project_source_root),
2656 'rev-parse', 'HEAD',
2657 check : false).stdout().strip()
dd6ab3df 2658 git_head_short = run_command(
e92777d2
ZJS
2659 git, '--git-dir=@0@/.git'.format(project_source_root),
2660 'rev-parse', '--short=7', 'HEAD',
2661 check : false).stdout().strip()
dd6ab3df
ZJS
2662
2663 run_target(
2664 'git-snapshot',
0f4c4f38 2665 command : [git, 'archive',
1485aacb 2666 '-o', '@0@/systemd-@1@.tar.gz'.format(project_source_root,
dd6ab3df
ZJS
2667 git_head_short),
2668 '--prefix', 'systemd-@0@/'.format(git_head),
2669 'HEAD'])
2670endif
829257d1 2671
e6267e83 2672#####################################################################
829257d1 2673
dd1e33c8 2674check_api_docs_sh = find_program('tools/check-api-docs.sh')
51b13863
LP
2675run_target(
2676 'check-api-docs',
2677 depends : [man, libsystemd, libudev],
dd1e33c8 2678 command : [check_api_docs_sh, libsystemd.full_path(), libudev.full_path()])
51b13863 2679
f12c5d36
ZJS
2680alias_target('update-dbus-docs', update_dbus_docs)
2681alias_target('update-man-rules', update_man_rules)
e3c368f6 2682
0628d48e
LB
2683if not meson.is_cross_build()
2684 custom_target(
2685 'export-dbus-interfaces',
4645074e 2686 output : fs.name(dbus_interfaces_dir),
0628d48e 2687 install : dbus_interfaces_dir != 'no',
4645074e 2688 install_dir : fs.parent(dbus_interfaces_dir),
0628d48e
LB
2689 command : [export_dbus_interfaces_py, '@OUTPUT@', dbus_programs])
2690endif
e3c68924 2691
e6267e83 2692#####################################################################
829257d1 2693
e92777d2
ZJS
2694alt_time_epoch = run_command('date', '-Is', '-u', '-d', '@@0@'.format(time_epoch),
2695 check : true).stdout().strip()
12085ebb
ZJS
2696
2697summary({
12085ebb
ZJS
2698 'split bin-sbin' : split_bin,
2699 'prefix directory' : prefixdir,
12085ebb
ZJS
2700 'sysconf directory' : sysconfdir,
2701 'include directory' : includedir,
2702 'lib directory' : libdir,
12085ebb
ZJS
2703 'SysV init scripts' : sysvinit_path,
2704 'SysV rc?.d directories' : sysvrcnd_path,
2705 'PAM modules directory' : pamlibdir,
2706 'PAM configuration directory' : pamconfdir,
0abd510f
LP
2707 'ssh server configuration directory' : sshdconfdir,
2708 'ssh client configuration directory' : sshconfdir,
12085ebb
ZJS
2709 'libcryptsetup plugins directory' : libcryptsetup_plugins_dir,
2710 'RPM macros directory' : rpmmacrosdir,
2711 'modprobe.d directory' : modprobedir,
2712 'D-Bus policy directory' : dbuspolicydir,
2713 'D-Bus session directory' : dbussessionservicedir,
2714 'D-Bus system directory' : dbussystemservicedir,
7e560e79 2715 'D-Bus interfaces directory' : dbus_interfaces_dir,
12085ebb
ZJS
2716 'bash completions directory' : bashcompletiondir,
2717 'zsh completions directory' : zshcompletiondir,
a2b0cd3f 2718 'private shared lib version tag' : shared_lib_tag,
12085ebb
ZJS
2719 'extra start script' : get_option('rc-local'),
2720 'debug shell' : '@0@ @ @1@'.format(get_option('debug-shell'),
2721 get_option('debug-tty')),
2722 'system UIDs' : '<=@0@ (alloc >=@1@)'.format(conf.get('SYSTEM_UID_MAX'),
2723 conf.get('SYSTEM_ALLOC_UID_MIN')),
2724 'system GIDs' : '<=@0@ (alloc >=@1@)'.format(conf.get('SYSTEM_GID_MAX'),
2725 conf.get('SYSTEM_ALLOC_GID_MIN')),
2726 'dynamic UIDs' : '@0@…@1@'.format(dynamic_uid_min, dynamic_uid_max),
2727 'container UID bases' : '@0@…@1@'.format(container_uid_base_min, container_uid_base_max),
2728 'static UID/GID allocations' : ' '.join(static_ugids),
2729 '/dev/kvm access mode' : get_option('dev-kvm-mode'),
2730 'render group access mode' : get_option('group-render-mode'),
2731 'certificate root directory' : get_option('certificate-root'),
2732 'support URL' : support_url,
2733 'nobody user name' : nobody_user,
2734 'nobody group name' : nobody_group,
2735 'fallback hostname' : get_option('fallback-hostname'),
9798deaf 2736 'default compression method' : compression,
12085ebb
ZJS
2737 'default DNSSEC mode' : default_dnssec,
2738 'default DNS-over-TLS mode' : default_dns_over_tls,
2739 'default mDNS mode' : default_mdns,
2740 'default LLMNR mode' : default_llmnr,
2741 'default DNS servers' : dns_servers.split(' '),
2742 'default NTP servers' : ntp_servers.split(' '),
2743 'default cgroup hierarchy' : default_hierarchy,
2744 'default net.naming-scheme value' : default_net_naming_scheme,
2745 'default KillUserProcesses value' : kill_user_processes,
2746 'default locale' : default_locale,
88b6f0de 2747 'default nspawn locale' : nspawn_locale,
79dec86a 2748 'default status unit format' : status_unit_format_default,
12085ebb
ZJS
2749 'default user $PATH' :
2750 default_user_path != '' ? default_user_path : '(same as system services)',
2751 'systemd service watchdog' : service_watchdog == '' ? 'disabled' : service_watchdog,
2752 'time epoch' : '@0@ (@1@)'.format(time_epoch, alt_time_epoch)})
829257d1
ZJS
2753
2754# TODO:
2755# CFLAGS: ${OUR_CFLAGS} ${CFLAGS}
2756# CPPFLAGS: ${OUR_CPPFLAGS} ${CPPFLAGS}
2757# LDFLAGS: ${OUR_LDFLAGS} ${LDFLAGS}
2758
829257d1
ZJS
2759found = []
2760missing = []
2761
2762foreach tuple : [
56d68e71
ZJS
2763 # dependencies
2764 ['ACL'],
829257d1 2765 ['AUDIT'],
829257d1 2766 ['AppArmor'],
56d68e71
ZJS
2767 ['IMA'],
2768 ['PAM'],
829257d1 2769 ['SECCOMP'],
56d68e71 2770 ['SELinux'],
829257d1 2771 ['SMACK'],
56d68e71
ZJS
2772 ['blkid'],
2773 ['elfutils'],
829257d1 2774 ['gcrypt'],
829257d1 2775 ['gnutls'],
7d861e12 2776 ['libbpf'],
56d68e71 2777 ['libcryptsetup'],
d1ae38d8 2778 ['libcryptsetup-plugins'],
829257d1 2779 ['libcurl'],
56d68e71
ZJS
2780 ['libfdisk'],
2781 ['libfido2'],
829257d1 2782 ['libidn'],
56d68e71 2783 ['libidn2'],
829257d1 2784 ['libiptc'],
56d68e71
ZJS
2785 ['microhttpd'],
2786 ['openssl'],
2787 ['p11kit'],
1d8aae43 2788 ['passwdqc'],
56d68e71
ZJS
2789 ['pcre2'],
2790 ['pwquality'],
2791 ['qrencode'],
2792 ['tpm2'],
2793 ['xkbcommon'],
2794
2795 # compression libs
2796 ['zstd'],
2797 ['lz4'],
2798 ['xz'],
2799 ['zlib'],
2800 ['bzip2'],
2801
2802 # components
2803 ['backlight'],
829257d1 2804 ['binfmt'],
dfca5587 2805 ['bootloader'],
0a0d4899 2806 ['bpf-framework', conf.get('BPF_FRAMEWORK') == 1],
56d68e71 2807 ['coredump'],
56d68e71 2808 ['efi'],
dfca5587 2809 ['environment.d'],
829257d1 2810 ['firstboot'],
56d68e71
ZJS
2811 ['hibernate'],
2812 ['homed'],
2813 ['hostnamed'],
2814 ['hwdb'],
2815 ['importd'],
2816 ['initrd'],
f887eab1 2817 ['kernel-install'],
56d68e71 2818 ['localed'],
829257d1
ZJS
2819 ['logind'],
2820 ['machined'],
56d68e71
ZJS
2821 ['networkd'],
2822 ['nss-myhostname'],
2823 ['nss-mymachines'],
2824 ['nss-resolve'],
2825 ['nss-systemd'],
2826 ['oomd'],
61d0578b 2827 ['portabled'],
56d68e71
ZJS
2828 ['pstore'],
2829 ['quotacheck'],
2830 ['randomseed'],
2831 ['repart'],
2832 ['resolve'],
2833 ['rfkill'],
9bca4ae4 2834 ['sysext'],
0a0d4899 2835 ['systemd-analyze', conf.get('ENABLE_ANALYZE') == 1],
43cc7a3e 2836 ['sysupdate'],
56d68e71 2837 ['sysusers'],
1761066b 2838 ['storagetm'],
829257d1
ZJS
2839 ['timedated'],
2840 ['timesyncd'],
56d68e71
ZJS
2841 ['tmpfiles'],
2842 ['userdb'],
2843 ['vconsole'],
9de3cc14 2844 ['vmspawn'],
56d68e71
ZJS
2845 ['xdg-autostart'],
2846
2847 # optional features
12b4cffd 2848 ['dmi'],
56d68e71 2849 ['idn'],
829257d1 2850 ['polkit'],
56d68e71 2851 ['nscd'],
0a0d4899 2852 ['legacy-pkla', install_polkit_pkla],
829257d1 2853 ['kmod'],
ede5a78f 2854 ['xenctrl'],
829257d1
ZJS
2855 ['dbus'],
2856 ['glib'],
829257d1 2857 ['tpm'],
0a0d4899
JH
2858 ['man pages', want_man],
2859 ['html pages', want_html],
2860 ['man page indices', want_man and have_lxml],
829257d1 2861 ['SysV compat'],
56d68e71 2862 ['compat-mutable-uid-boundaries'],
829257d1
ZJS
2863 ['utmp'],
2864 ['ldconfig'],
0a0d4899
JH
2865 ['adm group', get_option('adm-group')],
2866 ['wheel group', get_option('wheel-group')],
b14e1b43 2867 ['gshadow'],
829257d1
ZJS
2868 ['debug hashmap'],
2869 ['debug mmap cache'],
d6601495 2870 ['debug siphash'],
0a0d4899 2871 ['trace logging', conf.get('LOG_TRACE') == 1],
69525346
YW
2872 ['slow tests', slow_tests],
2873 ['fuzz tests', fuzz_tests],
0a0d4899
JH
2874 ['install tests', install_tests],
2875 ['link-udev-shared', get_option('link-udev-shared')],
2876 ['link-systemctl-shared', get_option('link-systemctl-shared')],
2877 ['link-networkd-shared', get_option('link-networkd-shared')],
2878 ['link-timesyncd-shared', get_option('link-timesyncd-shared')],
2879 ['link-journalctl-shared', get_option('link-journalctl-shared')],
2880 ['link-boot-shared', get_option('link-boot-shared')],
c06d2e44 2881 ['link-portabled-shared', get_option('link-portabled-shared')],
93651582 2882 ['first-boot-full-preset'],
ceedbf81 2883 ['fexecve'],
0a0d4899
JH
2884 ['standalone-binaries', get_option('standalone-binaries')],
2885 ['coverage', get_option('b_coverage')],
829257d1
ZJS
2886]
2887
af4d7860
ZJS
2888 if tuple.length() >= 2
2889 cond = tuple[1]
2890 else
829257d1
ZJS
2891 ident1 = 'HAVE_' + tuple[0].underscorify().to_upper()
2892 ident2 = 'ENABLE_' + tuple[0].underscorify().to_upper()
349cc4a5 2893 cond = conf.get(ident1, 0) == 1 or conf.get(ident2, 0) == 1
829257d1
ZJS
2894 endif
2895 if cond
5a8b1640 2896 found += tuple[0]
829257d1 2897 else
5a8b1640 2898 missing += tuple[0]
829257d1
ZJS
2899 endif
2900endforeach
2901
c716c253
ZJS
2902if static_libsystemd == 'false'
2903 missing += 'static-libsystemd'
2904else
2905 found += 'static-libsystemd(@0@)'.format(static_libsystemd)
2906endif
2907
2908if static_libudev == 'false'
2909 missing += 'static-libudev'
2910else
2911 found += 'static-libudev(@0@)'.format(static_libudev)
2912endif
2913
57633d23
ZJS
2914if conf.get('HAVE_OPENSSL_OR_GCRYPT') == 1 and conf.get('PREFER_OPENSSL') == 1
2915 found += 'cryptolib(openssl)'
2916elif conf.get('HAVE_OPENSSL_OR_GCRYPT') == 1
2917 found += 'cryptolib(gcrypt)'
2918else
2919 missing += 'cryptolib'
2920endif
2921
237f2da9
ZJS
2922if conf.get('DNS_OVER_TLS_USE_GNUTLS') == 1
2923 found += 'DNS-over-TLS(gnutls)'
2924elif conf.get('DNS_OVER_TLS_USE_OPENSSL') == 1
2925 found += 'DNS-over-TLS(openssl)'
2926else
2927 missing += 'DNS-over-TLS'
2928endif
2929
12085ebb
ZJS
2930summary({
2931 'enabled' : ', '.join(found),
2932 'disabled' : ', '.join(missing)},
2933 section : 'Features')