[v2,21/24] trace-cmd: Make libtracecmd buildable out-of-tree
diff mbox series

Message ID 20180206084906.9854-22-vladislav.valtchev@gmail.com
State New, archived
Headers show
  • trace-cmd: restructure the project's source tree
Related show

Commit Message

Vladislav Valtchev (VMware) Feb. 6, 2018, 8:49 a.m. UTC
This patch allows the libtracecmd to be buildable out-of-tree when the 'O'
variable is set at command line while invoking make.

At this stage, when the 'O' variable is set, the out-of-tree build will fail (as
it *already* does on the master branch) but with errors unrelated with
libtracecmd: with this patch the final goal of a fully working out-of-tree build
gets closer.

In successive steps, the remaining Makefiles will be made to support out-of-tree
builds, until everything works.

NOTE: the regular in-tree build of all targets clearly continues to work.
Signed-off-by: Vladislav Valtchev (VMware) <vladislav.valtchev@gmail.com>
 Makefile               |  4 ++--
 lib/trace-cmd/Makefile | 27 ++++++++++++++++++---------
 2 files changed, 20 insertions(+), 11 deletions(-)

diff mbox series

diff --git a/Makefile b/Makefile
index df20885..a40bf28 100644
--- a/Makefile
+++ b/Makefile
@@ -267,10 +267,10 @@  $(LIBTRACEEVENT_STATIC): force
 	$(Q)$(MAKE) -C $(src)/lib/traceevent $@
 $(LIBTRACECMD_STATIC): force $(obj)/plugins/trace_plugin_dir
-	$(Q)$(MAKE) -C $(src)/lib/trace-cmd libtracecmd.a
+	$(Q)$(MAKE) -C $(src)/lib/trace-cmd $@
 $(LIBTRACECMD_SHARED): force $(obj)/plugins/trace_plugin_dir
-	$(Q)$(MAKE) -C $(src)/lib/trace-cmd libtracecmd.so
+	$(Q)$(MAKE) -C $(src)/lib/trace-cmd $@
 libtraceevent.so: $(LIBTRACEEVENT_SHARED)
 libtraceevent.a: $(LIBTRACEEVENT_STATIC)
diff --git a/lib/trace-cmd/Makefile b/lib/trace-cmd/Makefile
index e8fb088..ee09099 100644
--- a/lib/trace-cmd/Makefile
+++ b/lib/trace-cmd/Makefile
@@ -2,7 +2,9 @@ 
 include $(src)/scripts/utils.mk
-DEFAULT_TARGET = libtracecmd.a
+DEFAULT_TARGET = $(bdir)/libtracecmd.a
 OBJS += trace-hash.o
@@ -15,25 +17,32 @@  OBJS += trace-util.o
 OBJS += trace-blk-hack.o
 OBJS += trace-ftrace.o
-DEPS := $(OBJS:%.o=.%.d)
+OBJS := $(OBJS:%.o=$(bdir)/%.o)
+DEPS := $(OBJS:$(bdir)/%.o=$(bdir)/.%.d)
-libtracecmd.a: $(OBJS)
+	@mkdir -p $(bdir)
+$(OBJS): | $(bdir)
+$(DEPS): | $(bdir)
+$(bdir)/libtracecmd.a: $(OBJS)
 	$(Q)$(call do_build_static_lib)
-libtracecmd.so: $(OBJS)
+$(bdir)/libtracecmd.so: $(OBJS)
 	$(Q)$(call do_compile_shared_library)
-%.o: %.c
+$(bdir)/%.o: %.c
 	$(Q)$(call do_fpic_compile)
-trace-util.o: $(obj)/plugins/trace_plugin_dir
+$(bdir)/trace-util.o: $(obj)/plugins/trace_plugin_dir
-$(DEPS): .%.d: %.c
+$(DEPS): $(bdir)/.%.d: %.c
 	$(Q)$(CC) -M $(CPPFLAGS) $(CFLAGS) $< > $@
-$(OBJS): %.o : .%.d
+$(OBJS): $(bdir)/%.o : $(bdir)/.%.d
 dep_includes := $(wildcard $(DEPS))
@@ -42,6 +51,6 @@  ifneq ($(dep_includes),)
-	$(RM) *.a *.so *.o .*.d
+	$(RM) $(bdir)/*.a $(bdir)/*.so $(bdir)/*.o $(bdir)/.*.d
 .PHONY: clean