From patchwork Wed Jan 10 15:58:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Vladislav Valtchev (VMware)" X-Patchwork-Id: 10758457 Return-Path: linux-trace-devel-owner@vger.kernel.org Received: from mail-wr0-f193.google.com ([209.85.128.193]:43212 "EHLO mail-wr0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965173AbeAJP65 (ORCPT ); Wed, 10 Jan 2018 10:58:57 -0500 Received: by mail-wr0-f193.google.com with SMTP id s13so15413677wra.10 for ; Wed, 10 Jan 2018 07:58:56 -0800 (PST) From: "Vladislav Valtchev (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org, "Vladislav Valtchev (VMware)" Subject: [PATCH 1/6] trace-cmd: Make libtraceevent builable out-of-tree Date: Wed, 10 Jan 2018 17:58:27 +0200 Message-Id: <20180110155832.15928-2-vladislav.valtchev@gmail.com> In-Reply-To: <20180110155832.15928-1-vladislav.valtchev@gmail.com> References: <20180110155832.15928-1-vladislav.valtchev@gmail.com> Sender: linux-trace-devel-owner@vger.kernel.org List-ID: Content-Length: 3678 This patch allows the libtraceevent 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 libtraceevent: with this patch the final goal of a fully working out-of-tree build gets significantly 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) --- Makefile | 31 +++++++++++-------------------- lib/traceevent/Makefile | 25 +++++++++++++++++-------- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/Makefile b/Makefile index 2370c8d..d1fed58 100644 --- a/Makefile +++ b/Makefile @@ -144,27 +144,18 @@ endef blk-flags := $(call test-build,$(BLK_TC_FLUSH_SOURCE),-DHAVE_BLK_TC_FLUSH) ifeq ("$(origin O)", "command line") - BUILD_OUTPUT := $(O) + + saved-output := $(O) + BUILD_OUTPUT := $(shell cd $(O) && /bin/pwd) + $(if $(BUILD_OUTPUT),, \ + $(error output directory "$(saved-output)" does not exist)) + +else + BUILD_OUTPUT = $(CURDIR) endif -ifeq ($(BUILD_SRC),) -ifneq ($(BUILD_OUTPUT),) - -define build_output - $(if $(VERBOSE:1=),@)$(MAKE) -C $(BUILD_OUTPUT) \ - BUILD_SRC=$(CURDIR) -f $(CURDIR)/Makefile $1 -endef - -saved-output := $(BUILD_OUTPUT) -BUILD_OUTPUT := $(shell cd $(BUILD_OUTPUT) && /bin/pwd) -$(if $(BUILD_OUTPUT),, \ - $(error output directory "$(saved-output)" does not exist)) - -endif # BUILD_OUTPUT -endif # BUILD_SRC - srctree := $(if $(BUILD_SRC),$(BUILD_SRC),$(CURDIR)) -objtree := $(CURDIR) +objtree := $(BUILD_OUTPUT) src := $(srctree) obj := $(objtree) @@ -269,10 +260,10 @@ trace-graph: force $(CMD_TARGETS) $(Q)$(MAKE) -C $(src)/kernel-shark $@ $(LIBTRACEEVENT_SHARED): force - $(Q)$(MAKE) -C $(src)/lib/traceevent libtraceevent.so + $(Q)$(MAKE) -C $(src)/lib/traceevent $(obj)/lib/traceevent/libtraceevent.so $(LIBTRACEEVENT_STATIC): force - $(Q)$(MAKE) -C $(src)/lib/traceevent libtraceevent.a + $(Q)$(MAKE) -C $(src)/lib/traceevent $(obj)/lib/traceevent/libtraceevent.a $(LIBTRACECMD_STATIC): force $(obj)/plugins/trace_plugin_dir $(Q)$(MAKE) -C $(src)/lib/trace-cmd libtracecmd.a diff --git a/lib/traceevent/Makefile b/lib/traceevent/Makefile index f9c595c..60246aa 100644 --- a/lib/traceevent/Makefile +++ b/lib/traceevent/Makefile @@ -2,7 +2,9 @@ include $(src)/scripts/utils.mk -DEFAULT_TARGET = libtraceevent.a +bdir:=$(obj)/lib/traceevent + +DEFAULT_TARGET = $(bdir)/libtraceevent.a OBJS = OBJS += event-parse.o @@ -15,23 +17,30 @@ OBJS += parse-utils.o # Additional util objects OBJS += str_error_r.o -DEPS := $(OBJS:%.o=.%.d) +OBJS := $(OBJS:%.o=$(bdir)/%.o) +DEPS := $(OBJS:$(bdir)/%.o=$(bdir)/.%.d) all: $(DEFAULT_TARGET) -libtraceevent.a: $(OBJS) +$(bdir): + @mkdir -p $(bdir) + +$(OBJS): | $(bdir) +$(DEPS): | $(bdir) + +$(bdir)/libtraceevent.a: $(OBJS) $(Q)$(call do_build_static_lib) -libtraceevent.so: $(OBJS) +$(bdir)/libtraceevent.so: $(OBJS) $(Q)$(call do_compile_shared_library) -%.o: %.c +$(bdir)/%.o: %.c $(Q)$(call do_fpic_compile) -$(DEPS): .%.d: %.c +$(DEPS): $(bdir)/.%.d: %.c $(Q)$(CC) -M $(CPPFLAGS) $(CFLAGS) $< > $@ -$(OBJS): %.o : .%.d +$(OBJS): $(bdir)/%.o : $(bdir)/.%.d dep_includes := $(wildcard $(DEPS)) @@ -40,6 +49,6 @@ ifneq ($(dep_includes),) endif clean: - $(RM) *.a *.so *.o .*.d + $(RM) -f $(bdir)/*.a $(bdir)/*.so $(bdir)/*.o $(bdir)/.*.d .PHONY: clean