From c335921e136d9bf4c2ae90c3c16ab8bb045b5a57 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Fri, 23 Jun 2023 11:09:10 +0900 Subject: [PATCH] meson: introduce infra to build executables and shared libraries by using dictionary That is not used yet. It will be used later. --- meson.build | 166 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 166 insertions(+) diff --git a/meson.build b/meson.build index 379eeda9e4..3753d19094 100644 --- a/meson.build +++ b/meson.build @@ -2174,6 +2174,9 @@ simple_tests = [] fuzzers = [] simple_fuzzers = [] catalogs = [] +modules = [] # nss, pam, and other plugins +executables = [] +executables_by_name = {} # binaries that have --help and are intended for use by humans, # usually, but not always, installed in /bin. @@ -2355,6 +2358,68 @@ endif ############################################################ +executable_template = { + 'include_directories' : includes, + 'link_with' : libshared, + 'install_rpath' : pkglibdir, + 'install' : true, +} + +generator_template = executable_template + { + 'install_dir' : systemgeneratordir, +} + +libexec_template = executable_template + { + 'install_dir' : libexecdir, +} + +executable_additional_kwargs = { + 'dependencies' : userspace, +} + +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' : [ + libsystemd_static, + libshared_static, + libbasic, + ], + 'dependencies' : [ + librt, + threads, + ], + 'install' : true, + 'install_tag' : 'nss', + 'install_dir' : libdir, +} + +pam_template = { + 'name_prefix' : '', + 'include_directories' : includes, + 'link_with' : [ + libsystemd_static, + libshared_static, + ], + 'dependencies' : [ + libpam_misc, + libpam, + threads, + ], + 'install' : true, + 'install_tag' : 'pam', + 'install_dir' : pamlibdir, +} + +module_additional_kwargs = { + 'link_args' : ['-shared'], + 'dependencies' : userspace, +} + +############################################################ + # systemd-analyze requires 'libcore' subdir('src/core') # systemd-journal-remote requires 'libjournal_core' @@ -2407,6 +2472,51 @@ alias_target('devel', libsystemd_pc, libudev_pc, systemd_pc, udev_pc) ############################################################ +foreach dict : executables + name = dict.get('name') + + 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', 'dbus', 'public', 'conditions'] + continue + endif + kwargs += { key : val } + endforeach + + foreach key, val : executable_additional_kwargs + kwargs += { key : [ kwargs.get(key, []), val ]} + endforeach + + exe = executable( + name, + kwargs : kwargs, + ) + + executables_by_name += { name : exe } + + if dict.get('build_by_default', true) + if dict.get('dbus', false) + dbus_programs += exe + endif + if dict.get('public', false) + public_programs += exe + endif + endif +endforeach + +############################################################ + # only static linking apart from libdl, to make sure that the # module is linked to all libraries that it uses. test_dlopen = executable( @@ -2477,6 +2587,62 @@ foreach tuple : [['myhostname', 'ENABLE_NSS_MYHOSTNAME'], endif endforeach +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'] + continue + endif + kwargs += { key : val } + endforeach + + sym = meson.current_source_dir() / '@0@'.format(dict.get('link_depends')[0]) + kwargs += { + 'link_args' : [ + kwargs.get('link_args', []), + '-Wl,--version-script=' + sym, + ], + } + foreach key, val : module_additional_kwargs + kwargs += { key : [ kwargs.get(key, []), val ]} + endforeach + + lib = shared_library( + name, + kwargs : kwargs, + ) + + 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', 'rm $DESTDIR@0@/lib@1@.so'.format(libdir, name), + install_tag : 'nss') + 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) + endif +endforeach + ############################################################ exe = executable(