Make outdir board-specific to avoid build collisions
Casual building in the tree leads to regular messups where I forget to
clean up the outdir first when switching platforms and the build fails
in strange ways.
Put a $(BOARD) subdirectory under outdir, and use that at $(O) when
the user does not provide an output directory.
Note that "make pristine" continues to remove the entire outdir,
including other architecutres (so as to make the tree pristine).
Also update a few spots where outdir was mentioned in documentation to
clarify the new scheme.
Change-Id: I365eec06ea440f17380b9f9ace5f5d34b9bed4dc
Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
diff --git a/Makefile.inc b/Makefile.inc
index 5a632b0..439b838 100644
--- a/Makefile.inc
+++ b/Makefile.inc
@@ -14,7 +14,26 @@
PROJECT_BASE ?= $(CURDIR)
endif
-O ?= $(PROJECT_BASE)/outdir
+ifdef BOARD
+KBUILD_DEFCONFIG_PATH=$(wildcard $(ZEPHYR_BASE)/boards/*/$(BOARD)_defconfig)
+ifeq ($(KBUILD_DEFCONFIG_PATH),)
+$(error Board $(BOARD) not found!)
+endif
+else
+$(error BOARD is not defined!)
+endif
+
+# Choose a default output directory if one wasn't supplied. Note that
+# PRISTINE_O depends on whether this is default or not. If building
+# in-tree, we want to remove the whole outdir and not just the BOARD
+# specified (thus "pristine"). Out of tree, we can obviously remove
+# only what we were told to build.
+ifndef O
+PRISTINE_O = outdir
+O = $(PROJECT_BASE)/outdir/$(BOARD)
+else
+PRISTINE_O = $(O)
+endif
# Turn O into an absolute path; we call the main Kbuild with $(MAKE) -C
# which changes the working directory, relative paths don't work right.
@@ -30,15 +49,6 @@
KERNEL_TYPE ?= micro
override CONF_FILE := $(strip $(subst $(DQUOTE),,$(CONF_FILE)))
-ifdef BOARD
-KBUILD_DEFCONFIG_PATH=$(wildcard $(ZEPHYR_BASE)/boards/*/$(BOARD)_defconfig)
-ifeq ($(KBUILD_DEFCONFIG_PATH),)
-$(error Board $(BOARD) not found!)
-endif
-else
-$(error BOARD is not defined!)
-endif
-
SOURCE_DIR ?= $(PROJECT_BASE)/src/
override SOURCE_DIR := $(abspath $(SOURCE_DIR))
override SOURCE_DIR := $(subst \,/,$(SOURCE_DIR))
@@ -132,7 +142,7 @@
$(Q)$(MAKE) $(S) -C $(ZEPHYR_BASE) O=$(O) PROJECT=$(PROJECT_BASE) oldnoconfig
pristine:
- $(Q)rm -rf $(O)
+ $(Q)rm -rf $(PRISTINE_O)
PHONY += FORCE initconfig
FORCE:
diff --git a/doc/getting_started/getting_started.rst b/doc/getting_started/getting_started.rst
index 6fc5398..b5e97e2 100644
--- a/doc/getting_started/getting_started.rst
+++ b/doc/getting_started/getting_started.rst
@@ -113,7 +113,7 @@
The sample projects for the microkernel and the nanokernel are available
at :file:`$ZEPHYR_BASE/samples`.
After building an application successfully, the results can be found in the
-:file:`outdir` sub-directory under the application root directory.
+:file:`outdir` sub-directory under the application root directory, in a subdirectory that matches the BOARD string.
The ELF binaries generated by the build system are named by default
:file:`zephyr.elf`. This value can be overridden in the application configuration
diff --git a/samples/task_profiler/README.txt b/samples/task_profiler/README.txt
index 5078fd2..9e1ae67 100644
--- a/samples/task_profiler/README.txt
+++ b/samples/task_profiler/README.txt
@@ -316,7 +316,7 @@
cd $OPENOCD_FOLDER
openocd -f interface/ftdi/olimex-arm-usb-ocd-h.cfg -f board/quark_x10xx_board.cfg
cd $APP_BASE
-gdb outdir/zephyr.elf
+gdb outdir/$BOARD/zephyr.elf
(gdb) target remote localhost:3333
(gdb) c
-->
diff --git a/tests/benchmark/footprint/microkernel/README.txt b/tests/benchmark/footprint/microkernel/README.txt
index 1a6f986..1bbc45d 100644
--- a/tests/benchmark/footprint/microkernel/README.txt
+++ b/tests/benchmark/footprint/microkernel/README.txt
@@ -100,5 +100,6 @@
Additional notes:
-Various host utilities (such as the Unix "size" utility) can be used to
-determine the footprint of the resulting outdir/microkernel.elf image.
+Various host utilities (such as the Unix "size" utility) can be used
+to determine the footprint of the resulting
+outdir/$BOARD/microkernel.elf image.