All of lore.kernel.org
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: linux-trace-devel@vger.kernel.org
Subject: [PATCH 05/12] libtracecmd: Update ld.so.conf.d/trace.conf if needed
Date: Tue, 15 Dec 2020 23:41:55 -0500	[thread overview]
Message-ID: <20201216044213.730082526@goodmis.org> (raw)
In-Reply-To: 20201216044150.375001748@goodmis.org

From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>

If DESTDIR is not defined (building for the current machine) check if after
installing libtracecmd, if it is in the ld.so path by building a test
program and running it, and making sure that the dynamic linker works, and
if not, then update /etc/ld.so.conf.d/trace.conf to include the path to
libtracecmd.so.

Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
 Makefile               |  6 +++++-
 lib/trace-cmd/Makefile | 26 ++++++++++++++++++++++++++
 lib/trace-cmd/test.c   |  7 +++++++
 3 files changed, 38 insertions(+), 1 deletion(-)
 create mode 100644 lib/trace-cmd/test.c

diff --git a/Makefile b/Makefile
index e956a2e6e8b6..101820733862 100644
--- a/Makefile
+++ b/Makefile
@@ -37,6 +37,10 @@ endef
 $(call allow-override,CC,$(CROSS_COMPILE)gcc)
 $(call allow-override,AR,$(CROSS_COMPILE)ar)
 $(call allow-override,PKG_CONFIG,pkg-config)
+$(call allow-override,LD_SO_CONF_PATH,/etc/ld.so.conf.d/)
+$(call allow-override,LDCONFIG,ldconfig)
+
+export LD_SO_CONF_PATH LDCONFIG
 
 EXT = -std=gnu99
 INSTALL = install
@@ -76,7 +80,7 @@ etcdir ?= /etc
 etcdir_SQ = '$(subst ','\'',$(etcdir))'
 
 export man_dir man_dir_SQ html_install html_install_SQ INSTALL
-export img_install img_install_SQ libdir_SQ includedir_SQ
+export img_install img_install_SQ libdir libdir_SQ includedir_SQ
 export DESTDIR DESTDIR_SQ
 
 ifeq ($(prefix),$(HOME))
diff --git a/lib/trace-cmd/Makefile b/lib/trace-cmd/Makefile
index 75e4fea4e3e0..a26b989a2c82 100644
--- a/lib/trace-cmd/Makefile
+++ b/lib/trace-cmd/Makefile
@@ -3,6 +3,7 @@
 include $(src)/scripts/utils.mk
 
 bdir:=$(obj)/lib/trace-cmd
+ldir:=$(src)/lib/trace-cmd
 
 DEFAULT_TARGET = $(LIBTRACECMD_STATIC)
 
@@ -59,11 +60,36 @@ $(DEPS): $(bdir)/.%.d: %.c
 
 $(OBJS): $(bdir)/%.o : $(bdir)/.%.d
 
+ifeq ("$(DESTDIR)", "")
+# If DESTDIR is not defined, then test if after installing the library
+# and running ldconfig, if the library is visible by ld.so.
+# If not, add the path to /etc/ld.so.conf.d/trace.conf and run ldconfig again.
+define install_ld_config
+	$(LDCONFIG); \
+	if ! grep "^$(libdir)$$" $(LD_SO_CONF_PATH)/* &> /dev/null ; then \
+		$(CC) -o $(bdir)/test $(ldir)/test.c -I $(includedir_SQ) \
+			-L $(libdir_SQ) -ltracecmd > /dev/null; \
+		if ! $(bdir)/test &> /dev/null; then \
+			$(call print_install,trace.conf,$(LD_SO_CONF_PATH)) \
+			echo $(libdir_SQ) >> $(LD_SO_CONF_PATH)/trace.conf; \
+			$(LDCONFIG); \
+		fi; \
+		$(RM) $(bdir)/test; \
+	fi
+endef
+else
+# If installing to a location for another machine or package, do not bother
+# with running ldconfig.
+define install_ld_config
+endef
+endif # DESTDIR = ""
+
 install_libs:
 	$(Q)$(call do_install,$(LIBTRACECMD_SHARED),$(libdir_SQ))
 	cp -fpR $(LIBTRACECMD_SHARED_VERSION) $(DESTDIR)$(libdir_SQ)
 	cp -fpR $(LIBTRACECMD_SHARED_SO) $(DESTDIR)$(libdir_SQ)
 	$(Q)$(call do_install,$(src)/include/trace-cmd/trace-cmd.h,$(includedir_SQ)/trace-cmd)
+	$(Q)$(call install_ld_config)
 
 dep_includes := $(wildcard $(DEPS))
 
diff --git a/lib/trace-cmd/test.c b/lib/trace-cmd/test.c
new file mode 100644
index 000000000000..5622d79c86c5
--- /dev/null
+++ b/lib/trace-cmd/test.c
@@ -0,0 +1,7 @@
+#include <trace-cmd/trace-cmd.h>
+
+int main()
+{
+	tracecmd_open_head("trace.dat");
+	return 0;
+}
-- 
2.29.2



  parent reply	other threads:[~2020-12-16  4:43 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-16  4:41 [PATCH 00/12] trace-cmd: Updates to the Makefile Steven Rostedt
2020-12-16  4:41 ` [PATCH 01/12] trace-cmd: Move do_make_pkgconfig_file to utils.mk Steven Rostedt
2020-12-16  4:41 ` [PATCH 02/12] trace-cmd: Have etcdir always be at the root directory Steven Rostedt
2020-12-16  4:41 ` [PATCH 03/12] trace-cmd: Remove unused variable LD_SO_CONF_DIR Steven Rostedt
2020-12-16  4:41 ` [PATCH 04/12] trace-cmd: Use the LIBTRACE{EVENT,FS}_LIBS for building libtracecmd.so Steven Rostedt
2020-12-16  4:41 ` Steven Rostedt [this message]
2020-12-16  4:41 ` [PATCH 06/12] libtracecmd: Make installing show a nice INSTALL output Steven Rostedt
2020-12-16  4:41 ` [PATCH 07/12] libtracecmd: Build libtracecmd.pc when building the library Steven Rostedt
2020-12-16  4:41 ` [PATCH 08/12] libtracecmd: Show building of libtracecmd.pc Steven Rostedt
2020-12-16  4:41 ` [PATCH 09/12] libtracecmd: Install libtracecmd.pc when installing libs Steven Rostedt
2020-12-16  4:42 ` [PATCH 10/12] trace-cmd: Add make uninstall Steven Rostedt
2020-12-16  4:42 ` [PATCH 11/12] trace-cmd: Update libtracecmd.pc if prefix is different Steven Rostedt
2020-12-16  4:42 ` [PATCH 12/12] trace-cmd: Keep build_install files around Steven Rostedt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201216044213.730082526@goodmis.org \
    --to=rostedt@goodmis.org \
    --cc=linux-trace-devel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.