From: Tzvetomir (VMware) Stoyanov <tz.stoyanov@xxxxxxxxx> 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@xxxxxxxxx> --- 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