blob: 38684363f2b6e7f31cc8e664db5609bba7389e6d [file] [log] [blame]
Roman Okhrimenko89ecdac2020-02-28 17:05:55 +02001################################################################################
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
26# Compilers
27GCC_ARM := 1
28IAR := 2
29ARM := 3
30OTHER := 4
31
32ifeq ($(MAKEINFO), 1)
33$(info $(COMPILER))
34endif
35# Detect host OS to make resolving compiler pathes easier
36UNAME_S := $(shell uname -s)
37ifeq ($(UNAME_S), Darwin)
38 HOST_OS = osx
39else
40 ifeq ($(UNAME_S), Linux)
41 HOST_OS = linux
42 else
43 HOST_OS = win
44 endif
45endif
46
47# Path to the compiler installation
48# NOTE: Absolute pathes for now for the sake of development
49ifeq ($(HOST_OS), win)
50 ifeq ($(COMPILER), GCC_ARM)
51 TOOLCHAIN_PATH ?= c:/Users/$(USERNAME)/ModusToolbox_1.0/tools/gcc-7.2.1-1.0
52 MY_TOOLCHAIN_PATH:=$(subst \,/,$(TOOLCHAIN_PATH))
53 TOOLCHAIN_PATH := $(MY_TOOLCHAIN_PATH)
54 GCC_PATH := $(TOOLCHAIN_PATH)
55 # executables
56 CC := "$(GCC_PATH)/bin/arm-none-eabi-gcc"
57 LD := $(CC)
58
59 else ifeq ($(COMPILER), IAR)
60 IAR_PATH := C:/Program Files (x86)/IAR Systems/Embedded Workbench 8.0/arm
61 # executables
62 CC := "$(IAR_PATH)/bin/iccarm.exe"
63 AS := "$(IAR_PATH)/bin/iasmarm.exe"
64 LD := "$(IAR_PATH)/bin/ilinkarm.exe"
65 endif
66
67else ifeq ($(HOST_OS), osx)
68 TOOLCHAIN_PATH ?= /opt/gcc-arm-none-eabi
69 GCC_PATH := $(TOOLCHAIN_PATH)
70
71 CC := "$(GCC_PATH)/bin/arm-none-eabi-gcc"
72 LD := $(CC)
73
74else ifeq ($(HOST_OS), linux)
75 TOOLCHAIN_PATH ?= /usr/bin/gcc-arm-none-eabi/bin/arm-none-eabi-gcc
76 GCC_PATH := $(TOOLCHAIN_PATH)
77 # executables
78 CC := "$(GCC_PATH)/bin/arm-none-eabi-gcc"
79 LD := $(CC)
80endif
81
82PDL_ELFTOOL := "hal/tools/$(HOST_OS)/elf/cymcuelftool"
83
84OBJDUMP := "$(GCC_PATH)/bin/arm-none-eabi-objdump"
85OBJCOPY := "$(GCC_PATH)/bin/arm-none-eabi-objcopy"
86
87# Set flags for toolchain executables
88ifeq ($(COMPILER), GCC_ARM)
89 # set build-in compiler flags
90 CFLAGS_COMMON := -mcpu=cortex-m4 -mthumb -mfloat-abi=soft -fno-stack-protector -ffunction-sections -fdata-sections -ffat-lto-objects -fstrict-aliasing -g -Wall -Wextra
91 ifeq ($(BUILDCFG), Debug)
92 CFLAGS_COMMON += -Og -g3
93 else ifeq ($(BUILDCFG), Release)
94 CFLAGS_COMMON += -Os -g
95 else
96 $(error BUILDCFG : '$(BUILDCFG)' is not supported)
97 endif
98 # add defines and includes
99 CFLAGS := $(CFLAGS_COMMON) $(INCLUDES)
100 CC_DEPEND = -MD -MP -MF
101
102 LDFLAGS_COMMON := -mcpu=cortex-m4 -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
103 ifeq ($(BUILDCFG), Debug)
104 LDFLAGS_COMMON += -Og
105 else ifeq ($(BUILDCFG), Release)
106 LDFLAGS_COMMON += -Os
107 else
108 $(error BUILDCFG : '$(BUILDCFG)' is not supported)
109 endif
110 LDFLAGS_NANO := -L "$(GCC_PATH)/arm-none-eabi/lib/thumb/v6-m"
111 LDFLAGS := $(LDFLAGS_COMMON) $(LDFLAGS_NANO)
112
113else ifeq ($(COMPILER), IAR)
114
115 CFLAGS := --debug --endian=little --cpu=Cortex-M4 -e --fpu=None --dlib_config "$(IAR_PATH)\INC\c\DLib_Config_Normal.h"
116 CFLAGS += -Ohz --silent
117 CFLAGS += $(INCLUDES)
118 CC_DEPEND = --dependencies
119
120 AS_FLAGS := -s+ "-M<>" -w+ -r --cpu Cortex-M4 --fpu None -S
121
122 LINKER_SCRIPT := $(CHIP_SERIES).icf
123
124 #options to extend stack analize: --log call_graph --log_file $(OUT)/stack_usage_$(SUFFIX).txt
125 LDFLAGS_STACK_USAGE := --stack_usage_control $(STACK_CONTROL_FILE) --diag_suppress=Ls015 --diag_suppress=Ls016
126 LDFLAGS_COMMON := --vfe --text_out locale --silent --inline --merge_duplicate_sections
127 LDFLAGS := $(LDFLAGS_COMMON) $(LDFLAGS_STACK_USAGE) --config $(LINKER_SCRIPT) --map $(OUT_TARGET)/$(APP_NAME).map --entry Cy_FB_ResetHandler --no_exceptions
128endif