linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] libtracefs: Add support for pkg-config
@ 2020-12-04  8:43 Tzvetomir Stoyanov (VMware)
  0 siblings, 0 replies; only message in thread
From: Tzvetomir Stoyanov (VMware) @ 2020-12-04  8:43 UTC (permalink / raw)
  To: rostedt; +Cc: linux-trace-devel

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>
---
v2 changes:
 Added "SPDX-License-Identifier" in the Makefile, deleted by mistake in v1.


 Makefile               | 34 ++++++++++++++++++++++++++++++++--
 libtracefs.pc.template | 10 ++++++++++
 2 files changed, 42 insertions(+), 2 deletions(-)
 create mode 100644 libtracefs.pc.template

diff --git a/Makefile b/Makefile
index 468f908..3bb1564 100644
--- a/Makefile
+++ b/Makefile
@@ -27,6 +27,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 +48,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 +163,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 +181,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 +212,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 +220,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 +291,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


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2020-12-04  8:44 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-04  8:43 [PATCH v2] libtracefs: Add support for pkg-config Tzvetomir Stoyanov (VMware)

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).