1# 2# Build targets for a Cortex-M-based processor 3# 4 5# Cortex-M Environment Checks ################################################## 6 7# If building for the Cortex-M target, ensure that the user has specified a path 8# to the Cortex-M toolchain that they wish to use. 9ifeq ($(CORTEXM_TOOLS_PREFIX),) 10# Try to default to Android's Clang prebuilts if the tools prefix isn't 11# specified. 12include $(CHRE_PREFIX)/build/clang.mk 13endif # CORTEXM_TOOLS_PREFIX 14 15# Cortex-M Tools ############################################################### 16 17ifeq ($(IS_CLANG_TOOLCHAIN),) 18TARGET_AR = $(CORTEXM_TOOLS_PREFIX)/bin/arm-none-eabi-ar 19TARGET_CC = $(CORTEXM_TOOLS_PREFIX)/bin/arm-none-eabi-g++ 20TARGET_LD = $(CORTEXM_TOOLS_PREFIX)/bin/arm-none-eabi-ld 21else 22TARGET_AR = $(CLANG_TOOLCHAIN_PATH)/bin/llvm-ar 23TARGET_CC = $(CLANG_TOOLCHAIN_PATH)/bin/clang 24TARGET_LD = $(CLANG_TOOLCHAIN_PATH)/bin/ld.lld 25endif 26 27# Cortex-M Compiler Flags ###################################################### 28 29# Add Cortex-M compiler flags. 30TARGET_CFLAGS += $(CORTEXM_CFLAGS) 31 32# Code generation flags. 33GCC_CFLAGS += -mthumb 34GCC_CFLAGS += -mno-thumb-interwork 35GCC_CFLAGS += -ffast-math 36GCC_CFLAGS += -fsingle-precision-constant 37 38TARGET_CFLAGS += -ffunction-sections 39TARGET_CFLAGS += -fdata-sections 40TARGET_CFLAGS += -fshort-enums 41TARGET_CFLAGS += -fno-unwind-tables 42TARGET_CFLAGS += -mabi=aapcs 43 44ifneq ($(IS_NANOAPP_BUILD),) 45TARGET_CFLAGS += -fpic 46endif 47 48ifeq ($(IS_ARCHIVE_ONLY_BUILD), true) 49COMMON_CXX_CFLAGS += -fno-use-cxa-atexit 50endif 51 52# Sadly we must disable double promotion warnings due to logging macros. There 53# is a bug for this here: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53431 54TARGET_CFLAGS += -Wno-double-promotion 55 56# Cortex-M Shared Object Linker Flags ########################################## 57 58TARGET_SO_LDFLAGS += -shared 59TARGET_SO_LDFLAGS += -z max-page-size=0x8 60 61# Supported Cortex-M Architectures ############################################# 62 63CORTEXM_SUPPORTED_ARCHS = m4 m4_hardfp 64 65# Environment Checks ########################################################### 66 67# Ensure that an architecture is chosen. 68ifeq ($(filter $(CORTEXM_ARCH), $(CORTEXM_SUPPORTED_ARCHS)),) 69$(error "The CORTEXM_ARCH argument must be set to a supported architecture (\ 70 $(CORTEXM_SUPPORTED_ARCHS))") 71endif 72 73# Target Architecture ########################################################## 74 75# Set the Cortex-M architecture. 76ifeq ($(CORTEXM_ARCH), m4) 77GCC_CFLAGS += -mcpu=cortex-m4 78CLANG_CFLAGS += --target=arm-none-eabi 79TARGET_CFLAGS += -mfloat-abi=softfp 80TARGET_CFLAGS += -mfpu=fpv4-sp-d16 81endif 82 83ifeq ($(CORTEXM_ARCH), m4_hardfp) 84GCC_CFLAGS += -mcpu=cortex-m4 85CLANG_CFLAGS += --target=arm-none-eabi 86TARGET_CFLAGS += -mfloat-abi=hard 87TARGET_CFLAGS += -mfpu=fpv4-sp-d16 88endif 89 90 91ifeq ($(IS_CLANG_TOOLCHAIN),) 92TARGET_CFLAGS += $(GCC_CFLAGS) 93else 94TARGET_CFLAGS += $(CLANG_CFLAGS) 95endif 96 97# Optimization Level ########################################################### 98 99TARGET_CFLAGS += -O$(OPT_LEVEL) 100 101# Variant Specific Sources ##################################################### 102 103TARGET_VARIANT_SRCS += $(CORTEXM_SRCS) 104