commit 2f5f672244326f3b23165b3cc3fec72894c680c2
Author: Thomas Schöpping <tschoepp@cit-ec.uni-bielefeld.de>
Date:   Tue Mar 5 11:57:09 2019 +0100

    Enhanced the Makefiles to consistently use the BUIDDIR variable.

diff --git a/bootloader/bootloader.mk b/bootloader/bootloader.mk
index c7171bf..fc7b408 100644
--- a/bootloader/bootloader.mk
+++ b/bootloader/bootloader.mk
@@ -57,11 +57,7 @@ ifneq ($(wildcard $(BOOTLOADER_DIR)AMiRo-BLT/Host/Source/SerialBoot/build/Serial
 	FLASHTOOL = SerialBoot
 	FLASHTOOL_CMD = $(BOOTLOADER_DIR)AMiRo-BLT/Host/Source/SerialBoot/build/SerialBoot
 	FLASHTOOL_EXT = srec
-	ifdef PROJECT
-		FLASHTOOL_ARGS = -d$(FLASH_PORT) -b$(FLASH_BAUDRATE) $(foreach module,$(FLASH_MODULES),-T$($(module)_ID_HEX) build/$(module).$(FLASHTOOL_EXT))
-	else
-		FLASHTOOL_ARGS = -d$(FLASH_PORT) -b$(FLASH_BAUDRATE) $(foreach module,$(FLASH_MODULES),-T$($(module)_ID_HEX) $(FLASH_DIR)$(module)/build/$(module).$(FLASHTOOL_EXT))
-	endif
+	FLASHTOOL_ARGS = -d$(FLASH_PORT) -b$(FLASH_BAUDRATE) $(foreach module,$(FLASH_MODULES),-T$($(module)_ID_HEX) $(BUILDDIR)/$(module).$(FLASHTOOL_EXT))
 else
 	# the default tool to use is stm32flash
 	ifneq ($(words $(FLASH_MODULES)),1)
@@ -70,10 +66,6 @@ else
 	FLASHTOOL = stm32flash
 	FLASHTOOL_CMD = stm32flash
 	FLASHTOOL_EXT = hex
-	ifdef PROJECT
-		FLASHTOOL_ARGS = $(FLASH_PORT) -i "rts,-dtr,-rts":"rts,dtr,-rts" -R -b $(FLASH_BAUDRATE) -w build/$(FLASH_MODULES).$(FLASHTOOL_EXT)
-	else
-		FLASHTOOL_ARGS = $(FLASH_PORT) -i "rts,-dtr,-rts":"rts,dtr,-rts" -R -b $(FLASH_BAUDRATE) -w $(FLASH_MODULES)/build/$(FLASH_MODULES).$(FLASHTOOL_EXT)
-	endif
+	FLASHTOOL_ARGS = $(FLASH_PORT) -i "rts,-dtr,-rts":"rts,dtr,-rts" -R -b $(FLASH_BAUDRATE) -w $(BUILDDIR)/$(FLASH_MODULES).$(FLASHTOOL_EXT)
 endif
 
diff --git a/modules/DiWheelDrive_1-1/Makefile b/modules/DiWheelDrive_1-1/Makefile
index b7c9af6..86db148 100644
--- a/modules/DiWheelDrive_1-1/Makefile
+++ b/modules/DiWheelDrive_1-1/Makefile
@@ -112,8 +112,11 @@ endif
 # Project, target, sources and paths                                           #
 #                                                                              #
 
+# Absolute path to the project
+PROJECT_PATH := $(abspath $(dir $(abspath $(lastword $(MAKEFILE_LIST)))))
+
 # Define project name here
-PROJECT := $(patsubst $(abspath $(dir $(abspath $(lastword $(MAKEFILE_LIST))))..)/%,%,$(abspath $(dir $(abspath $(lastword $(MAKEFILE_LIST))))))
+PROJECT := $(patsubst $(abspath $(dir $(abspath $(lastword $(MAKEFILE_LIST))))..)/%,%,$(PROJECT_PATH))
 
 # Target settings.
 MCU = cortex-m3
@@ -123,7 +126,7 @@ include ../../kernel/kernel.mk
 CHIBIOS    := $(AMIROOS_KERNEL)
 CONFDIR    := .
 ifeq ($(BUILDDIR),)
-  BUILDDIR := ./build
+  BUILDDIR := $(PROJECT_PATH)/build
 endif
 DEPDIR     := $(dir $(BUILDDIR)).dep
 AMIROOS    := ../..
diff --git a/modules/LightRing_1-0/Makefile b/modules/LightRing_1-0/Makefile
index b7c9af6..86db148 100644
--- a/modules/LightRing_1-0/Makefile
+++ b/modules/LightRing_1-0/Makefile
@@ -112,8 +112,11 @@ endif
 # Project, target, sources and paths                                           #
 #                                                                              #
 
+# Absolute path to the project
+PROJECT_PATH := $(abspath $(dir $(abspath $(lastword $(MAKEFILE_LIST)))))
+
 # Define project name here
-PROJECT := $(patsubst $(abspath $(dir $(abspath $(lastword $(MAKEFILE_LIST))))..)/%,%,$(abspath $(dir $(abspath $(lastword $(MAKEFILE_LIST))))))
+PROJECT := $(patsubst $(abspath $(dir $(abspath $(lastword $(MAKEFILE_LIST))))..)/%,%,$(PROJECT_PATH))
 
 # Target settings.
 MCU = cortex-m3
@@ -123,7 +126,7 @@ include ../../kernel/kernel.mk
 CHIBIOS    := $(AMIROOS_KERNEL)
 CONFDIR    := .
 ifeq ($(BUILDDIR),)
-  BUILDDIR := ./build
+  BUILDDIR := $(PROJECT_PATH)/build
 endif
 DEPDIR     := $(dir $(BUILDDIR)).dep
 AMIROOS    := ../..
diff --git a/modules/NUCLEO-F103RB/Makefile b/modules/NUCLEO-F103RB/Makefile
index 47d8e6e..58e220b 100644
--- a/modules/NUCLEO-F103RB/Makefile
+++ b/modules/NUCLEO-F103RB/Makefile
@@ -112,8 +112,11 @@ endif
 # Project, target, sources and paths                                           #
 #                                                                              #
 
+# Absolute path to the project
+PROJECT_PATH := $(abspath $(dir $(abspath $(lastword $(MAKEFILE_LIST)))))
+
 # Define project name here
-PROJECT := $(patsubst $(abspath $(dir $(abspath $(lastword $(MAKEFILE_LIST))))..)/%,%,$(abspath $(dir $(abspath $(lastword $(MAKEFILE_LIST))))))
+PROJECT := $(patsubst $(abspath $(dir $(abspath $(lastword $(MAKEFILE_LIST))))..)/%,%,$(PROJECT_PATH))
 
 # Target settings.
 MCU = cortex-m3
@@ -123,7 +126,7 @@ include ../../kernel/kernel.mk
 CHIBIOS    := $(AMIROOS_KERNEL)
 CONFDIR    := .
 ifeq ($(BUILDDIR),)
-  BUILDDIR := ./build
+  BUILDDIR := $(PROJECT_PATH)/build
 endif
 DEPDIR     := $(dir $(BUILDDIR)).dep
 AMIROOS    := ../..
diff --git a/modules/NUCLEO-L476RG/Makefile b/modules/NUCLEO-L476RG/Makefile
index bbbc7fc..8497143 100644
--- a/modules/NUCLEO-L476RG/Makefile
+++ b/modules/NUCLEO-L476RG/Makefile
@@ -112,8 +112,11 @@ endif
 # Project, target, sources and paths                                           #
 #                                                                              #
 
+# Absolute path to the project
+PROJECT_PATH := $(abspath $(dir $(abspath $(lastword $(MAKEFILE_LIST)))))
+
 # Define project name here
-PROJECT := $(patsubst $(abspath $(dir $(abspath $(lastword $(MAKEFILE_LIST))))..)/%,%,$(abspath $(dir $(abspath $(lastword $(MAKEFILE_LIST))))))
+PROJECT := $(patsubst $(abspath $(dir $(abspath $(lastword $(MAKEFILE_LIST))))..)/%,%,$(PROJECT_PATH))
 
 # Target settings.
 MCU = cortex-m4
@@ -123,7 +126,7 @@ include ../../kernel/kernel.mk
 CHIBIOS    := $(AMIROOS_KERNEL)
 CONFDIR    := .
 ifeq ($(BUILDDIR),)
-  BUILDDIR := ./build
+  BUILDDIR := $(PROJECT_PATH)/build
 endif
 DEPDIR     := $(dir $(BUILDDIR)).dep
 AMIROOS    := ../..
diff --git a/modules/PowerManagement_1-1/Makefile b/modules/PowerManagement_1-1/Makefile
index d44afc7..f961f0a 100644
--- a/modules/PowerManagement_1-1/Makefile
+++ b/modules/PowerManagement_1-1/Makefile
@@ -112,8 +112,11 @@ endif
 # Project, target, sources and paths                                           #
 #                                                                              #
 
+# Absolute path to the project
+PROJECT_PATH := $(abspath $(dir $(abspath $(lastword $(MAKEFILE_LIST)))))
+
 # Define project name here
-PROJECT := $(patsubst $(abspath $(dir $(abspath $(lastword $(MAKEFILE_LIST))))..)/%,%,$(abspath $(dir $(abspath $(lastword $(MAKEFILE_LIST))))))
+PROJECT := $(patsubst $(abspath $(dir $(abspath $(lastword $(MAKEFILE_LIST))))..)/%,%,$(PROJECT_PATH))
 
 # Target settings.
 MCU = cortex-m4
@@ -123,7 +126,7 @@ include ../../kernel/kernel.mk
 CHIBIOS    := $(AMIROOS_KERNEL)
 CONFDIR    := .
 ifeq ($(BUILDDIR),)
-  BUILDDIR := ./build
+  BUILDDIR := $(PROJECT_PATH)/build
 endif
 DEPDIR     := $(dir $(BUILDDIR)).dep
 AMIROOS    := ../..
diff --git a/modules/STM32F407G-DISC1/Makefile b/modules/STM32F407G-DISC1/Makefile
index 336e0ef..d861af5 100644
--- a/modules/STM32F407G-DISC1/Makefile
+++ b/modules/STM32F407G-DISC1/Makefile
@@ -112,8 +112,11 @@ endif
 # Project, target, sources and paths                                           #
 #                                                                              #
 
+# Absolute path to the project
+PROJECT_PATH := $(abspath $(dir $(abspath $(lastword $(MAKEFILE_LIST)))))
+
 # Define project name here
-PROJECT := $(patsubst $(abspath $(dir $(abspath $(lastword $(MAKEFILE_LIST))))..)/%,%,$(abspath $(dir $(abspath $(lastword $(MAKEFILE_LIST))))))
+PROJECT := $(patsubst $(abspath $(dir $(abspath $(lastword $(MAKEFILE_LIST))))..)/%,%,$(PROJECT_PATH))
 
 # Target settings.
 MCU = cortex-m4
@@ -123,7 +126,7 @@ include ../../kernel/kernel.mk
 CHIBIOS    := $(AMIROOS_KERNEL)
 CONFDIR    := .
 ifeq ($(BUILDDIR),)
-  BUILDDIR := ./build
+  BUILDDIR := $(PROJECT_PATH)/build
 endif
 DEPDIR     := $(dir $(BUILDDIR)).dep
 AMIROOS    := ../..
