From 4c3c60c27099e7cbf9ac6fe86540b3c4e03f7650 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Mon, 1 Dec 2025 14:37:22 +0100 Subject: [PATCH 1/3] meson: reuse variable in one more place --- src/core/meson.build | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/core/meson.build b/src/core/meson.build index fbadd0f6a6..1fa0e68496 100644 --- a/src/core/meson.build +++ b/src/core/meson.build @@ -125,11 +125,12 @@ generated_sources += [load_fragment_gperf_c, load_fragment_gperf_nulstr_c, bpf_d libcore_sources += [load_fragment_gperf_c, load_fragment_gperf_nulstr_c, bpf_delegate_configs_inc] libcore_build_dir = meson.current_build_dir() libcore_name = 'systemd-core-@0@'.format(shared_lib_tag) +core_includes = [includes, include_directories('.')] libcore_static = static_library( libcore_name, libcore_sources, - include_directories : [includes, include_directories('.')], + include_directories : core_includes, implicit_include_directories : false, c_args : ['-fvisibility=default'], dependencies : [libaudit_cflags, @@ -155,8 +156,6 @@ libcore = shared_library( install : true, install_dir : pkglibdir) -core_includes = [includes, include_directories('.')] - systemd_sources = files( 'main.c', 'crash-handler.c', From 963bebd7b0e688fb1a66199ad28a12046d7ad8ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Mon, 1 Dec 2025 15:35:22 +0100 Subject: [PATCH 2/3] meson: add source dir to include_directories automatically Quite often we need to specify include_directories('.'). Normally, meson does this automatically, but we specify implicit_include_directories : false, see 30d20907bddfe064cc3437a888dd8f00d14929e4 for an explanation. Passing the include_directories argument through the template layers was rather cumbersome. Let's simplify things by always including the directory of the first source file. This makes the definitions simpler, at the cost of having an unnecessary include directory in the list in some cases. (Tests are excluded from this change, because they happen to not need this, but also because some tests have source[0] which is a custom target, and we'd need newer meson to support that.) --- meson.build | 23 ++++++++++++----------- src/core/meson.build | 1 - src/coredump/meson.build | 1 - src/home/meson.build | 2 -- src/journal/meson.build | 1 - src/login/meson.build | 1 - src/nsresourced/meson.build | 1 - src/resolve/meson.build | 1 - src/sleep/meson.build | 1 - src/timesync/meson.build | 1 - 10 files changed, 12 insertions(+), 21 deletions(-) diff --git a/meson.build b/meson.build index 8b08bb3178..85b8d1b407 100644 --- a/meson.build +++ b/meson.build @@ -2334,7 +2334,6 @@ else } endif fuzz_additional_kwargs += { - 'include_directories' : include_directories('src/fuzz'), 'c_args' : test_cflags, } @@ -2565,9 +2564,9 @@ foreach dict : executables kwargs = {} foreach key, val : dict - if key in ['name', 'dbus', 'public', 'conditions', - 'type', 'suite', 'timeout', 'parallel', - 'objects', 'sources', 'extract'] + if key in ['name', 'dbus', 'public', 'conditions', 'type', 'suite', + 'timeout', 'parallel', 'objects', 'sources', 'extract', + 'include_directories'] continue endif @@ -2578,15 +2577,15 @@ foreach dict : executables kwargs += { key : [ kwargs.get(key, []), val ]} endforeach + include_directories = dict['include_directories'] + if not is_test + include_directories += fs.parent(exe_sources[0]) + endif + foreach val : dict.get('objects', []) obj = objects_by_name[val] - kwargs += { - 'objects' : obj['objects'], - 'include_directories' : [ - kwargs.get('include_directories', []), - obj['include_directories'], - ], - } + kwargs += { 'objects' : obj['objects'] } + include_directories += obj['include_directories'] endforeach if is_test @@ -2597,6 +2596,7 @@ foreach dict : executables endif if is_fuzz + include_directories += include_directories('src/fuzz') foreach key, val : fuzz_additional_kwargs if key == 'sources' exe_sources += val @@ -2611,6 +2611,7 @@ foreach dict : executables sources : exe_sources, kwargs : kwargs, implicit_include_directories : false, + include_directories : include_directories, ) executables_by_name += { name : exe } diff --git a/src/core/meson.build b/src/core/meson.build index 1fa0e68496..11f19ad1f4 100644 --- a/src/core/meson.build +++ b/src/core/meson.build @@ -207,7 +207,6 @@ executables += [ 'name' : 'systemd-executor', 'public' : true, 'sources' : systemd_executor_sources, - 'include_directories' : core_includes, 'link_with' : executor_libs, 'dependencies' : [ libapparmor_cflags, diff --git a/src/coredump/meson.build b/src/coredump/meson.build index 230eb0f3e6..355993d09e 100644 --- a/src/coredump/meson.build +++ b/src/coredump/meson.build @@ -37,7 +37,6 @@ executables += [ libexec_template + { 'name' : 'systemd-coredump', 'sources' : systemd_coredump_sources, - 'include_directories' : [libexec_template['include_directories'], include_directories('.')], 'extract' : systemd_coredump_extract_sources, 'link_with' : [libshared], 'dependencies' : common_dependencies, diff --git a/src/home/meson.build b/src/home/meson.build index f913cb75e5..dbb374ce4a 100644 --- a/src/home/meson.build +++ b/src/home/meson.build @@ -63,8 +63,6 @@ executables += [ 'dbus' : true, 'sources' : systemd_homed_sources, 'extract' : systemd_homed_extract_sources, - 'include_directories' : includes + - include_directories('.'), 'dependencies' : [ libcrypt, libm, diff --git a/src/journal/meson.build b/src/journal/meson.build index fc5f557696..1ad5c40dfa 100644 --- a/src/journal/meson.build +++ b/src/journal/meson.build @@ -66,7 +66,6 @@ executables += [ 'name' : 'systemd-journald', 'sources' : systemd_journald_sources, 'extract' : systemd_journald_extract_sources, - 'include_directories' : [libexec_template['include_directories'], include_directories('.')], 'dependencies' : [ liblz4_cflags, libselinux_cflags, diff --git a/src/login/meson.build b/src/login/meson.build index 435dcf4d27..df3c232959 100644 --- a/src/login/meson.build +++ b/src/login/meson.build @@ -47,7 +47,6 @@ executables += [ 'dbus' : true, 'sources' : systemd_logind_sources, 'extract' : systemd_logind_extract_sources, - 'include_directories' : [libexec_template['include_directories'], include_directories('.')], 'dependencies' : [ threads, ], diff --git a/src/nsresourced/meson.build b/src/nsresourced/meson.build index 4fb55f67f9..6b6ae1558c 100644 --- a/src/nsresourced/meson.build +++ b/src/nsresourced/meson.build @@ -32,7 +32,6 @@ executables += [ 'name' : 'systemd-nsresourced', 'sources' : systemd_nsresourced_sources, 'extract' : systemd_nsresourced_extract_sources, - 'include_directories' : [libexec_template['include_directories'], include_directories('.')], 'dependencies' : threads, }, libexec_template + { diff --git a/src/resolve/meson.build b/src/resolve/meson.build index b32e9526c8..49ac293f51 100644 --- a/src/resolve/meson.build +++ b/src/resolve/meson.build @@ -83,7 +83,6 @@ executables += [ 'dbus' : true, 'sources' : systemd_resolved_sources, 'extract' : systemd_resolved_extract_sources, - 'include_directories' : [libexec_template['include_directories'], include_directories('.')], }, executable_template + resolve_common_template + { 'name' : 'resolvectl', diff --git a/src/sleep/meson.build b/src/sleep/meson.build index ff9ea74aa2..7411aa1ceb 100644 --- a/src/sleep/meson.build +++ b/src/sleep/meson.build @@ -5,7 +5,6 @@ executables += [ 'name' : 'systemd-sleep', 'sources' : files('sleep.c'), 'extract' : files('battery-capacity.c'), - 'include_directories' : [libexec_template['include_directories'], include_directories('.')], }, test_template + { 'sources' : files('test-battery-capacity.c'), diff --git a/src/timesync/meson.build b/src/timesync/meson.build index 51e9d3f5c1..b307245772 100644 --- a/src/timesync/meson.build +++ b/src/timesync/meson.build @@ -34,7 +34,6 @@ executables += [ 'name' : 'systemd-timesyncd', 'sources' : timesyncd_sources, 'extract' : timesyncd_extract_sources, - 'include_directories' : [libexec_template['include_directories'], include_directories('.')], 'link_with' : timesyncd_link_with, 'dependencies' : [ libm, From 322f6adbcdda05f2d978a0094a5f6d41b1b9f585 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Mon, 1 Dec 2025 16:09:43 +0100 Subject: [PATCH 3/3] meson: add tools/meson.build Previously, we looked for scripts in the tools/ directory ad hoc, wherever they were needed. Let's do those checks in one place. The main meson.build file is shrunk somewhat, which is always nice. --- meson.build | 55 +++++++---------------------------------- src/version/meson.build | 2 +- tools/meson.build | 37 +++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 47 deletions(-) create mode 100644 tools/meson.build diff --git a/meson.build b/meson.build index 85b8d1b407..63b77ce2b4 100644 --- a/meson.build +++ b/meson.build @@ -79,17 +79,6 @@ summary({ ##################################################################### -# Try to install the git pre-commit hook -git_setup_sh = find_program('tools/git-setup.sh', required : false) -if git_setup_sh.found() - git_hook = run_command(git_setup_sh, check : false) - if git_hook.returncode() == 0 - message(git_hook.stdout().strip()) - endif -endif - -##################################################################### - fs = import('fs') if get_option('split-bin') == 'auto' split_bin = not fs.is_symlink('/usr/sbin') @@ -351,7 +340,6 @@ cc = meson.get_compiler('c') userspace_c_args = [] userspace_c_ld_args = [] userspace_sources = [] -meson_build_sh = files('tools/meson-build.sh') want_tests = get_option('tests') want_slow_tests = want_tests != 'false' and get_option('slow-tests') @@ -1952,10 +1940,6 @@ conf.set10('ENABLE_UKIFY', want_ukify) ##################################################################### -check_efi_alignment_py = files('tools/check-efi-alignment.py') - -##################################################################### - use_provided_vmlinux_h = false use_generated_vmlinux_h = false provided_vmlinux_h_path = get_option('vmlinux-h-path') @@ -2027,24 +2011,6 @@ conf.set10('ENABLE_SYSCTL_BPF', conf.get('HAVE_VMLINUX_H') == 1 and libbpf.versi ##################################################################### -check_version_history_py = files('tools/check-version-history.py') -elf2efi_py = files('tools/elf2efi.py') -export_dbus_interfaces_py = files('tools/dbus_exporter.py') -generate_gperfs = files('tools/generate-gperfs.py') -make_autosuspend_rules_py = files('tools/make-autosuspend-rules.py') -make_directive_index_py = files('tools/make-directive-index.py') -sync_docs_py = files('tools/sync-docs.py') -make_man_index_py = files('tools/make-man-index.py') -meson_render_jinja2 = files('tools/meson-render-jinja2.py') -update_dbus_docs_py = files('tools/update-dbus-docs.py') -update_hwdb_autosuspend_sh = files('tools/update-hwdb-autosuspend.sh') -update_hwdb_sh = files('tools/update-hwdb.sh') -update_man_rules_py = files('tools/update-man-rules.py') -update_syscall_tables_sh = files('tools/update-syscall-tables.sh') -xml_helper_py = files('tools/xml_helper.py') - -##################################################################### - version_tag = get_option('version-tag') if version_tag == '' version_tag = meson.project_version() @@ -2052,6 +2018,7 @@ endif conf.set_quoted('VERSION_TAG', version_tag) +subdir('tools') subdir('src/version') shared_lib_tag = get_option('shared-lib-tag') @@ -2071,7 +2038,7 @@ config_h = configure_file( userspace_c_args += ['-include', 'config.h'] -jinja2_cmdline = [meson_render_jinja2, config_h] +jinja2_cmdline = [meson_render_jinja2_py, config_h] userspace = declare_dependency( compile_args : userspace_c_args, @@ -2906,20 +2873,17 @@ endif ##################################################################### -check_help = files('tools/check-help.sh') -check_version = files('tools/check-version.sh') - foreach exec : public_programs name = fs.name(exec.full_path()) if want_tests != 'false' test('check-help-' + name, - check_help, + check_help_sh, suite : 'dist', args : exec.full_path(), depends: exec) test('check-version-' + name, - check_version, + check_version_sh, suite : 'dist', args : [exec.full_path(), project_major_version], @@ -2950,7 +2914,7 @@ if git.found() run_target( 'git-contrib', - command : files('tools/git-contrib.sh')) + command : git_contrib_sh) #################################################### @@ -3013,10 +2977,9 @@ foreach name, exe : executables_by_name symbol_analysis_exes += exe endforeach -find_unused_library_symbols = find_program('tools/find-unused-library-symbols.py') test( 'libshared-unused-symbols', - find_unused_library_symbols, + find_unused_library_symbols_py, suite : 'unused-symbols', args : [libshared, libcore] + nss_targets + pam_targets + symbol_analysis_exes, ) @@ -3024,7 +2987,7 @@ test( run_target( 'check-api-docs', depends : [man, libsystemd, libudev], - command : [files('tools/check-api-docs.sh'), + command : [check_api_docs_sh, libsystemd.full_path(), libudev.full_path()]) @@ -3039,7 +3002,7 @@ if not meson.is_cross_build() output : fs.name(dbus_interfaces_dir), install : dbus_interfaces_dir != 'no', install_dir : fs.parent(dbus_interfaces_dir), - command : [export_dbus_interfaces_py, '@OUTPUT@', dbus_programs]) + command : [dbus_exporter_py, '@OUTPUT@', dbus_programs]) endif custom_target( @@ -3047,7 +3010,7 @@ custom_target( capture : true, install : want_tests != 'no' and install_tests, install_dir : testdata_dir, - command : [files('tools/meson-extract-unit-files.py'), + command : [meson_extract_unit_files_py, meson.project_build_root()]) ##################################################################### diff --git a/src/version/meson.build b/src/version/meson.build index 03f58697b7..54db791ccf 100644 --- a/src/version/meson.build +++ b/src/version/meson.build @@ -7,7 +7,7 @@ version_h = custom_target('version', output : 'version.h', capture : true, command : [ - meson.project_source_root() / 'tools/vcs-tag.sh', + vcs_tag_sh, '@INPUT@', get_option('mode'), vcs_tag ? '1' : '0', diff --git a/tools/meson.build b/tools/meson.build new file mode 100644 index 0000000000..3132eeddba --- /dev/null +++ b/tools/meson.build @@ -0,0 +1,37 @@ +# SPDX-License-Identifier: LGPL-2.1-or-later + +check_api_docs_sh = files('check-api-docs.sh') +check_efi_alignment_py = files('check-efi-alignment.py') +check_help_sh = files('check-help.sh') +check_version_history_py = files('check-version-history.py') +check_version_sh = files('check-version.sh') +elf2efi_py = files('elf2efi.py') +dbus_exporter_py = files('dbus_exporter.py') +find_unused_library_symbols_py = files('find-unused-library-symbols.py') +generate_gperfs = files('generate-gperfs.py') +git_contrib_sh = files('git-contrib.sh') +make_autosuspend_rules_py = files('make-autosuspend-rules.py') +make_directive_index_py = files('make-directive-index.py') +make_man_index_py = files('make-man-index.py') +meson_build_sh = files('meson-build.sh') +meson_extract_unit_files_py = files('meson-extract-unit-files.py') +meson_render_jinja2_py = files('meson-render-jinja2.py') +sync_docs_py = files('sync-docs.py') +update_dbus_docs_py = files('update-dbus-docs.py') +update_hwdb_autosuspend_sh = files('update-hwdb-autosuspend.sh') +update_hwdb_sh = files('update-hwdb.sh') +update_man_rules_py = files('update-man-rules.py') +update_syscall_tables_sh = files('update-syscall-tables.sh') +vcs_tag_sh = files('vcs-tag.sh') +xml_helper_py = files('xml_helper.py') + +##################################################################### + +# Try to install the git pre-commit hook +git_setup_sh = find_program('./git-setup.sh', required : false) +if git_setup_sh.found() + git_hook = run_command(git_setup_sh, check : false) + if git_hook.returncode() == 0 + message(git_hook.stdout().strip()) + endif +endif