From d90f33e654ebbc6bc4c49c1dcbd581caa9a46680 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Joakim=20Nohlg=C3=A5rd?= <joakim.nohlgard@eistec.se>
Date: Wed, 1 Mar 2017 11:24:11 +0100
Subject: [PATCH] make: Add support for specifying a different compiler for
 assembler

---
 Makefile.base             |  4 ++--
 Makefile.vars             |  5 ++++-
 cpu/Makefile.include.gnu  | 23 ++++++++++++-----------
 cpu/Makefile.include.llvm |  1 +
 4 files changed, 19 insertions(+), 14 deletions(-)

diff --git a/Makefile.base b/Makefile.base
index 8bbe3e39ad56..582ae88f33da 100644
--- a/Makefile.base
+++ b/Makefile.base
@@ -53,8 +53,8 @@ $(BINDIR)/$(MODULE).a $(OBJ): | $(BINDIR)/$(MODULE)/
 $(BINDIR)/$(MODULE).a: $(OBJ) | ${DIRS:%=ALL--%}
 	$(Q)$(AR) $(ARFLAGS) $@ $?
 
-
 CXXFLAGS = $(filter-out $(CXXUWFLAGS), $(CFLAGS)) $(CXXEXFLAGS)
+CCASFLAGS = $(filter-out $(CCASUWFLAGS), $(CFLAGS)) $(CCASEXFLAGS)
 
 # compile and generate dependency info
 
@@ -76,7 +76,7 @@ $(ASMOBJ): $(BINDIR)/$(MODULE)/%.o: %.s
 	$(Q)$(AS) $(ASFLAGS) -o $@ $(abspath $<)
 
 $(ASSMOBJ): $(BINDIR)/$(MODULE)/%.o: %.S
-	$(Q)$(CC) $(CFLAGS) $(INCLUDES) -MD -MP -c -o $@ $(abspath $<)
+	$(Q)$(CCAS) $(CCASFLAGS) $(INCLUDES) -MD -MP -c -o $@ $(abspath $<)
 
 # pull in dependency info for *existing* .o files
 # deleted header files will be silently ignored
diff --git a/Makefile.vars b/Makefile.vars
index 39e3abf0921d..68372649c543 100644
--- a/Makefile.vars
+++ b/Makefile.vars
@@ -27,9 +27,12 @@ export TARGET_ARCH           # The target platform name, in GCC triple notation,
 export PREFIX                # The prefix of the toolchain commands, usually "$(TARGET_ARCH)-", e.g. "arm-none-eabi-" or "msp430-".
 export CC                    # The C compiler to use.
 export CXX                   # The CXX compiler to use.
+export CCAS                  # The C compiler to use for assembler files, typically the same as CC.
 export CFLAGS                # The compiler flags. Must only ever be used with `+=`.
-export CXXUWFLAGS            # (Patters of) flags in CFLAGS, that should not be passed to CXX.
+export CXXUWFLAGS            # (Patterns of) flags in CFLAGS that should not be passed to CXX.
 export CXXEXFLAGS            # Additional flags that should be passed to CXX.
+export CCASUWFLAGS           # (Patterns of) flags in CFLAGS that should not be passed to CCAS.
+export CCASEXFLAGS           # Additional flags that should be passed to CCAS.
 export AR                    # The command to create the object file archives.
 export ARFLAGS               # Command-line options to pass to AR, default `rcs`.
 export AS                    # The assembler.
diff --git a/cpu/Makefile.include.gnu b/cpu/Makefile.include.gnu
index ea61b4cc7628..afa205eb506e 100644
--- a/cpu/Makefile.include.gnu
+++ b/cpu/Makefile.include.gnu
@@ -1,18 +1,19 @@
 export GDBPREFIX ?= $(PREFIX)
-export CC = $(PREFIX)gcc
-export CXX = $(PREFIX)g++
+export CC         = $(PREFIX)gcc
+export CXX        = $(PREFIX)g++
+export CCAS      ?= $(CC)
 ifeq ($(LTO),1)
-export AR = $(PREFIX)gcc-ar
+export AR         = $(PREFIX)gcc-ar
 else
-export AR = $(PREFIX)ar
+export AR         = $(PREFIX)ar
 endif
-export AS = $(PREFIX)as
-export LINK = $(PREFIX)gcc
-export SIZE = $(PREFIX)size
-export OBJCOPY = $(shell command -v $(PREFIX)objcopy gobjcopy objcopy | head -n 1)
+export AS         = $(PREFIX)as
+export LINK       = $(PREFIX)gcc
+export SIZE       = $(PREFIX)size
+export OBJCOPY   ?= $(shell command -v $(PREFIX)objcopy gobjcopy objcopy | head -n 1)
 ifeq ($(OBJCOPY),)
 $(warning objcopy not found. Hex file will not be created.)
-export OBJCOPY = true
+export OBJCOPY    = true
 endif
-export OBJDUMP = $(PREFIX)objdump
-export DBG = $(GDBPREFIX)gdb
+export OBJDUMP    = $(PREFIX)objdump
+export DBG        = $(GDBPREFIX)gdb
diff --git a/cpu/Makefile.include.llvm b/cpu/Makefile.include.llvm
index 222c27e90717..f797f6fa0464 100644
--- a/cpu/Makefile.include.llvm
+++ b/cpu/Makefile.include.llvm
@@ -9,6 +9,7 @@ export LLVMPREFIX :=
 endif
 export CC          = clang
 export CXX         = clang++
+export CCAS       ?= $(CC)
 export LINK        = $(CC)
 export AS          = $(LLVMPREFIX)as
 export AR          = $(LLVMPREFIX)ar