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