]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
meson: allow manager to be linked statically
authorZbigniew Jędrzejewski-Szmek <zbyszek@amutable.com>
Tue, 30 Jun 2026 12:06:28 +0000 (14:06 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@amutable.com>
Thu, 2 Jul 2026 15:19:18 +0000 (17:19 +0200)
After stripping, in an unoptimized build with glibc, we get a 8.7 MB binary:
$ file build-static/systemd
build-static/systemd: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), statically linked, BuildID[sha1]=1ec004bf61b775d284d909a818a3c4f63f83f055, for GNU/Linux 3.2.0, stripped
$ ls -lh build-static/systemd
-rwxr-xr-x 1 zbyszek zbyszek 8.7M Jun 30 14:07 build-static/systemd

src/core/meson.build

index 3708caf4e0bbaab953d0457a5bc0c6b7052542e7..2d3ed4cff2a6ad2af7be9e105d4cba53e06abf33 100644 (file)
@@ -209,6 +209,9 @@ systemd_deps = [
         libselinux_cflags,
 ]
 
+systemd_link_args = get_option('build-static') ? ['-static'] : []
+systemd_libs = get_option('build-static') ? core_libs_static : core_libs_shared
+
 executor_libs = get_option('link-executor-shared') ? core_libs_shared : core_libs_static
 
 if conf.get('SYSTEMD_MULTICALL_BINARY') == 1
@@ -226,7 +229,8 @@ executables += [
                 'dbus' : true,
                 'public' : true,
                 'sources' : systemd_sources,
-                'link_with' : core_libs_shared,
+                'link_args' : systemd_link_args,
+                'link_with' : systemd_libs,
                 'dependencies' : systemd_deps,
         },