From 0e8dbcd49059f8abbe79dc82de9bdef758a7eb47 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Mon, 19 Feb 2024 15:18:35 -0500 Subject: [PATCH] build: factor out `pluginarchive` function to `src/Makefile.common.inc` A subsequent patch will need to bundle a plugin in a test executable, requiring the same command line used by the CLI to bundle plugins in the `babeltrace2` executable, when `--enable-built-in-plugins` is used. Move the `pluginarchive` "function" and `PLUGINS_PATH` definition to a new file, `src/Makefile.common.inc`, and include that file from `src/cli/Makefile.am`. Change-Id: I36a8d6191deb82e5bceab3f5b038f69626ecdfe2 Signed-off-by: Simon Marchi Reviewed-on: https://review.lttng.org/c/babeltrace/+/11830 Tested-by: jenkins Reviewed-by: Michael Jeanson Reviewed-by: Philippe Proulx --- src/Makefile.common.inc | 21 +++++++++++++++++++++ src/cli/Makefile.am | 18 ++---------------- 2 files changed, 23 insertions(+), 16 deletions(-) create mode 100644 src/Makefile.common.inc diff --git a/src/Makefile.common.inc b/src/Makefile.common.inc new file mode 100644 index 00000000..0d71e95f --- /dev/null +++ b/src/Makefile.common.inc @@ -0,0 +1,21 @@ +# SPDX-FileCopyrightText: 2017-2024 EfficiOS, Inc. +# SPDX-License-Identifier: MIT + +# Path to the plugins build directory. +PLUGINS_PATH = $(abs_top_builddir)/src/plugins + +# Takes a plugin name and outputs the needed LDFLAGS to embed it. +# +# The --whole-archive option is important here. From the GNU linker's +# documentation: +# +# For each archive mentioned on the command line after the +# --whole-archive option, include every object file in the archive in +# the link, rather than searching the archive for the required object +# files. +# +# In our case, we find the plugins thanks to special sections in the +# binary that are filled by plugin objects. If the linker discards those +# symbols because the CLI does not use them directly, the CLI reports +# no plugins found (plugins are effectively not embedded). +pluginarchive = $(LD_WHOLE_ARCHIVE)$(PLUGINS_PATH)/$(1)/.libs/babeltrace-plugin-$(1).a$(LD_NO_WHOLE_ARCHIVE) diff --git a/src/cli/Makefile.am b/src/cli/Makefile.am index 4731375b..45254878 100644 --- a/src/cli/Makefile.am +++ b/src/cli/Makefile.am @@ -1,7 +1,8 @@ # SPDX-FileCopyrightText: 2019-2023 EfficiOS, Inc. # SPDX-License-Identifier: MIT -PLUGINS_PATH = $(abs_top_builddir)/src/plugins +include $(top_srcdir)/src/Makefile.common.inc + LTTNG_UTILS_PLUGIN_PATH = if ENABLE_DEBUG_INFO @@ -69,21 +70,6 @@ babeltrace2_bin_LDADD = \ $(top_builddir)/src/ctfser/libctfser.la if ENABLE_BUILT_IN_PLUGINS -# Takes a plugin name and outputs the needed LDFLAGS to embed it. -# -# The --whole-archive option is important here. From the GNU linker's -# documentation: -# -# For each archive mentioned on the command line after the -# --whole-archive option, include every object file in the archive in -# the link, rather than searching the archive for the required object -# files. -# -# In our case, we find the plugins thanks to special sections in the -# binary that are filled by plugin objects. If the linker discards those -# symbols because the CLI does not use them directly, the CLI reports -# no plugins found (plugins are effectively not embedded). -pluginarchive = $(LD_WHOLE_ARCHIVE)$(PLUGINS_PATH)/$(1)/.libs/babeltrace-plugin-$(1).a$(LD_NO_WHOLE_ARCHIVE) # Built-in plugins babeltrace2_bin_LDFLAGS += $(call pluginarchive,ctf) -- 2.34.1