diff mbox series

[11/12] trace-cmd: Update libtracecmd.pc if prefix is different

Message ID 20201216044214.856860622@goodmis.org (mailing list archive)
State Accepted
Commit 9633afb2047cbfd4390c5bb42cc66c7b22651850
Headers show
Series trace-cmd: Updates to the Makefile | expand

Commit Message

Steven Rostedt Dec. 16, 2020, 4:42 a.m. UTC
From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>

If a build is done with different DESTDIR and the prefix is changed, the
the libtracecmd.pc is not updated with the new prefix, and the one used may
not work with the installation being performed.

Add a "build_prefix" dependency, that creates a file "build_prefix" that has
the last prefix used to build the library. And if a new prefix is used, then
that file gets updated and so does libtracecmd.pc.

Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
 .gitignore       |  1 +
 Makefile         |  7 ++++++-
 scripts/utils.mk | 10 ++++++++++
 3 files changed, 17 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/.gitignore b/.gitignore
index 1e8c1d4f5734..9ce25c8e031e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -24,3 +24,4 @@  traceevent_plugin_dir
 trace_python_dir
 tracecmd_plugin_dir
 libtracecmd.pc
+build_prefix
diff --git a/Makefile b/Makefile
index ddceab3f45e7..396a6795bad1 100644
--- a/Makefile
+++ b/Makefile
@@ -343,7 +343,12 @@  CMAKE_COMMAND = /usr/bin/cmake
 # Build with "BUILD_TYPE=Release" to remove cmake debug info
 BUILD_TYPE ?= RelWithDebInfo
 
-$(PKG_CONFIG_FILE) : ${PKG_CONFIG_SOURCE_FILE}.template
+BUILD_PREFIX := $(BUILD_OUTPUT)/build_prefix
+
+$(BUILD_PREFIX): force
+	$(Q)$(call build_prefix,$(prefix))
+
+$(PKG_CONFIG_FILE) : ${PKG_CONFIG_SOURCE_FILE}.template $(BUILD_PREFIX)
 	$(Q) $(call do_make_pkgconfig_file,$(prefix))
 
 $(kshark-dir)/build/Makefile: $(kshark-dir)/CMakeLists.txt
diff --git a/scripts/utils.mk b/scripts/utils.mk
index c8ef44b3776a..c06888795ddf 100644
--- a/scripts/utils.mk
+++ b/scripts/utils.mk
@@ -121,6 +121,16 @@  define update_dir
 	fi);
 endef
 
+define build_prefix
+	(echo $1 > $@.tmp;	\
+	if [ -r $@ ] && cmp -s $@ $@.tmp; then				\
+		rm -f $@.tmp;						\
+	else								\
+		$(print_update)						\
+		mv -f $@.tmp $@;					\
+	fi);
+endef
+
 define do_install
 	$(print_install)				\
 	if [ ! -d '$(DESTDIR_SQ)$2' ]; then		\