]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
meson: introduce infra to build executables and shared libraries by using dictionary
authorYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 23 Jun 2023 02:09:10 +0000 (11:09 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 31 Jul 2023 13:17:34 +0000 (22:17 +0900)
That is not used yet. It will be used later.

meson.build

index 379eeda9e42f0ce0d05c57f1014203cdb9fb2457..3753d1909471d908aac24b4e89a4eceb3f576fa0 100644 (file)
@@ -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(