# ******************************************************************************
# (C) Automotive-Lighting Reutlingen GmbH  -  ALRT/EEG
#     Tuebinger Strasse 123, 72762 Reutlingen, Germany
# ******************************************************************************

# ------------------------------------------------------------------------------
# file   Hal_030_Flags.gmk
#
# \brief compiler/assembler/linker options on HAL level
#
# \descr
#
# ------------------------------------------------------------------------------

# Result of this file:
#  CFLAGS_DEFAULT (Compiler flags for C)
#  CFLAGS_NOWARN  (Compiler flags for C, all warnings disabled)
#  CFLAGS_DEBUG   (Compiler flags for C, debug info available and optimization disabled)
#  CPPFLAGS       (Compiler flags for C++)
#  AFLAGS         (Compiler flags for assembler)
#  LDFLAGS        (Compiler flags for linker)

C_DEFINES       := $(C_DEFINES)

C_DEFINES_TOOL_INTERNAL := $(C_DEFINES_TOOL_INTERNAL)         \
                           __GNUC__=9                         \
                           __attribute__()=

CFLAGS_BASE      = -gdwarf-2                                  \
                   -fno-exceptions                            \
                   -ffunction-sections                        \
                   -fdata-sections

CFLAGS_OPT_SPACE = -Os                                        \
                   -fno-inline-functions

CFLAGS_OPT_SPEED = -O2                                        \
                   -finline-functions                         \
                   -finline-limit=16

CFLAGS_OPT_DEBUG = -O0                                        \
                   -g                                         \
                   -fno-inline-functions

CFLAGS_WARN_NONE = -w

CFLAGS_WARN_ALL  = -Wall                                      \
                   -Wextra                                    \
                   -pedantic                                  \
                   -Wmain                                     \
                   -Wundef                                    \
                   -Wsign-conversion                          \
                   -Wunused-parameter                         \
                   -Wuninitialized                            \
                   -Wunreachable-code                         \
                   -Wswitch-default                           \
                   -Wcast-align                               \
                   -Wmissing-include-dirs                     \
                   -Winit-self                                \
                   -Wdouble-promotion                         \

ifeq ($(TYP_CORE),M0P)
CFLAGS_CORE_M0P  = -mabi=aapcs                               \
                   -mcpu=cortex-m0plus                       \
                   -mtune=cortex-m0plus                      \
                   -march=armv6s-m                           \
                   -mthumb                                   \
                   -mfloat-abi=soft                          \
                   -mno-long-calls

CFLAGS_CORE      = $(CFLAGS_CORE_M0P)

C_DEFINES       += __CORE_CORTEXM0PLUS__
endif

ifeq ($(TYP_CORE),M3)
CFLAGS_CORE_M3   = -mcpu=cortex-m3                           \
                   -mtune=cortex-m3                          \
                   -mthumb                                   \
                   -mfloat-abi=soft                          \
                   -mno-unaligned-access                     \
                   -mno-long-calls

CFLAGS_CORE      = $(CFLAGS_CORE_M3)
endif

ifeq ($(TYP_CORE),M4F)
CFLAGS_CORE_M4F  = -mcpu=cortex-m4                           \
                   -mtune=cortex-m4                          \
                   -mthumb                                   \
                   -mfloat-abi=hard                          \
                   -mfpu=fpv4-sp-d16                         \
                   -ffast-math                               \
                   -mno-unaligned-access                     \
                   -mno-long-calls

CFLAGS_CORE      = $(CFLAGS_CORE_M4F)
C_DEFINES       += __CORE_CORTEXM4__
endif

CFLAGS_DEFAULT   = -x c                                      \
                   -std=c99                                  \
                   $(CFLAGS_BASE)                            \
                   $(CFLAGS_CORE)                            \
                   $(CFLAGS_OPT_SPEED)                       \
                   $(CFLAGS_WARN_ALL)                        \
                   -Wunsuffixed-float-constants

CFLAGS_NOWARN    = -x c                                      \
                   -std=c99                                  \
                   $(CFLAGS_BASE)                            \
                   $(CFLAGS_CORE)                            \
                   $(CFLAGS_OPT_SPEED)                       \
                   $(CFLAGS_WARN_NONE)

CFLAGS_DEBUG     = -x c                                      \
                   -std=c99                                  \
                   $(CFLAGS_BASE)                            \
                   $(CFLAGS_CORE)                            \
                   $(CFLAGS_OPT_DEBUG)                       \
                   $(CFLAGS_WARN_ALL)

CPPFLAGS         = -x c++                                    \
                   -std=c++11                                \
                   -fno-rtti                                 \
                   -fno-weak                                 \
                   -fno-nonansi-builtins                     \
                   -fno-use-cxa-atexit                       \
                   -fno-enforce-eh-specs                     \
                   -fno-nonansi-builtins                     \
                   -fno-threadsafe-statics                   \
                   -fconstexpr-depth=16                      \
                   -fno-enforce-eh-specs                     \
                   -fno-use-cxa-atexit                       \
                   $(CFLAGS_BASE)                            \
                   $(CFLAGS_CORE)                            \
                   $(CFLAGS_OPT_SPEED)                       \
                   $(CFLAGS_WARN_ALL)

AFLAGS           = -x assembler                              \
                   $(CFLAGS_BASE)                            \
                   $(CFLAGS_CORE)

LDFLAGS          = -x none                                   \
                   -nostdlib                                 \
                   -nostartfiles                             \
                   -Wl,--gc-sections                         \
                   $(CFLAGS_BASE)                            \
                   $(CFLAGS_CORE)
