]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
meson: avoid double compilation for standalone progs 40148/head
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 16 Dec 2025 16:38:44 +0000 (17:38 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 19 Dec 2025 12:15:49 +0000 (13:15 +0100)
So far we compiled the normal and standalone versions completely
independently. Let's use the 'extract' template pattern to avoid any
additional compilation and only require an single link to produce the
.standalone variants.

Unfortunately, as designed, the 'extract' framework only allows one set of
object files to be extracted. Since we need all the files for the
.standalone version, we cannot use 'extract' for other purposes. Thus, in
the two cases where 'extract' was used for the test binaries, this is now
changed to compile the files a second time. But the number of files in that
list is small, so this seems like a better option.

(If we weren't using the template system, we could easily extract just the
objects we need. But with the current system, at the point of the
definition, the binaries are not defined yet. We'd need to handle all of
this through sets of dictionaries, and that just seems like too much
trouble to avoid double compilation of a few small files.)

meson.build
src/repart/meson.build
src/shutdown/meson.build
src/sysusers/meson.build
src/tmpfiles/meson.build

index 37ee1c81ebe2be34405f66405f515a4f1c968e81..5f9f8adb9bae524a627fc7dd6a7a5903ae32c6fe 100644 (file)
@@ -2548,7 +2548,7 @@ foreach dict : executables
         endforeach
 
         include_directories = dict['include_directories']
-        if not is_test
+        if not is_test and exe_sources.length() > 0
                 include_directories += fs.parent(exe_sources[0])
         endif
 
index de0c8902d9fd688e8840e583e3d73dbce9d980ac..e6e32f54c7a25abbb8b5b3638e993c5a0e257ecd 100644 (file)
@@ -8,7 +8,7 @@ executables += [
         executable_template + {
                 'name' : 'systemd-repart',
                 'public' : true,
-                'sources' : files('repart.c'),
+                'extract' : files('repart.c'),
                 'link_with' : [
                         libshared,
                         libshared_fdisk,
@@ -24,7 +24,7 @@ executables += [
         executable_template + {
                 'name' : 'systemd-repart.standalone',
                 'public' : true,
-                'sources' : files('repart.c'),
+                'objects' : ['systemd-repart'],
                 'link_with' : [
                         libc_wrapper_static,
                         libbasic_static,
index f5ccdbd8dd655222f1c1a8076d0e6a7476f579dd..709b0fa69257d9893f4804f096d6ae5f7c41ec80 100644 (file)
@@ -4,13 +4,7 @@ if conf.get('HAVE_LIBMOUNT') != 1
         subdir_done()
 endif
 
-systemd_shutdown_sources = files(
-        'detach-dm.c',
-        'detach-loopback.c',
-        'detach-md.c',
-        'shutdown.c',
-)
-systemd_shutdown_extract_sources = files(
+shutdown_detach_sources = files(
         'detach-swap.c',
         'umount.c',
 )
@@ -18,13 +12,17 @@ systemd_shutdown_extract_sources = files(
 executables += [
         libexec_template + {
                 'name' : 'systemd-shutdown',
-                'sources' : systemd_shutdown_sources,
-                'extract' : systemd_shutdown_extract_sources,
+                'extract' : files(
+                        'detach-dm.c',
+                        'detach-loopback.c',
+                        'detach-md.c',
+                        'shutdown.c',
+                ) + shutdown_detach_sources,
                 'dependencies' : libmount_cflags,
         },
         libexec_template + {
                 'name' : 'systemd-shutdown.standalone',
-                'sources' : systemd_shutdown_sources + systemd_shutdown_extract_sources,
+                'objects' : ['systemd-shutdown'],
                 'link_with' : [
                         libc_wrapper_static,
                         libbasic_static,
@@ -34,8 +32,8 @@ executables += [
                 'dependencies' : libmount_cflags,
         },
         test_template + {
-                'sources' : files('test-umount.c'),
-                'objects' : ['systemd-shutdown'],
+                'sources' : files('test-umount.c') +
+                            shutdown_detach_sources,
                 'dependencies' : libmount_cflags,
         },
 ]
index bbfd846e329b296564a273dd26e2a007fc3d1acf..b74ac6aa1a8c4fb7f32345f1cb72878fcd642608 100644 (file)
@@ -8,13 +8,13 @@ executables += [
         executable_template + {
                 'name' : 'systemd-sysusers',
                 'public' : true,
-                'sources' : files('sysusers.c'),
+                'extract' : files('sysusers.c'),
                 'dependencies' : libaudit_cflags,
         },
         executable_template + {
                 'name' : 'systemd-sysusers.standalone',
                 'public' : true,
-                'sources' : files('sysusers.c'),
+                'objects' : ['systemd-sysusers'],
                 'link_with' : [
                         libc_wrapper_static,
                         libbasic_static,
index 05a3171c2d0b7e7eadddcee28d8c4c5bff08022f..2a7728c295533dd40105321948a00b1041d60150 100644 (file)
@@ -4,25 +4,20 @@ if conf.get('ENABLE_TMPFILES') != 1
         subdir_done()
 endif
 
-systemd_tmpfiles_sources = files(
-        'tmpfiles.c',
-)
-systemd_tmpfiles_extract_sources = files(
-        'offline-passwd.c',
-)
+offline_passwd_c = files('offline-passwd.c')
 
 executables += [
         executable_template + {
                 'name' : 'systemd-tmpfiles',
                 'public' : true,
-                'sources' : systemd_tmpfiles_sources,
-                'extract' : systemd_tmpfiles_extract_sources,
+                'extract' : files('tmpfiles.c') +
+                            offline_passwd_c,
                 'dependencies' : libacl_cflags,
         },
         executable_template + {
                 'name' : 'systemd-tmpfiles.standalone',
                 'public' : true,
-                'sources' : systemd_tmpfiles_sources + systemd_tmpfiles_extract_sources,
+                'objects' : ['systemd-tmpfiles'],
                 'link_with' : [
                         libc_wrapper_static,
                         libbasic_static,
@@ -32,7 +27,7 @@ executables += [
                 'dependencies' : libacl_cflags,
         },
         test_template + {
-                'sources' : files('test-offline-passwd.c'),
-                'objects' : ['systemd-tmpfiles'],
+                'sources' : files('test-offline-passwd.c') +
+                            offline_passwd_c,
         },
 ]