From: Zbigniew Jędrzejewski-Szmek Date: Tue, 16 Dec 2025 16:38:44 +0000 (+0100) Subject: meson: avoid double compilation for standalone progs X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F40148%2Fhead;p=thirdparty%2Fsystemd.git meson: avoid double compilation for standalone progs 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.) --- diff --git a/meson.build b/meson.build index 37ee1c81ebe..5f9f8adb9ba 100644 --- a/meson.build +++ b/meson.build @@ -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 diff --git a/src/repart/meson.build b/src/repart/meson.build index de0c8902d9f..e6e32f54c7a 100644 --- a/src/repart/meson.build +++ b/src/repart/meson.build @@ -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, diff --git a/src/shutdown/meson.build b/src/shutdown/meson.build index f5ccdbd8dd6..709b0fa6925 100644 --- a/src/shutdown/meson.build +++ b/src/shutdown/meson.build @@ -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, }, ] diff --git a/src/sysusers/meson.build b/src/sysusers/meson.build index bbfd846e329..b74ac6aa1a8 100644 --- a/src/sysusers/meson.build +++ b/src/sysusers/meson.build @@ -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, diff --git a/src/tmpfiles/meson.build b/src/tmpfiles/meson.build index 05a3171c2d0..2a7728c2955 100644 --- a/src/tmpfiles/meson.build +++ b/src/tmpfiles/meson.build @@ -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, }, ]