From: "Tzvetomir Stoyanov (VMware)" <tz.stoyanov@gmail.com>
To: rostedt@goodmis.org
Cc: linux-trace-devel@vger.kernel.org
Subject: [PATCH 1/3] libtracefs: Add support for pkg-config
Date: Thu, 26 Nov 2020 09:27:17 +0200 [thread overview]
Message-ID: <20201126072719.906443-2-tz.stoyanov@gmail.com> (raw)
In-Reply-To: <20201126072719.906443-1-tz.stoyanov@gmail.com>
From: Tzvetomir (VMware) Stoyanov <tz.stoyanov@gmail.com>
The pkg-config file is used by the library users to check if the
library is installed on the system and get required CFLAGS and LDFLAGS
in order to use it.
Signed-off-by: Tzvetomir (VMware) Stoyanov <tz.stoyanov@gmail.com>
---
Makefile | 35 ++++++++++++++++++++++++++++++++---
libtracefs.pc.template | 10 ++++++++++
2 files changed, 42 insertions(+), 3 deletions(-)
create mode 100644 libtracefs.pc.template
diff --git a/Makefile b/Makefile
index 468f908..dc7deb1 100644
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,3 @@
-# SPDX-License-Identifier: LGPL-2.1
# libtracefs version
TFS_VERSION = 0
TFS_PATCHLEVEL = 1
@@ -27,6 +26,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
@@ -47,6 +47,11 @@ libdir ?= $(prefix)/lib
libdir_SQ = '$(subst ','\'',$(libdir))'
includedir = $(prefix)/include
includedir_SQ = '$(subst ','\'',$(includedir))'
+pkgconfig_dir ?= $(word 1,$(shell $(PKG_CONFIG) \
+ --variable pc_path pkg-config | tr ":" " "))
+
+PKG_CONFIG_SOURCE_FILE = libtracefs.pc
+PKG_CONFIG_FILE := $(addprefix $(OUTPUT),$(PKG_CONFIG_SOURCE_FILE))
ifeq ($(prefix),/usr/local)
etcdir ?= /etc
@@ -157,7 +162,7 @@ LIB_INSTALL := $(addprefix $(bdir)/,$(LIB_INSTALL))
TARGETS = $(LIBTRACEFS_SHARED) $(LIBTRACEFS_STATIC)
-all_cmd: $(TARGETS)
+all_cmd: $(TARGETS) $(PKG_CONFIG_FILE)
libtracefs.a: $(LIBTRACEFS_STATIC)
libtracefs.so: $(LIBTRACEFS_SHARED)
@@ -175,6 +180,25 @@ define find_tag_files
! -name '\.#' -print
endef
+define do_make_pkgconfig_file
+ cp -f ${PKG_CONFIG_SOURCE_FILE}.template ${PKG_CONFIG_FILE}; \
+ sed -i "s|INSTALL_PREFIX|${1}|g" ${PKG_CONFIG_FILE}; \
+ sed -i "s|LIB_VERSION|${TRACEFS_VERSION}|g" ${PKG_CONFIG_FILE}; \
+ sed -i "s|LIB_DIR|${libdir}|g" ${PKG_CONFIG_FILE}; \
+ sed -i "s|HEADER_DIR|$(includedir)|g" ${PKG_CONFIG_FILE};
+endef
+
+$(PKG_CONFIG_FILE) : ${PKG_CONFIG_SOURCE_FILE}.template
+ $(Q) $(call do_make_pkgconfig_file,$(prefix))
+
+define do_install_pkgconfig_file
+ if [ -n "${pkgconfig_dir}" ]; then \
+ $(call do_install,$(PKG_CONFIG_FILE),$(pkgconfig_dir),644); \
+ else \
+ (echo Failed to locate pkg-config directory) 1>&2; \
+ fi
+endef
+
tags: force
$(RM) tags
$(call find_tag_files) | xargs ctags --extra=+f --c-kinds=+px
@@ -187,7 +211,7 @@ cscope: force
$(RM) cscope*
$(call find_tag_files) | cscope -b -q
-install_libs: libs
+install_libs: libs install_pkgconfig
$(Q)$(call do_install,$(LIBTRACEFS_SHARED),$(libdir_SQ)/tracefs); \
cp -fpR $(LIB_INSTALL) $(DESTDIR)$(libdir_SQ)/tracefs
$(Q)$(call do_install,$(src)/include/tracefs.h,$(includedir_SQ)/tracefs)
@@ -195,6 +219,10 @@ install_libs: libs
install: install_libs
+install_pkgconfig: $(PKG_CONFIG_FILE)
+ $(Q)$(call , $(PKG_CONFIG_FILE)) \
+ $(call do_install_pkgconfig_file,$(prefix))
+
doc:
$(MAKE) -C $(src)/Documentation all
doc_gui:
@@ -262,5 +290,6 @@ endif
clean:
$(RM) $(TARGETS) $(bdir)/*.a $(bdir)/*.so $(bdir)/*.o $(bdir)/.*.d
+ $(RM) $(PKG_CONFIG_FILE)
.PHONY: clean
diff --git a/libtracefs.pc.template b/libtracefs.pc.template
new file mode 100644
index 0000000..5e7d54a
--- /dev/null
+++ b/libtracefs.pc.template
@@ -0,0 +1,10 @@
+prefix=INSTALL_PREFIX
+libdir=LIB_DIR
+includedir=HEADER_DIR
+
+Name: libtracefs
+URL: https://git.kernel.org/pub/scm/libs/libtrace/libtracefs.git/
+Description: Library for accessing ftrace file system
+Version: LIB_VERSION
+Cflags: -I${includedir}
+Libs: -L${libdir} -ltracefs
--
2.28.0
next prev parent reply other threads:[~2020-11-26 7:27 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-26 7:27 [PATCH 0/3] libtracefs install and test fixes Tzvetomir Stoyanov (VMware)
2020-11-26 7:27 ` Tzvetomir Stoyanov (VMware) [this message]
2020-11-26 7:27 ` [PATCH 2/3] libtracefs: Add unit tests Tzvetomir Stoyanov (VMware)
2020-11-26 7:27 ` [PATCH 3/3] libtracefs: Do not install library in a subfolder Tzvetomir Stoyanov (VMware)
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=20201126072719.906443-2-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).