From patchwork Wed Dec 5 09:21:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tzvetomir Stoyanov X-Patchwork-Id: 10760125 Return-Path: Received: from mail-eopbgr710054.outbound.protection.outlook.com ([40.107.71.54]:10064 "EHLO NAM05-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726918AbeLEJV4 (ORCPT ); Wed, 5 Dec 2018 04:21:56 -0500 From: Tzvetomir Stoyanov To: "rostedt@goodmis.org" CC: "linux-trace-devel@vger.kernel.org" Subject: [PATCH 5/6] tools lib traceevent: Added support for pkg-config Date: Wed, 5 Dec 2018 09:21:52 +0000 Message-ID: <20181205092134.2214-6-tstoyanov@vmware.com> References: <20181205092134.2214-1-tstoyanov@vmware.com> In-Reply-To: <20181205092134.2214-1-tstoyanov@vmware.com> Content-Language: en-US MIME-Version: 1.0 Sender: linux-trace-devel-owner@vger.kernel.org List-ID: Content-Length: 5000 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 Cc: Andrew Morton Cc: Jiri Olsa Cc: Namhyung Kim Link: http://lkml.kernel.org/r/20181130154647.022471992@goodmis.org Signed-off-by: Steven Rostedt (VMware) Signed-off-by: Arnaldo Carvalho de Melo --- Makefile | 44 ++++++++++++++++++++---- lib/traceevent/libtraceevent.pc.template | 10 ++++++ 2 files changed, 48 insertions(+), 6 deletions(-) create mode 100644 lib/traceevent/libtraceevent.pc.template 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