All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Tzvetomir Stoyanov (VMware)" <tz.stoyanov@gmail.com>
To: rostedt@goodmis.org
Cc: linux-trace-devel@vger.kernel.org
Subject: [PATCH] trace-cmd: Use system trace libraries, if available
Date: Thu, 26 Nov 2020 09:27:07 +0200	[thread overview]
Message-ID: <20201126072707.906347-1-tz.stoyanov@gmail.com> (raw)

Check if libtraceevent and libtracefs are installed in the system and
use them, otherwise build and use the local implementations.

Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
---
 Makefile                | 40 ++++++++++++++++++++++++++++------------
 lib/traceevent/Makefile |  2 ++
 lib/tracefs/Makefile    |  2 ++
 tracecmd/Makefile       |  6 ++++--
 4 files changed, 36 insertions(+), 14 deletions(-)

diff --git a/Makefile b/Makefile
index 8626b91b..c6cdeeae 100644
--- a/Makefile
+++ b/Makefile
@@ -191,6 +191,8 @@ export prefix bindir src obj kshark-dir
 
 LIBS = -ldl
 
+
+LIBTRACEEVENT=libtraceevent
 LIBTRACEEVENT_DIR = $(obj)/lib/traceevent
 LIBTRACEEVENT_STATIC = $(LIBTRACEEVENT_DIR)/libtraceevent.a
 LIBTRACEEVENT_SHARED = $(LIBTRACEEVENT_DIR)/libtraceevent.so
@@ -199,35 +201,48 @@ LIBTRACECMD_DIR = $(obj)/lib/trace-cmd
 LIBTRACECMD_STATIC = $(LIBTRACECMD_DIR)/libtracecmd.a
 LIBTRACECMD_SHARED = $(LIBTRACECMD_DIR)/libtracecmd.so
 
+LIBTRACEFS=libtracefs
 LIBTRACEFS_DIR = $(obj)/lib/tracefs
 LIBTRACEFS_STATIC = $(LIBTRACEFS_DIR)/libtracefs.a
 LIBTRACEFS_SHARED = $(LIBTRACEFS_DIR)/libtracefs.so
 
-TRACE_LIBS = -L$(LIBTRACECMD_DIR) -ltracecmd		\
-	     -L$(LIBTRACEEVENT_DIR) -ltraceevent	\
-	     -L$(LIBTRACEFS_DIR) -ltracefs
+ifeq ($(shell sh -c "pkg-config --cflags $(LIBTRACEEVENT) > /dev/null 2>&1 && echo y"), y)
+LIBTRACEEVENT_CFLAGS = $(shell sh -c "pkg-config --cflags $(LIBTRACEEVENT)")
+LIBTRACEEVENT_LDLAGS = $(shell sh -c "pkg-config --libs $(LIBTRACEEVENT)")
+else
+LIBTRACEEVENT_CFLAGS = -I$(src)/include/traceevent -I$(src)/lib/traceevent/include
+LIBTRACEEVENT_LDLAGS = -L$(LIBTRACEEVENT_DIR) -ltraceevent
+LIBTRACEEVENT_STATIC_BUILD = $(LIBTRACEEVENT_STATIC)
+endif
+
+ifeq ($(shell sh -c "pkg-config --cflags $(LIBTRACEFS) > /dev/null 2>&1 && echo y"), y)
+LIBTRACEFS_CFLAGS = $(shell sh -c "pkg-config --cflags $(LIBTRACEFS)")
+LIBTRACEFS_LDLAGS = $(shell sh -c "pkg-config --libs $(LIBTRACEFS)")
+else
+LIBTRACEFS_CFLAGS = -I$(src)/include/tracefs
+LIBTRACEFS_LDLAGS = -L$(LIBTRACEFS_DIR) -ltracefs
+LIBTRACEFS_STATIC_BUILD = $(LIBTRACEFS_STATIC)
+endif
+
+
+TRACE_LIBS = -L$(LIBTRACECMD_DIR) -ltracecmd	\
+	     $(LIBTRACEEVENT_LDLAGS) $(LIBTRACEFS_LDLAGS)
 
 export LIBS TRACE_LIBS
 export LIBTRACEEVENT_DIR LIBTRACECMD_DIR LIBTRACEFS_DIR
 export LIBTRACECMD_STATIC LIBTRACECMD_SHARED
-export LIBTRACEEVENT_STATIC LIBTRACEEVENT_SHARED
-export LIBTRACEFS_STATIC LIBTRACEFS_SHARED
-
 export Q SILENT VERBOSE EXT
 
 # Include the utils
 include scripts/utils.mk
 
 INCLUDES = -I$(src)/include -I$(src)/../../include
-INCLUDES += -I$(src)/include/traceevent
 INCLUDES += -I$(src)/include/trace-cmd
-INCLUDES += -I$(src)/include/tracefs
-INCLUDES += -I$(src)/lib/traceevent/include
 INCLUDES += -I$(src)/lib/trace-cmd/include
 INCLUDES += -I$(src)/lib/trace-cmd/include/private
-INCLUDES += -I$(src)/lib/tracefs/include
 INCLUDES += -I$(src)/tracecmd/include
-INCLUDES += -I$(obj)/tracecmd/include
+INCLUDES += $(LIBTRACEEVENT_CFLAGS)
+INCLUDES += $(LIBTRACEFS_CFLAGS)
 
 include $(src)/features.mk
 
@@ -288,6 +303,7 @@ CMD_TARGETS = trace-cmd $(BUILD_PYTHON)
 #    Default we just build trace-cmd
 #
 #    If you want kernelshark, then do:  make gui
+#    If you want all libraries, then do: make libs
 ###
 
 all: all_cmd plugins show_gui_make
@@ -309,7 +325,7 @@ gui: force
 	@echo "gui build complete"
 	@echo "  kernelshark located at $(kshark-dir)/bin"
 
-trace-cmd: force $(LIBTRACEEVENT_STATIC) $(LIBTRACECMD_STATIC) $(LIBTRACEFS_STATIC) \
+trace-cmd: force $(LIBTRACEEVENT_STATIC_BUILD) $(LIBTRACECMD_STATIC) $(LIBTRACEFS_STATIC_BUILD) \
 	force $(obj)/lib/trace-cmd/plugins/tracecmd_plugin_dir
 	$(Q)$(MAKE) -C $(src)/tracecmd $(obj)/tracecmd/$@
 
diff --git a/lib/traceevent/Makefile b/lib/traceevent/Makefile
index d0666911..c7f7cda0 100644
--- a/lib/traceevent/Makefile
+++ b/lib/traceevent/Makefile
@@ -6,6 +6,8 @@ bdir:=$(obj)/lib/traceevent
 
 DEFAULT_TARGET = $(bdir)/libtraceevent.a
 
+CFLAGS += -I$(bdir)/include
+
 OBJS =
 OBJS += event-parse.o
 OBJS += event-plugin.o
diff --git a/lib/tracefs/Makefile b/lib/tracefs/Makefile
index cbcce362..89519517 100644
--- a/lib/tracefs/Makefile
+++ b/lib/tracefs/Makefile
@@ -6,6 +6,8 @@ bdir:=$(obj)/lib/tracefs
 
 DEFAULT_TARGET = $(bdir)/libtracefs.a
 
+CFLAGS += -I$(bdir)/include
+
 OBJS =
 OBJS += tracefs-utils.o
 OBJS += tracefs-instance.o
diff --git a/tracecmd/Makefile b/tracecmd/Makefile
index 01f36c61..de14176e 100644
--- a/tracecmd/Makefile
+++ b/tracecmd/Makefile
@@ -11,6 +11,8 @@ TARGETS = $(bdir)/trace-cmd $(TC_VERSION)
 BUILDGUI := 0
 include $(src)/scripts/utils.mk
 
+CFLAGS += -I$(bdir)/include
+
 TRACE_CMD_OBJS =
 TRACE_CMD_OBJS += trace-cmd.o
 TRACE_CMD_OBJS += trace-record.o
@@ -47,7 +49,7 @@ all_objs := $(sort $(ALL_OBJS))
 all_deps := $(all_objs:$(bdir)/%.o=$(bdir)/.%.d)
 
 CONFIG_INCLUDES =
-CONFIG_LIBS	= -lrt -lpthread
+CONFIG_LIBS	= -lrt -lpthread $(TRACE_LIBS)
 CONFIG_FLAGS	=
 
 all: $(TARGETS)
@@ -67,7 +69,7 @@ $(all_objs): | $(bdir)
 $(bdir)/trace-cmd: $(ALL_OBJS)
 	$(Q)$(do_app_build)
 
-$(bdir)/trace-cmd: $(LIBTRACECMD_STATIC) $(LIBTRACEEVENT_STATIC) $(LIBTRACEFS_STATIC)
+$(bdir)/trace-cmd: $(LIBTRACECMD_STATIC)
 
 $(bdir)/%.o: %.c
 	$(Q)$(call do_compile)
-- 
2.28.0


                 reply	other threads:[~2020-11-26  7:27 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20201126072707.906347-1-tz.stoyanov@gmail.com \
    --to=tz.stoyanov@gmail.com \
    --cc=linux-trace-devel@vger.kernel.org \
    --cc=rostedt@goodmis.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.