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 <kumar.gala@linaro.org>
This commit is contained in:
Kumar Gala 2016-06-03 09:51:56 -05:00 committed by Inaky Perez-Gonzalez
commit 23af1e928e
2 changed files with 10 additions and 8 deletions

View file

@ -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".

View file

@ -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)