1################################################################################
2# \file toolchains.mk
3# \version 1.0
4#
5# \brief
6# Makefile to describe supported toolchains for Cypress MCUBoot based applications.
7#
8################################################################################
9# \copyright
10# Copyright 2018-2019 Cypress Semiconductor Corporation
11# SPDX-License-Identifier: Apache-2.0
12#
13# Licensed under the Apache License, Version 2.0 (the "License");
14# you may not use this file except in compliance with the License.
15# You may obtain a copy of the License at
16#
17#     http://www.apache.org/licenses/LICENSE-2.0
18#
19# Unless required by applicable law or agreed to in writing, software
20# distributed under the License is distributed on an "AS IS" BASIS,
21# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22# See the License for the specific language governing permissions and
23# limitations under the License.
24################################################################################
25
26include common_libs.mk
27
28# Compilers
29GCC_ARM	:= 1
30IAR		:= 2
31ARM		:= 3
32OTHER 	:= 4
33
34ifeq ($(MAKEINFO), 1)
35$(info $(COMPILER))
36endif
37# Detect host OS to make resolving compiler pathes easier
38UNAME_S := $(shell uname -s)
39ifeq ($(UNAME_S), Darwin)
40	HOST_OS = osx
41else
42	ifeq ($(UNAME_S), Linux)
43		HOST_OS = linux
44	else
45		HOST_OS = win
46	endif
47endif
48
49# Path to the compiler installation
50# NOTE: Absolute pathes for now for the sake of development
51ifeq ($(HOST_OS), win)
52	ifeq ($(COMPILER), GCC_ARM)
53		TOOLCHAIN_PATH ?= c:/Users/$(USERNAME)/ModusToolbox/tools_2.2/gcc
54		MY_TOOLCHAIN_PATH:=$(subst \,/,$(TOOLCHAIN_PATH))
55		TOOLCHAIN_PATH := $(MY_TOOLCHAIN_PATH)
56		GCC_PATH := $(TOOLCHAIN_PATH)
57		# executables
58		CC := "$(GCC_PATH)/bin/arm-none-eabi-gcc"
59		LD := $(CC)
60	endif
61
62else ifeq ($(HOST_OS), osx)
63	TOOLCHAIN_PATH ?= /opt/gcc-arm-none-eabi
64	GCC_PATH := $(TOOLCHAIN_PATH)
65
66	CC := "$(GCC_PATH)/bin/arm-none-eabi-gcc"
67	LD := $(CC)
68
69else ifeq ($(HOST_OS), linux)
70	TOOLCHAIN_PATH ?= /opt/gcc-arm-none-eabi
71	GCC_PATH := $(TOOLCHAIN_PATH)
72	# executables
73	CC := "$(GCC_PATH)/bin/arm-none-eabi-gcc"
74	LD := $(CC)
75endif
76
77PDL_ELFTOOL := "hal/tools/$(HOST_OS)/elf/cymcuelftool"
78
79OBJDUMP  := "$(GCC_PATH)/bin/arm-none-eabi-objdump"
80OBJCOPY  := "$(GCC_PATH)/bin/arm-none-eabi-objcopy"
81
82# Set flags for toolchain executables
83ifeq ($(COMPILER), GCC_ARM)
84	# set build-in compiler flags
85	CFLAGS_COMMON := -mcpu=cortex-$(CORE_SIFFX) -mthumb -mfloat-abi=soft -fno-stack-protector -ffunction-sections -fdata-sections -ffat-lto-objects -fstrict-aliasing -g -Wall -Wextra
86	ifeq ($(BUILDCFG), Debug)
87		CFLAGS_COMMON += -Og -g3
88	else ifeq ($(BUILDCFG), Release)
89		CFLAGS_COMMON += -Os -g
90	else
91$(error BUILDCFG : '$(BUILDCFG)' is not supported)
92	endif
93	# add defines and includes
94	CFLAGS := $(CFLAGS_COMMON) $(INCLUDES)
95	CC_DEPEND = -MD -MP -MF
96
97	LDFLAGS_COMMON := -mcpu=cortex-$(CORE_SIFFX) -mthumb -specs=nano.specs -ffunction-sections -fdata-sections  -Wl,--gc-sections -L "$(GCC_PATH)/lib/gcc/arm-none-eabi/7.2.1/thumb/v6-m" -ffat-lto-objects -g --enable-objc-gc
98	ifeq ($(BUILDCFG), Debug)
99		LDFLAGS_COMMON += -Og
100	else ifeq ($(BUILDCFG), Release)
101		LDFLAGS_COMMON += -Os
102	else
103$(error BUILDCFG : '$(BUILDCFG)' is not supported)
104	endif
105	LDFLAGS_NANO := -L "$(GCC_PATH)/arm-none-eabi/lib/thumb/v6-m"
106	LDFLAGS := $(LDFLAGS_COMMON) $(LDFLAGS_NANO)
107endif
108