From 23af1e928ec25ec2657bb4a6de58211754dabf62 Mon Sep 17 00:00:00 2001 From: Kumar Gala Date: Fri, 3 Jun 2016 09:51:56 -0500 Subject: [PATCH] build: Fix application object files placement when building out of tree For the application object files to get properly placed in the outdir when the source files are outside of the zephyr tree we need to set $srctree in kbuild to the parent dir of the application source code rather than getting the default of $srctree being set to $ZEPHYR_BASE. By doing this we are able to get the kbuild system to place the object file results in the outdir rather than in the application source dir. Jira: ZEP-369 Change-Id: I4d3ba67a4a38c15978d5bf7e1f0a912e9bf00f08 Signed-off-by: Kumar Gala --- Makefile | 9 +++++---- Makefile.inc | 9 +++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 27e3f3c6c62..44c0713dab3 100644 --- a/Makefile +++ b/Makefile @@ -218,7 +218,7 @@ objtree := . src := $(srctree) obj := $(objtree) -VPATH := $(srctree) +VPATH := $(SOURCE_DIR_PARENT) $(srctree) export srctree objtree VPATH @@ -731,13 +731,13 @@ export KBUILD_IMAGE ?= zephyr zephyr-dirs := $(patsubst %/,%,$(filter %/, $(core-y) $(drivers-y) \ $(libs-y))) -zephyr-app-dirs := $(patsubst %/,%,$(filter %/, $(app-y))) +zephyr-app-dirs := $(SOURCE_DIR) zephyr-alldirs := $(sort $(zephyr-dirs) $(zephyr-app-dirs) $(patsubst %/,%,$(filter %/, \ $(core-) $(drivers-) $(libs-) $(app-)))) core-y := $(patsubst %/, %/built-in.o, $(core-y)) -app-y := $(patsubst %/, %/built-in.o, $(app-y)) +app-y := $(patsubst %, %/built-in.o, $(notdir $(zephyr-app-dirs))) drivers-y := $(patsubst %/, %/built-in.o, $(drivers-y)) libs-y1 := $(patsubst %/, %/lib.a, $(libs-y)) libs-y2 := $(patsubst %/, %/built-in.o, $(libs-y)) @@ -879,8 +879,9 @@ $(zephyr-dirs): prepare scripts $(Q)$(MAKE) $(build)=$@ PHONY += $(zephyr-app-dirs) +$(zephyr-app-dirs): zephyr-app-dir-root = $(abspath $(patsubst %, %/.., $@)) $(zephyr-app-dirs): prepare scripts - $(Q)$(MAKE) $(build)=$@ + $(Q)$(MAKE) $(build)=$(@F) srctree=$(zephyr-app-dir-root) # Things we need to do before we recursively start building the kernel # or the modules are listed in "prepare". diff --git a/Makefile.inc b/Makefile.inc index 289f9b67756..4953f0dc8e3 100644 --- a/Makefile.inc +++ b/Makefile.inc @@ -39,11 +39,12 @@ $(error BOARD is not defined!) endif SOURCE_DIR ?= $(PROJECT_BASE)/src/ -# Kbuild doesn't work correctly if this is an absolute path -# FIXME Do not depend on python -override SOURCE_DIR := $(shell python -c "import os.path; print(\"%s\" % os.path.relpath(os.path.realpath('$(SOURCE_DIR)'), os.path.realpath('$(ZEPHYR_BASE)')))")/ +override SOURCE_DIR := $(abspath $(SOURCE_DIR)) override SOURCE_DIR := $(subst \,/,$(SOURCE_DIR)) -export SOURCE_DIR +override SOURCE_DIR_PARENT := $(patsubst %, %/.., $(SOURCE_DIR)) +override SOURCE_DIR_PARENT := $(abspath $(SOURCE_DIR_PARENT)) +override SOURCE_DIR_PARENT := $(subst \,/,$(SOURCE_DIR_PARENT)) +export SOURCE_DIR SOURCE_DIR_PARENT ifeq ("$(origin V)", "command line") KBUILD_VERBOSE = $(V)