HALF ECHO LEARN / REFERENCE COLLECTION

v262.2

meson.build

124,145 bytesGit mode 100644Download original fileLGPL-2.1-or-later

Git blob: a4dfc11e43c6b0a295f78968c04686e85ecfc709

Lines 2001–3000 of 3,224

                        userspace,
                ],
                c_args : static_libudev_pic ? [] : ['-fno-PIC'],
                pic : static_libudev_pic)
 
        alias_target('libudev', libudev, install_libudev_static)
else
        alias_target('libudev', libudev)
endif
 
#####################################################################
 
runtest_env = custom_target(
        output : 'systemd-runtest.env',
        command : ['printf',
                   'SYSTEMD_TEST_DATA=%q\nSYSTEMD_CATALOG_DIR=%q\n',
                   meson.project_source_root() / 'test',
                   meson.project_build_root() / 'catalog'],
        capture: true,
        depends : catalogs,
        build_by_default : true)
 
test_cflags = ['-DTEST_CODE=1']
# We intentionally do not do inline initializations with definitions for a
# bunch of _cleanup_ variables in tests, to ensure valgrind is triggered if we
# use the variable unexpectedly. This triggers a lot of maybe-uninitialized
# false positives when the combination of -O2 and -flto is used. Suppress them.
if '-O2' in c_args and '-flto=auto' in c_args
        test_cflags += cc.first_supported_argument('-Wno-maybe-uninitialized')
endif
 
#####################################################################
 
# The 'install' field is extended to also control whether the automatically
# added variant, which is statically linked with libsystemd-shared, is installed:
#   'yes'    : Mapped to true.
#   'no'     : Mapped to false.
#   'static' : Mapped to false, and its target name is suffixed with '.shared'.
#              The static variant will be installed instead using the original name
#              (without the '.standalone' suffix).
# Currently, test and fuzzer executables only support 'yes' or 'no'.
#
# For executables matched by the install-standalone list, a .standalone variant
# will be installed if install is true.
executable_template = {
        'include_directories' : includes,
        'link_with' : [libshared],
        'install_rpath' : pkglibdir,
        'install' : 'yes',
        'build_by_default' : true,
}
 
generator_template = executable_template + {
        'install_dir' : systemgeneratordir,
}
 
libexec_template = executable_template + {
        'install_dir' : libexecdir,
}
 
executable_additional_kwargs = {
        'dependencies' : userspace,
}
 
test_template = executable_template + {
        'build_by_default' : want_tests != 'false',
        'install' : install_tests ? 'yes' : 'no',
        'install_dir' : unittestsdir,
}
 
test_additional_kwargs = {
        'c_args' : test_cflags,
        'link_depends' : runtest_env,
}
 
fuzz_template = executable_template + {
        'build_by_default' : want_fuzz_tests,
        'install' : 'no',
}
 
if want_ossfuzz
        fuzz_additional_kwargs = {
                'dependencies' : fuzzing_engine,
        }
elif want_libfuzzer
        fuzz_additional_kwargs = {
                'link_args' : ['-fsanitize=fuzzer'],
        }
else
        fuzz_additional_kwargs = {
                'sources' : files('src/fuzz/fuzz-main.c'),
        }
endif
fuzz_additional_kwargs += {
        'c_args' : test_cflags,
}
 
nss_template = {
        'version' : '2',
        'include_directories' : includes,
        # Note that we link NSS modules with '-z nodelete' so that mempools never get orphaned
        'link_args' : ['-z', 'nodelete'],
        'link_with' : [
                libc_wrapper_static,
                libsystemd_static,
                libshared_static,
                libbasic_static,
        ],
        'install' : true,
        'install_tag' : 'nss',
        'install_dir' : libdir,
}
 
pam_template = {
        'name_prefix' : '',
        'include_directories' : includes,
        'link_with' : [
                libsystemd_static,
                libshared_static,
        ],
        'dependencies' : libpam_cflags,
        'install' : true,
        'install_tag' : 'pam',
        'install_dir' : pamlibdir,
}
 
module_additional_kwargs = {
        'link_args' : ['-shared'],
        'dependencies' : userspace,
}
 
#####################################################################
 
# 'src/core' embeds a built-in copy of some unit files, so the unit file list
# from 'units' must be defined first.
subdir('units')
# systemd-analyze requires 'libcore'
subdir('src/core')
# systemd-networkd requires 'libsystemd_network'
subdir('src/libsystemd-network')
# hwdb requires 'udev_link_with' and 'udev_rpath'
subdir('src/udev')
 
subdir('src/ac-power')
subdir('src/analyze')
subdir('src/ask-password')
subdir('src/backlight')
subdir('src/battery-check')
subdir('src/binfmt')
subdir('src/bless-boot')
subdir('src/boot')
subdir('src/bootctl')
subdir('src/busctl')
subdir('src/cgls')
subdir('src/cgtop')
subdir('src/clonesetup')
subdir('src/coredump')
subdir('src/creds')
subdir('src/cryptenroll')
subdir('src/cryptsetup')
subdir('src/debug-generator')
subdir('src/delta')
subdir('src/detect-virt')
subdir('src/dissect')
subdir('src/environment-d-generator')
subdir('src/escape')
subdir('src/factory-reset')
subdir('src/firstboot')
subdir('src/fsck')
subdir('src/fstab-generator')
subdir('src/getty-generator')
subdir('src/gpt-auto-generator')
subdir('src/growfs')
subdir('src/hibernate-resume')
subdir('src/home')
subdir('src/hostname')
subdir('src/hwdb')
subdir('src/id128')
subdir('src/import')
subdir('src/imds') # Note, we are not alphabetically here, since we want to use a variable from src/import/ here
subdir('src/integritysetup')
subdir('src/journal')
subdir('src/journal-remote')
subdir('src/kernel-install')
subdir('src/keyutil')
subdir('src/locale')
subdir('src/login')
subdir('src/machine')
subdir('src/machine-id-setup')
subdir('src/measure')
subdir('src/modules-load')
subdir('src/mount')
subdir('src/mountfsd')
subdir('src/mstack')
subdir('src/mute-console')
subdir('src/network')
subdir('src/notify')
subdir('src/nspawn')
subdir('src/nsresourced')
subdir('src/nss-myhostname')
subdir('src/nss-mymachines')
subdir('src/nss-resolve')
subdir('src/nss-systemd')
subdir('src/oom')
subdir('src/path')
subdir('src/pcrextend')
subdir('src/pcrlock')
subdir('src/portable')
subdir('src/pstore')
subdir('src/ptyfwd')
subdir('src/quotacheck')
subdir('src/random-seed')
subdir('src/remount-fs')
subdir('src/repart')
subdir('src/report')
subdir('src/reply-password')
subdir('src/resolve')
subdir('src/rfkill')
subdir('src/rpm')
subdir('src/run')
subdir('src/run-generator')
subdir('src/sbsign')
subdir('src/shutdown')
subdir('src/sleep')
subdir('src/socket-activate')
subdir('src/socket-proxy')
subdir('src/ssh-generator')
subdir('src/stdio-bridge')
subdir('src/storage')
subdir('src/storagetm')
subdir('src/sulogin-shell')
subdir('src/sysctl')
subdir('src/sysext')
subdir('src/sysinstall')
subdir('src/system-update-generator')
subdir('src/systemctl')
subdir('src/sysupdate')
subdir('src/sysusers')
subdir('src/timedate')
subdir('src/timesync')
subdir('src/tmpfiles')
subdir('src/tpm2-setup')
subdir('src/tty-ask-password-agent')
subdir('src/update-done')
subdir('src/update-utmp')
subdir('src/user-sessions')
subdir('src/userdb')
subdir('src/validatefs')
subdir('src/varlinkctl')
subdir('src/vconsole')
subdir('src/veritysetup')
subdir('src/vmspawn')
subdir('src/volatile-root')
subdir('src/vpick')
subdir('src/xdg-autostart-generator')
 
subdir('src/systemd')
 
subdir('src/test')
subdir('src/fuzz')
subdir('src/ukify/test')  # needs to be last for test_env variable
subdir('test/fuzz')
 
subdir('mime')
 
alias_target('devel', libsystemd_pc, libudev_pc, systemd_pc, udev_pc)
 
#####################################################################
 
foreach test : simple_tests
        executables += test_template + { 'sources' : [test] }
endforeach
 
foreach test : libsystemd_tests
        executables += test_template + test
endforeach
 
foreach fuzzer : simple_fuzzers
        executables += fuzz_template + { 'sources' : [fuzzer] }
endforeach
 
foreach dict : executables
        name = dict.get('name', '')
        if name == ''
                name = fs.stem(dict.get('sources')[0])
                assert(name.split('-')[0] in ['test', 'fuzz'])
        endif
 
        is_test = name.startswith('test-')
        is_fuzz = name.startswith('fuzz-')
 
        build = true
        foreach cond : dict.get('conditions', [])
                if conf.get(cond) != 1
                        build = false
                        break
                endif
        endforeach
        if not build
                continue
        endif
 
        exe_sources = dict.get('sources', []) + dict.get('export', [])
 
        foreach bpf_name : dict.get('bpf_programs', [])
                if bpf_name in bpf_programs_by_name
                        exe_sources += bpf_programs_by_name[bpf_name]
                endif
        endforeach
 
        kwargs = {}
        foreach key, val : dict
                if key in ['name', 'dbus', 'public', 'conditions', 'type', 'suite',
                           'timeout', 'parallel', 'sources', 'import', 'export',
                           'include_directories', 'build_by_default', 'install',
                           'bpf_programs', 'link_args_static']
                        continue
                endif
 
                kwargs += { key : val }
        endforeach
 
        foreach key, val : executable_additional_kwargs
                kwargs += { key : [ kwargs.get(key, []), val ]}
        endforeach
 
        include_directories = dict['include_directories']
        if not is_test and exe_sources.length() > 0
                include_directories += fs.parent(exe_sources[0])
        endif
 
        foreach val : dict.get('import', [])
                obj = exported_by_name[val]
                kwargs += { 'objects' : kwargs.get('objects', []) + obj['exported'] }
                include_directories += obj['include_directories']
        endforeach
 
        if is_test
                kwargs += { 'install_dir' : kwargs.get('install_dir') / dict.get('type', '') }
                foreach key, val : test_additional_kwargs
                        kwargs += { key : [ kwargs.get(key, []), val ] }
                endforeach
        endif
 
        if is_fuzz
                include_directories += include_directories('src/fuzz')
                foreach key, val : fuzz_additional_kwargs
                        if key == 'sources'
                                exe_sources += val
                        else
                                kwargs += { key : [ kwargs.get(key, []), val ] }
                        endif
                endforeach
        endif
 
        name_shared = name
        name_static = name + '.standalone'
        install = dict.get('install')
        build_by_default = dict.get('build_by_default')
        install_standalone = false
        if not (is_test or is_fuzz)
                foreach pattern : standalone_binaries
                        if name.contains(pattern)
                                install_standalone = true
                        endif
                endforeach
        endif
 
        if install in ['yes', 'no']
                install_shared = install == 'yes'
                install_static = install_shared and install_standalone
                build_by_default_shared = build_by_default
                build_by_default_static = build_by_default and (install_standalone or want_dlopen_tests)
        elif install == 'static'
                if is_test or is_fuzz
                        error('Install mode "@0@" is not supported for test or fuzzer target "@1@"'.format(install, name))
                endif
                name_shared = name + '.shared'
                name_static = name
                install_shared = false
                install_static = true
                build_by_default_shared = false
                build_by_default_static = build_by_default
        else
                error('Unknown install mode "@0@" for target "@1@"'.format(install, name))
        endif
 
        exe = executable(
                name_shared,
                sources : exe_sources,
                kwargs : kwargs,
                implicit_include_directories : false,
                include_directories : include_directories,
                build_by_default: build_by_default_shared,
                install: install_shared,
        )
 
        executables_by_name += { name_shared : exe }
        sources += exe_sources
 
        if 'export' in dict
                exported_by_name += {
                        name : {
                                'exported' : exe.extract_objects(dict['export']),
                                'include_directories' : fs.parent(dict['export'][0]),
                        }
                }
        endif
 
        if build_by_default_shared
                if dict.get('dbus', false)
                        dbus_programs += exe
                endif
                if dict.get('public', false)
                        public_programs += exe
                endif
        endif
 
        if not is_test and not is_fuzz
                link_with_static = []
                foreach obj : kwargs.get('link_with', [])
                        if obj.full_path() == libshared.full_path()
                                link_with_static += [
                                        libshared_static,
                                        libsystemd_static,
                                ]
                        elif obj.full_path() == libcore.full_path()
                                link_with_static += libcore_static
                        else
                                link_with_static += obj
                        endif
                endforeach
 
                kwargs_static = kwargs + {
                        # Always import all objects from the main executable.
                        'objects' : kwargs.get('objects', []) + exe.extract_objects(exe_sources),
                        'link_with' : link_with_static,
                        'link_args' : dict.get('link_args_static', kwargs.get('link_args', [])),
                }
 
                exe_static = executable(
                        name_static,
                        kwargs : kwargs_static,
                        implicit_include_directories : false,
                        include_directories : include_directories,
                        build_by_default: build_by_default_static,
                        install: install_static,
                )
 
                if build_by_default_static
                        executables_by_name += { name_static : exe_static }
 
                        if dict.get('dbus', false) and not build_by_default_shared
                                dbus_programs += exe_static
                        endif
                        if dict.get('public', false)
                                public_programs += exe_static
                        endif
                endif
        endif
 
        if is_test
                type = dict.get('type', '')
                suite = dict.get('suite', '')
                if suite == ''
                        suite = fs.name(fs.parent(dict.get('sources')[0]))
                        if suite.startswith('sd-')
                                suite = 'libsystemd'
                        endif
                endif
 
                if type == 'manual'
                        message(f'@suite@/@name@ is a manual test')
                elif type == 'unsafe' and want_tests != 'unsafe'
                        message(f'@suite@/@name@ is an unsafe test')
                elif dict.get('build_by_default')
                        test(name, exe,
                             env : test_env,
                             timeout : dict.get('timeout', 30),
                             suite : suite,
                             is_parallel : dict.get('parallel', true))
                endif
        endif
 
        if is_fuzz
                fuzzer_exes += exe
 
                if want_tests != 'false' and want_fuzz_tests
                        fuzz_ins = fuzz_regression_tests.get(name, {})
                        foreach directive : fuzz_ins.get('directives', [])
                                tt = '@0@_@1@'.format(name, fs.name(directive.full_path()))
                                if tt.substring(45) != ''
                                        error('Directive sample name is too long:', directive.full_path())
                                endif
 
                                test(tt,
                                     exe,
                                     suite : 'fuzz',
                                     args : directive.full_path(),
                                     env : ['UBSAN_OPTIONS=print_stacktrace=1:print_summary=1:halt_on_error=1'],
                                     timeout : 60,
                                     depends : directive)
                        endforeach
                        foreach file : fuzz_ins.get('files', [])
                                tt = '@0@_@1@'.format(name, fs.name(file))
                                if tt.substring(45) != ''
                                        error('Fuzz sample name is too long:', fs.name(file))
                                endif
 
                                test(tt,
                                     exe,
                                     suite : 'fuzz',
                                     env : ['UBSAN_OPTIONS=print_stacktrace=1:print_summary=1:halt_on_error=1'],
                                     timeout : 60,
                                     args : file)
                        endforeach
                endif
        endif
endforeach
 
alias_target('fuzzers', fuzzer_exes)
 
#####################################################################
 
test_dlopen = executables_by_name.get('test-dlopen')
 
nss_targets = []
pam_targets = []
module_targets = []
modules_by_name = {}
foreach dict : modules
        name = dict.get('name')
        is_nss = name.startswith('nss_')
        is_pam = name.startswith('pam_')
 
        build = true
        foreach cond : dict.get('conditions', [])
                if conf.get(cond) != 1
                        build = false
                        break
                endif
        endforeach
        if not build
                continue
        endif
 
        kwargs = {}
        foreach key, val : dict
                if key in ['name', 'conditions', 'version-script']
                        continue
                endif
                kwargs += { key : val }
        endforeach
 
        kwargs += {
                'link_args' : [
                        kwargs.get('link_args', []),
                        '-Wl,--version-script=' + dict.get('version-script'),
                ],
                'link_depends' : [
                        kwargs.get('link_depends', []),
                        dict.get('version-script'),
                ],
        }
        foreach key, val : module_additional_kwargs
                kwargs += { key : [ kwargs.get(key, []), val ]}
        endforeach
 
        lib = shared_library(
                name,
                kwargs : kwargs,
                implicit_include_directories : false,
        )
 
        module_targets += lib
        modules_by_name += { name : lib }
 
        if not is_nss and not is_pam
                # Typically for cryptsetup token modules.
 
                name_static = name + '.standalone'
 
                link_with_static = []
                foreach obj : kwargs.get('link_with', [])
                        if obj.full_path() == libshared.full_path()
                                link_with_static += [
                                        libshared_static,
                                        libsystemd_static,
                                ]
                        else
                                link_with_static += obj
                        endif
                endforeach
 
                kwargs_static = kwargs + {
                        'sources' : [],
                        'objects' : kwargs.get('objects', []) + lib.extract_objects(dict.get('sources', [])),
                        'link_with' : link_with_static,
                        'install' : false,
                        'build_by_default' : false,
                }
 
                lib_static = shared_library(
                        name_static,
                        kwargs : kwargs_static,
                        implicit_include_directories : false,
                )
 
                modules_by_name += { name_static : lib_static }
        endif
 
        if is_nss
                # We cannot use shared_module because it does not support version suffix.
                # Unfortunately shared_library insists on creating the symlink…
                meson.add_install_script(sh, '-c', f'rm -f $DESTDIR@libdir@/lib@name@.so',
                                         install_tag : 'nss')
                nss_targets += lib
        endif
 
        if is_pam
                pam_targets += lib
        endif
 
        if want_tests != 'false' and (is_nss or is_pam)
                test('dlopen-' + name,
                     test_dlopen,
                     # path to dlopen must include a slash
                     args : lib.full_path(),
                     depends : lib,
                     suite : is_nss ? 'nss' : 'pam')
        endif
endforeach
 
# We need the actual targets to build aliases
if nss_targets.length() > 0
        alias_target('nss', nss_targets)
endif
if pam_targets.length() > 0
        alias_target('pam', pam_targets)
endif
 
#####################################################################
 
ukify_depends = []
 
foreach executable : ['systemd-measure', 'systemd-sbsign', 'systemd-keyutil']
        if executable in executables_by_name
                ukify_depends += [executables_by_name[executable]]
        endif
endforeach
 
ukify = custom_target(
        input : 'src/ukify/ukify.py',
        output : 'ukify',
        command : [jinja2_cmdline, '@INPUT@', '@OUTPUT@'],
        install : want_ukify,
        install_mode : 'rwxr-xr-x',
        depends : ukify_depends,
        install_dir : bindir)
if want_ukify
        public_programs += ukify
 
        # symlink for backwards compatibility after rename
        install_symlink('ukify',
                        pointing_to : libexecdir_to_bin / 'ukify',
                        install_dir : libexecdir)
endif
 
#####################################################################
 
mkosi = find_program('mkosi', required : false)
mkosi_depends = public_programs
 
foreach executable : ['systemd-journal-remote', 'systemd-sbsign', 'systemd-keyutil']
        if executable in executables_by_name
                mkosi_depends += [executables_by_name[executable]]
        endif
endforeach
 
if mkosi.found()
        custom_target(
                build_always_stale : true,
                build_by_default: false,
                console : true,
                output : 'mkosi',
                command : [
                        mkosi,
                        '--directory', meson.current_source_dir(),
                        '--output-dir', meson.current_build_dir() / 'mkosi.output',
                        '--cache-dir', meson.current_build_dir() / 'mkosi.cache',
                        '--build-dir', meson.current_build_dir() / 'mkosi.builddir',
                        '--extra-search-path', meson.current_build_dir(),
                        '--force',
                        'build',
                ],
                depends : mkosi_depends,
        )
endif
 
if install_tests
        install_subdir('mkosi',
                       install_dir : testsdir,
                       exclude_files : ['mkosi.local.conf', 'mkosi.key', 'mkosi.crt'],
                       exclude_directories : ['mkosi.local', 'mkosi.tools'])
endif
 
############################################################
 
subdir('rules.d')
subdir('test')
 
#####################################################################
 
subdir('docs/var-log')
subdir('hostname-wordlist')
subdir('hwdb.d')
subdir('man')
subdir('modprobe.d')
subdir('network')
subdir('presets')
subdir('profile.d')
subdir('shell-completion/bash')
subdir('shell-completion/zsh')
subdir('sysctl.d')
subdir('sysusers.d')
subdir('tmpfiles.d')
 
install_subdir('factory/etc',
               install_dir : factorydir)
subdir('factory/templates')
 
if install_sysconfdir
        install_data('xorg/50-systemd-user.sh',
                     install_dir : xinitrcdir)
endif
install_data('LICENSE.GPL2',
             'LICENSE.LGPL2.1',
             'NEWS',
             'README',
             'docs/ENVIRONMENT.md',
             'docs/TRANSIENT-SETTINGS.md',
             'docs/UIDS-GIDS.md',
             install_dir : docdir)
 
install_subdir('LICENSES',
               install_dir : docdir)
 
#####################################################################
 
# Ensure that changes to the docs/ directory do not break the
# basic Github pages build. But only run it in developer mode,
# as it might be fragile due to changes in the tooling, and it is
# not generally useful for users.
jekyll = find_program('jekyll', required : false)
if get_option('mode') == 'developer' and want_tests != 'false' and jekyll.found()
        test('github-pages',
             jekyll,
             suite : 'dist',
             args : ['build',
                     '--source', meson.project_source_root() / 'docs',
                     '--destination', meson.project_build_root() / '_site'])
endif
 
#####################################################################
 
foreach exec : public_programs
        name = fs.name(exec.full_path())
        if want_tests != 'false'
                test('check-version-' + name,
                     check_version_sh,
                     suite : 'dist',
                     args : [exec.full_path(),
                             project_major_version],
                     depends: exec)
 
                if not name.endswith('.standalone')
                        test('check-help-' + name,
                             check_help_sh,
                             suite : 'dist',
                             args : exec.full_path(),
                             depends: exec)
                endif
        endif
endforeach
 
#####################################################################
 
if git.found()
        all_files = run_command(
                env, '-u', 'GIT_WORK_TREE',
                git, '--git-dir=@0@/.git'.format(meson.project_source_root()),
                     'ls-files', ':/*.[ch]', ':/*.cc',
                check : false)
        if all_files.returncode() == 0
                existing_files = []
                foreach f : all_files.stdout().split()
                        if fs.exists(f)
                                existing_files += f
                        endif
                endforeach
                all_files = files(existing_files)
 
                custom_target(
                        output : 'tags',
                        command : [env, 'etags', '-o', '@0@/TAGS'.format(meson.project_source_root())] + all_files)
                run_target(
                        'ctags',
                        command : [env, 'ctags', '--tag-relative=never', '-o', '@0@/tags'.format(meson.project_source_root())] + all_files)
        endif
 
        ####################################################
 
        run_target(
                'git-contrib',
                command : git_contrib_sh)
 
        ####################################################
 
        git_head = run_command(
                git, '--git-dir=@0@/.git'.format(meson.project_source_root()),
                     'rev-parse', 'HEAD',
                check : false).stdout().strip()
        git_head_short = run_command(
                git, '--git-dir=@0@/.git'.format(meson.project_source_root()),
                     'rev-parse', '--short=7', 'HEAD',
                check : false).stdout().strip()
 
        run_target(
                'git-snapshot',
                command : [git, 'archive',
                           '-o', '@0@/systemd-@1@.tar.gz'.format(meson.project_source_root(),
                                                                 git_head_short),
                           '--prefix', f'systemd-@git_head@/',
                           'HEAD'])
endif
 
#####################################################################
 
alias_target('gensources', generated_sources)
 
clang_tidy = find_program('clang-tidy', required : false)
if meson.version().version_compare('>=1.4.0')
        uniq = {}
 
        foreach source : sources
                if source.full_path() in uniq
                        continue
                endif
                uniq += {source.full_path(): source}
        endforeach
 
        # TODO: Use uniq.values() when we can rely on meson 1.10.0.
        sources = []
        foreach path, file : uniq
                sources += [file]
        endforeach
 
        foreach source : sources
                if systemd_headers.contains(source)
                        continue
                endif
 
                if not source.full_path().endswith('.c') and not source.full_path().endswith('.h')
                        continue
                endif
 
                inputs = [source]
 
                header = source.full_path().replace('.c', '.h')
                if fs.exists(header) and header != source.full_path() and header != libudev_h_path
                        inputs += header
                endif
 
                # Generated sources are in the build directory, which is often build/ below the
                # source directory. Relative to the source directory, the path of a generated
                # source starts with build/ instead of src/ and gets no clang-tidy-<directory> suite.
                root = meson.project_source_root()
                if source.full_path().startswith(meson.project_build_root() + '/')
                        root = meson.project_build_root()
                endif
 
                suites = ['clang-tidy']
                parts = fs.relative_to(source.full_path(), root).split('/')
                if parts.length() > 2 and parts[0] == 'src'
                        suites += 'clang-tidy-@0@'.format(parts[1])
                endif
 
                foreach input : inputs
                        if clang_tidy.found()
                                test(
                                        'clang-tidy-@0@'.format(fs.name(input)),
                                        clang_tidy,
                                        args : ['-p', meson.project_build_root(), input],
                                        suite : suites,
                                        depends : generated_sources,
                                )
                        endif
                endforeach
        endforeach
endif
 
spatch = find_program('spatch', required : false)
if spatch.found()
        coccinelle_exclude = [
                # libc/ has no assert() or systemd-headers so leave it
                'src/libc/',
                # test/ has some deliberate wonky pointers, just leave excluded
                'src/test/',
        ]
 
        coccinelle_src_dirs = run_command(
                'sh', '-c', 'printf "%s\n" src/*/',
                check : true,
        ).stdout().strip().split('\n')
 
        foreach dir : coccinelle_src_dirs
                if dir not in coccinelle_exclude
                        test(
                                'coccinelle-@0@'.format(fs.name(dir.strip('/'))),
                                check_coccinelle_sh,
                                args : [meson.project_source_root() / dir,
                                        meson.project_source_root() / 'coccinelle'],
                                suite : 'coccinelle',
                                timeout : 300,
                        )
                endif
        endforeach
endif
 
if want_tests != 'false' and conf.get('BUILD_MODE_DEVELOPER') == 1
        symbol_analysis_exes = []
        foreach name, exe : executables_by_name
                symbol_analysis_exes += exe
        endforeach
 
        test(
                'libshared-unused-symbols',
                find_unused_library_symbols_py,
                suite : 'unused-symbols',
                args : [libshared, libcore] + nss_targets + pam_targets + symbol_analysis_exes,
        )
endif
 
run_target(
        'check-api-docs',
        depends : [man, libsystemd, libudev],
        command : [check_api_docs_sh,
                   libsystemd.full_path(),
                   libudev.full_path()])
 
alias_target('man', man)
alias_target('html', html)
alias_target('update-dbus-docs', update_dbus_docs)
alias_target('update-man-rules', update_man_rules)
 
if not meson.is_cross_build()
        custom_target(
                'export-dbus-interfaces',
                output : fs.name(dbus_interfaces_dir),
                install : dbus_interfaces_dir != 'no',
                install_dir : fs.parent(dbus_interfaces_dir),
                command : [dbus_exporter_py, '@OUTPUT@', dbus_programs])
endif
 
custom_target(
        output : 'installed-unit-files.txt',
        capture : true,
        install : want_tests != 'no' and install_tests,
        install_dir : testdata_dir,
        command : [meson_extract_unit_files_py,
                   meson.project_build_root()])
 
#####################################################################
 
udev_targets = []
foreach bin : udev_binaries
        udev_targets += executables_by_name.get(bin, [])
endforeach
alias_target('udev', buildable_rules, udev_targets, udev_units)
 
if conf.get('ENABLE_HWDB') == 1
        alias_target('hwdb', auto_suspend_rules, executables_by_name.get('systemd-hwdb'), hwdb_units)
endif
 
alt_time_epoch = run_command('date', '-Is', '-u', '-d', f'@@time_epoch@', check : false)
if alt_time_epoch.returncode() != 0
        # If the above fails, maybe the date(1) uses BSD-style syntax
        alt_time_epoch = run_command('date', '-Iseconds', '-u', '-r', f'@time_epoch@', check : true)
endif
alt_time_epoch = alt_time_epoch.stdout().strip()
 
summary({
        'split bin-sbin'                            : split_bin,
        'prefix directory'                          : prefixdir,
        'sysconf directory'                         : sysconfdir,
        'include directory'                         : includedir,
        'lib directory'                             : libdir,
        'PAM modules directory'                     : pamlibdir,
        'PAM configuration directory'               : pamconfdir,
        'ssh server configuration directory'        : sshdconfdir,