From deba38739343f58817b3c1a1b18dd61b24db4d1f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Joakim=20Nohlg=C3=A5rd?= <joakim.nohlgard@eistec.se>
Date: Fri, 15 Jan 2016 18:21:29 +0100
Subject: [PATCH] cortexm_common: Move toolchain settings to cpu dir

---
 boards/Makefile.include.cortexm_common | 54 ------------------------
 cpu/Makefile.include.cortexm_common    | 58 ++++++++++++++++++++++++++
 2 files changed, 58 insertions(+), 54 deletions(-)

diff --git a/boards/Makefile.include.cortexm_common b/boards/Makefile.include.cortexm_common
index 93073ff6b9..e3824ca988 100644
--- a/boards/Makefile.include.cortexm_common
+++ b/boards/Makefile.include.cortexm_common
@@ -1,56 +1,2 @@
-# Target triple for the build. Use arm-none-eabi if you are unsure.
-export TARGET_TRIPLE ?= arm-none-eabi
-
-# Use TOOLCHAIN environment variable to select the toolchain to use.
-# Default: gnu
-TOOLCHAIN ?= gnu
-
-# TOOLCHAIN = clang is an alias for TOOLCHAIN = llvm
-ifeq (clang,$(TOOLCHAIN))
-# use override so that we can redefine a variable set on the command line (as
-# opposed to one set in the environment)
-override TOOLCHAIN := llvm
-endif
-# TOOLCHAIN = gcc is an alias for TOOLCHAIN = gnu
-ifeq (gcc,$(TOOLCHAIN))
-# use override so that we can redefine a variable set on the command line (as
-# opposed to one set in the environment)
-override TOOLCHAIN := gnu
-endif
-
-export TOOLCHAIN
-
-# default toolchain prefix, defaults to target triple followed by a dash, you
-# will most likely not need to touch this.
-export PREFIX ?= $(if $(TARGET_TRIPLE),$(TARGET_TRIPLE)-)
-
-# define build specific options
-export CFLAGS_CPU   = -mcpu=$(MCPU) -mlittle-endian -mthumb $(CFLAGS_FPU)
-ifneq (llvm,$(TOOLCHAIN))
-# Clang (observed with v3.7) does not understand  -mno-thumb-interwork, only add if
-# not building with LLVM
-export CFLAGS_CPU  += -mno-thumb-interwork
-endif
-export CFLAGS_STYLE = -std=gnu99 -Wall -Wstrict-prototypes -Werror=implicit-function-declaration
-export CFLAGS_LINK  = -ffunction-sections -fdata-sections -fno-builtin -fshort-enums
-export CFLAGS_DBG   = -ggdb -g3
-export CFLAGS_OPT  ?= -Os
-
-export CFLAGS += $(CFLAGS_CPU) $(CFLAGS_STYLE) $(CFLAGS_LINK) $(CFLAGS_DBG) $(CFLAGS_OPT)
-
-export ASFLAGS += $(CFLAGS_CPU) $(CFLAGS_DEBUG)
-export LINKFLAGS += -L$(RIOTCPU)/$(CPU)/ldscripts -L$(RIOTCPU)/cortexm_common/ldscripts
-export LINKFLAGS += -T$(RIOTCPU)/$(CPU)/ldscripts/$(CPU_MODEL).ld -Wl,--fatal-warnings
-export LINKFLAGS += $(CFLAGS_DEBUG) $(CFLAGS_CPU) $(CFLAGS_STYLE) -static -lgcc -nostartfiles
-export LINKFLAGS += -Wl,--gc-sections
-
-# Import all toolchain settings
-include $(RIOTBOARD)/Makefile.include.$(TOOLCHAIN)
-
-# use the nano-specs of Newlib when available
-ifeq ($(shell $(LINK) -specs=nano.specs -E - 2>/dev/null >/dev/null </dev/null ; echo $$?),0)
-export LINKFLAGS += -specs=nano.specs -lc -lnosys
-endif
-
 # export board specific includes to the global includes-listing
 export INCLUDES += -I$(RIOTBOARD)/$(BOARD)/include
diff --git a/cpu/Makefile.include.cortexm_common b/cpu/Makefile.include.cortexm_common
index fde97cc307..1d586fb170 100644
--- a/cpu/Makefile.include.cortexm_common
+++ b/cpu/Makefile.include.cortexm_common
@@ -1,3 +1,53 @@
+# Target triple for the build. Use arm-none-eabi if you are unsure.
+export TARGET_TRIPLE ?= arm-none-eabi
+
+# Use TOOLCHAIN environment variable to select the toolchain to use.
+# Default: gnu
+TOOLCHAIN ?= gnu
+
+# TOOLCHAIN = clang is an alias for TOOLCHAIN = llvm
+ifeq (clang,$(TOOLCHAIN))
+# use override so that we can redefine a variable set on the command line (as
+# opposed to one set in the environment)
+override TOOLCHAIN := llvm
+endif
+# TOOLCHAIN = gcc is an alias for TOOLCHAIN = gnu
+ifeq (gcc,$(TOOLCHAIN))
+# use override so that we can redefine a variable set on the command line (as
+# opposed to one set in the environment)
+override TOOLCHAIN := gnu
+endif
+
+ifeq (,$(TOOLCHAIN))
+override TOOLCHAIN := gnu
+endif
+
+export TOOLCHAIN
+
+# default toolchain prefix, defaults to target triple followed by a dash, you
+# will most likely not need to touch this.
+export PREFIX ?= $(if $(TARGET_TRIPLE),$(TARGET_TRIPLE)-)
+
+# define build specific options
+export CFLAGS_CPU   = -mcpu=$(MCPU) -mlittle-endian -mthumb $(CFLAGS_FPU)
+ifneq (llvm,$(TOOLCHAIN))
+# Clang (observed with v3.7) does not understand  -mno-thumb-interwork, only add if
+# not building with LLVM
+export CFLAGS_CPU  += -mno-thumb-interwork
+endif
+export CFLAGS_STYLE = -std=gnu99 -Wall -Wstrict-prototypes -Werror=implicit-function-declaration
+export CFLAGS_LINK  = -ffunction-sections -fdata-sections -fno-builtin -fshort-enums
+export CFLAGS_DBG   = -ggdb -g3
+export CFLAGS_OPT  ?= -Os
+
+export CFLAGS += $(CFLAGS_CPU) $(CFLAGS_STYLE) $(CFLAGS_LINK) $(CFLAGS_DBG) $(CFLAGS_OPT)
+
+export ASFLAGS += $(CFLAGS_CPU) $(CFLAGS_DEBUG)
+export LINKFLAGS += -L$(RIOTCPU)/$(CPU)/ldscripts -L$(RIOTCPU)/cortexm_common/ldscripts
+export LINKFLAGS += -T$(RIOTCPU)/$(CPU)/ldscripts/$(CPU_MODEL).ld -Wl,--fatal-warnings
+export LINKFLAGS += $(CFLAGS_DEBUG) $(CFLAGS_CPU) $(CFLAGS_STYLE) -static -lgcc -nostartfiles
+export LINKFLAGS += -Wl,--gc-sections
+
 # This CPU implementation is using the new core/CPU interface:
 export CFLAGS += -DCOREIF_NG=1
 
@@ -70,6 +120,14 @@ endif
 # CPU depends on the cortex-m common module, so include it:
 include $(RIOTCPU)/cortexm_common/Makefile.include
 
+# Import all toolchain settings
+include $(RIOTBOARD)/Makefile.include.$(TOOLCHAIN)
+
+# use the nano-specs of Newlib when available
+ifeq ($(shell $(LINK) -specs=nano.specs -E - 2>/dev/null >/dev/null </dev/null ; echo $$?),0)
+export LINKFLAGS += -specs=nano.specs -lc -lnosys
+endif
+
 # Avoid overriding the default rule:
 all:
 
-- 
GitLab