diff mbox series

[5/6] tools lib traceevent: Added support for pkg-config

Message ID 20181205092134.2214-6-tstoyanov@vmware.com (mailing list archive)
State Accepted
Headers show
Series tools/lib/traceevent: Various changes in libtraceevent APIs | expand

Commit Message

Tzvetomir Stoyanov Dec. 5, 2018, 9:21 a.m. UTC
This patch implements integration with pkg-config framework.  pkg-config
can be used by the library users to determine required CFLAGS and
LDFLAGS in order to use the library

Signed-off-by: Tzvetomir Stoyanov <tstoyanov@vmware.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: http://lkml.kernel.org/r/20181130154647.022471992@goodmis.org
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 Makefile                                 | 44 ++++++++++++++++++++----
 lib/traceevent/libtraceevent.pc.template | 10 ++++++
 2 files changed, 48 insertions(+), 6 deletions(-)
 create mode 100644 lib/traceevent/libtraceevent.pc.template

Comments

Steven Rostedt Dec. 11, 2018, 4:52 p.m. UTC | #1
On Wed, 5 Dec 2018 09:21:52 +0000
Tzvetomir Stoyanov <tstoyanov@vmware.com> wrote:

> This patch implements integration with pkg-config framework.  pkg-config
> can be used by the library users to determine required CFLAGS and
> LDFLAGS in order to use the library
> 

I applied patches 1-4 in my trace-cmd repo, but I'm not going to apply
this and patch 6. Although trace-cmd may hold a copy of the
libtraceevent source code, I don't want it to install it. The
kernel/tools/lib/traceevent is going to be the official home of the
libtraceevent library, and because of that trace-cmd should not be
installing it as that will lead to conflicts in the future.

I would be OK to have a pkg-config when we start to create a trace-cmd
(libftrace) library. But that's going to be in the future.

Thanks!

-- Steve
diff mbox series

Patch

diff --git a/Makefile b/Makefile
index 7ee9e0d..8dbba58 100644
--- a/Makefile
+++ b/Makefile
@@ -29,6 +29,7 @@  endef
 # Allow setting CC and AR, or setting CROSS_COMPILE as a prefix.
 $(call allow-override,CC,$(CROSS_COMPILE)gcc)
 $(call allow-override,AR,$(CROSS_COMPILE)ar)
+$(call allow-override,PKG_CONFIG,pkg-config)
 
 EXT = -std=gnu99
 INSTALL = install
@@ -40,6 +41,13 @@  INSTALL = install
 DESTDIR ?=
 DESTDIR_SQ = '$(subst ','\'',$(DESTDIR))'
 
+LP64 := $(shell echo __LP64__ | ${CC} ${CFLAGS} -E -x c - | tail -n 1)
+ifeq ($(LP64), 1)
+  libdir_relative = lib64
+else
+  libdir_relative = lib
+endif
+
 prefix ?= /usr/local
 bindir_relative = bin
 bindir = $(prefix)/$(bindir_relative)
@@ -49,10 +57,16 @@  html_install = $(prefix)/share/kernelshark/html
 html_install_SQ = '$(subst ','\'',$(html_install))'
 img_install = $(prefix)/share/kernelshark/html/images
 img_install_SQ = '$(subst ','\'',$(img_install))'
-libdir ?= $(prefix)/lib
+libdir ?= $(prefix)/$(libdir_relative)
 libdir_SQ = '$(subst ','\'',$(libdir))'
-includedir = $(prefix)/include/trace-cmd
-includedir_SQ = '$(subst ','\'',$(includedir))'
+includedir_libtrace_relative = traceevent
+includedir_tc_relative = trace-cmd
+includedir_tc = $(prefix)/include/$(includedir_tc_relative)
+includedir_libtrace = $(prefix)/include/$(includedir_libtrace_relative)
+includedir_tc_SQ = '$(subst ','\'',$(includedir_tc))'
+includedir_libtrace_SQ = '$(subst ','\'',$(includedir_libtrace))'
+pkgconfig_dir ?= $(word 1,$(shell $(PKG_CONFIG) 		\
+			--variable pc_path pkg-config | tr ":" " "))
 
 export man_dir man_dir_SQ html_install html_install_SQ INSTALL
 export img_install img_install_SQ
@@ -305,6 +319,20 @@  show_gui_make:
 
 PHONY += show_gui_make
 
+PKG_CONFIG_FILE = libtraceevent.pc
+define do_install_pkgconfig_file
+	if [ -n "${pkgconfig_dir}" ]; then 					\
+		cp -f lib/traceevent/${PKG_CONFIG_FILE}.template ${PKG_CONFIG_FILE}; 		\
+		sed -i "s|INSTALL_PREFIX|${1}|g" ${PKG_CONFIG_FILE}; 		\
+		sed -i "s|LIB_VERSION|${TRACECMD_VERSION}|g" ${PKG_CONFIG_FILE}; \
+		sed -i "s|LIB_DIR|${libdir}|g" ${PKG_CONFIG_FILE}; \
+		sed -i "s|HEADER_DIR|$(includedir_libtrace)|g" ${PKG_CONFIG_FILE}; \
+		$(call do_install,$(PKG_CONFIG_FILE),$(pkgconfig_dir),644); 	\
+	else 									\
+		(echo Failed to locate pkg-config directory) 1>&2;		\
+	fi
+endef
+
 define find_tag_files
 	find . -name '\.pc' -prune -o -name '*\.[ch]' -print -o -name '*\.[ch]pp' \
 		! -name '\.#' -print
@@ -322,6 +350,9 @@  cscope: force
 	$(RM) cscope*
 	$(call find_tag_files) | cscope -b -q
 
+install_pkgconfig:
+	$(Q)$(call do_install_pkgconfig_file,$(prefix))
+
 install_plugins: force
 	$(Q)$(MAKE) -C $(src)/plugins $@
 
@@ -341,11 +372,11 @@  install: install_cmd
 install_gui: install_cmd gui
 	$(Q)$(MAKE) $(S) -C $(kshark-dir)/build install
 
-install_libs: libs
+install_libs: libs install_pkgconfig
 	$(Q)$(call do_install,$(LIBTRACECMD_SHARED),$(libdir_SQ))
 	$(Q)$(call do_install,$(LIBTRACEEVENT_SHARED),$(libdir_SQ))
-	$(Q)$(call do_install,$(src)/include/traceevent/event-parse.h,$(includedir_SQ))
-	$(Q)$(call do_install,$(src)/include/trace-cmd/trace-cmd.h,$(includedir_SQ))
+	$(Q)$(call do_install,$(src)/include/traceevent/event-parse.h,$(includedir_libtrace_SQ))
+	$(Q)$(call do_install,$(src)/include/trace-cmd/trace-cmd.h,$(includedir_tc_SQ))
 
 doc:
 	$(MAKE) -C $(src)/Documentation all
@@ -359,6 +390,7 @@  install_doc:
 clean:
 	$(RM) *.o *~ *.a *.so .*.d
 	$(RM) tags TAGS cscope*
+	$(RM) -f $(PKG_CONFIG_FILE)
 	$(MAKE) -C $(src)/lib/traceevent clean
 	$(MAKE) -C $(src)/lib/trace-cmd clean
 	$(MAKE) -C $(src)/kernel-shark clean
diff --git a/lib/traceevent/libtraceevent.pc.template b/lib/traceevent/libtraceevent.pc.template
new file mode 100644
index 0000000..86384fc
--- /dev/null
+++ b/lib/traceevent/libtraceevent.pc.template
@@ -0,0 +1,10 @@ 
+prefix=INSTALL_PREFIX
+libdir=LIB_DIR
+includedir=HEADER_DIR
+
+Name: libtraceevent
+URL: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
+Description: Linux kernel trace event library
+Version: LIB_VERSION
+Cflags: -I${includedir}
+Libs: -L${libdir} -ltraceevent