blob: c4942d4c1aa76eebef6cea3c17c61476edfd95cf [file] [log] [blame]
# Copyright Statement:
# --------------------
# This software is protected by Copyright and the information contained
# herein is confidential. The software may not be copied and the information
# contained herein may not be used or disclosed except with the written
# permission of MediaTek Inc. (C) 2015
#
# BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
# THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
# RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
# AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
# NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
# SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
# SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
# THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
# NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
# SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
#
# BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
# LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
# AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
# OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
# MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
#
# THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
# WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
# LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
# RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
# THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
# *****************************
# Environment and Tools
# *****************************
ifndef COMPILER_VER
COMPILER_VER = MIPS_GCCV4
endif
ifeq ($(strip $(LTO_BUILD)),TRUE)
LINK_BY_GCC = TRUE
else
LINK_BY_GCC = FALSE
LTO_BUILD = FALSE
endif
ifdef COMPILER
ifeq ($(strip $(COMPILER)),GCC)
ifeq ($(strip $(COMPILER_VER)),MIPS_GCCV6)
ifneq ($(strip $(COMPILER_ISA)),NANOMIPS)
GCC_TOOL_CHAIN := ./tools/GCC/MIPS/6.3.0/linux
else
GCC_TOOL_CHAIN := ./tools/GCC/NANOMIPS/6.3.0/linux
endif
else ifeq ($(strip $(COMPILER_VER)),MIPS_GCCV4)
GCC_TOOL_CHAIN := ./tools/GCC/MIPS/4.9.2/linux
endif
ifeq ($(strip $(COMPILER_ARCH)),ARM)
VIA = @
DEPEND = -MMD -MF
BIN_FORMAT = -O binary
DIR_TOOL = $(strip $(DIR_TOOL))
ifeq ($(strip $(OS_VERSION)),MSWin32)
CROSS = .\mtk_tools\GCC\ARM\bin\arm-none-eabi-
CPL = $(CROSS)gcc.exe # compiler
CC = $(CROSS)gcc.exe -mthumb # compiler
CC32 = $(CROSS)gcc.exe -marm # compiler
CPPC = $(CROSS)g++.exe # C++ compiler
CPPC32 = $(CROSS)g++.exe -marm # compiler
LINK = $(CROSS)ld.exe # Linker
DUMP = $(CROSS)objdump.exe # Linker
ASM = $(CROSS)as # ARM assembler
LIB = $(CROSS)ar.exe # Library tool
BIN_CREATE = $(CROSS)objcopy # Binary tool
CPLUSFLAGS = $(CFLAGS)
MD = ""
endif
else
VIA = @
DEPEND = -MMD -MP -MF
BIN_FORMAT = -O binary
DIR_TOOL = $(strip $(DIR_TOOL))
ifeq ($(strip $(OS_VERSION)),MSWin32)
CROSS = .\mtk_tools\GCC\ARM\bin\arm-none-eabi-
CPL = $(CROSS)gcc.exe # compiler
CC = $(CROSS)gcc.exe -mthumb # compiler
CC32 = $(CROSS)gcc.exe -marm # compiler
CPPC = $(CROSS)g++.exe # C++ compiler
CPPC32 = $(CROSS)g++.exe -marm # compiler
LINK = $(CROSS)ld.exe # Linker
DUMP = $(CROSS)objdump.exe # Linker
ASM = $(CROSS)as # ARM assembler
LIB = $(CROSS)ar.exe # Library tool
BIN_CREATE = $(CROSS)objcopy # Binary tool
CPLUSFLAGS = $(CFLAGS)
MD = ""
else
ifeq ($(strip $(COMPILER_ISA)),NANOMIPS)
CROSS = $(strip $(GCC_TOOL_CHAIN))/bin/nanomips-elf-
else
CROSS = $(strip $(GCC_TOOL_CHAIN))/bin/mips-mti-elf-
endif
CPL = $(CROSS)gcc # compiler
CC = $(CROSS)gcc # compiler
CC32 = $(CROSS)gcc # compiler
CPPC = $(CROSS)g++ # C++ compiler
CPPC32 = $(CROSS)g++ # compiler
LINK = $(CROSS)ld # Linker
DUMP = $(CROSS)objdump # Linker
ASM = $(CROSS)as # ARM assembler
LIB = $(CROSS)ar # Library tool
BIN_CREATE = $(CROSS)objcopy # Binary tool
GDB_CREATE = $(CROSS)gdb # Gdb tool
CPLUSFLAGS = $(CFLAGS)
MD = ""
endif
endif
endif
endif
ifeq ($(strip $(LINK_BY_GCC)),TRUE)
LINK := $(CROSS)gcc
LIB := $(CROSS)gcc-ar
endif
# *****************************
# C options COPTION16 for thumb mode and COPTION32 for arm mode
# *****************************
ifeq ($(strip $(COMPILER)),GCC)
CFLAGS := -Wno-attributes -Wno-pragmas -fstrict-volatile-bitfields
ifeq ($(strip $(GCC_WARN_AS_ERROR)),TRUE)
ifeq ($(strip $(NO_WARNING_AS_ERROR)),FALSE)
CFLAGS += -Werror
endif
endif
endif
ifneq ($(filter $(strip $(SUPPORT_PLATFORM)), $(strip $(PLATFORM))),)
ifeq ($(strip $(COMPILER)),GCC)
ifeq ($(strip $(COMPILER_ARCH)),ARM)
DWARF_FLAGS := -gdwarf-4
PLATFORM_FLAGS := -march=armv7-r -mcpu=cortex-r4 -mlittle-endian -Wa,-mimplicit-it=always -mabi=aapcs
PLATFORM_AFLAGS := -march=armv7-r -mcpu=cortex-r4 -mlittle-endian -mimplicit-it=always -mapcs-32
OFLAGS := -Os -fno-strict-aliasing -fno-common -fno-exceptions -ffunction-sections -fdata-sections
OAFLAGS := $(DWARF_FLAGS)
CFLAGS += $(PLATFORM_FLAGS) $(OFLAGS) -fno-delete-null-pointer-checks -Wall -c -mno-unaligned-access -fshort-wchar
ifeq ($(strip $(OS_VERSION)),MSWin32)
LINK_SEARCH_PATH = -L "./tools/GCC/ARM/4.9.3/win/arm-none-eabi/lib/armv7-ar/thumb" \
-L "./tools/GCC/ARM/4.9.3/win/lib/gcc/arm-none-eabi/4.9.3/armv7-ar/thumb"
endif
else
ifneq ($(strip $(OS_VERSION)),MSWin32)
DWARF_FLAGS := -gdwarf-4
ifeq ($(strip $(COMPILER_ISA)),MIPS16)
PLATFORM_FLAGS := -march=interAptiv-mr2 -mips16 -mmips16e2 -EL -mabi=32 -msoft-float -mno-dsp -mmt -mno-gpopt -mno-long-calls -G0 -minterlink-mips16 -mdead-loads -mblockmov-limit=0
PLATFORM_AFLAGS := -march=interAptiv-mr2 -mips16 -mmips16e2 -EL -msoft-float -mno-dsp -mmt -G0
else ifeq ($(strip $(COMPILER_ISA)),MIPS32)
PLATFORM_FLAGS := -march=interAptiv-mr2 -EL -mabi=32 -msoft-float -mno-dsp -mmt -mno-gpopt -mno-long-calls -G0 -minterlink-compressed -mdead-loads -mblockmov-limit=0
PLATFORM_AFLAGS := -march=interAptiv-mr2 -EL -msoft-float -mno-dsp -mmt -G0
else #nanomips
PLATFORM_FLAGS := -std=c11 -march=i7200 -EL -msoft-float -mmt -mno-gpopt -mno-long-calls -G0 -mblockmov-limit=0 -mno-dsp
PLATFORM_AFLAGS := -march=i7200 -EL -msoft-float -mmt -G0 -mno-dsp
EXTRA_AFLAGS :=
endif
OFLAGS := -Os -fno-builtin-printf -fstrict-aliasing -fno-common -fno-exceptions -ffunction-sections -fdata-sections
OAFLAGS := $(DWARF_FLAGS)
ifeq ($(strip $(COMPILER_VER)),MIPS_GCCV6)
CFLAGS += $(PLATFORM_FLAGS) $(OFLAGS) -fno-delete-null-pointer-checks -Wall -c -fshort-wchar -fshort-enums -std=c11 -D_GNU_SOURCE
ifeq ($(strip $(COMPILER_ISA)),NANOMIPS)
LINK_SEARCH_PATH = -L "./tools/GCC/NANOMIPS/6.3.0/linux/nanomips-elf/lib/nanomips-r6-soft-newlib/lib" \
-L "./tools/GCC/NANOMIPS/6.3.0/linux/lib/gcc/nanomips-elf/6.3.0/nanomips-r6-soft-newlib/lib"
else
LINK_SEARCH_PATH = -L "./tools/GCC/MIPS/6.3.0/linux/mips-mti-elf/lib/mipsel-r2-soft-newlib/lib" \
-L "./tools/GCC/MIPS/6.3.0/linux/lib/gcc/mips-mti-elf/6.3.0/mipsel-r2-soft-newlib/lib"
endif
else ifeq ($(strip $(COMPILER_VER)),MIPS_GCCV4)
CFLAGS += $(PLATFORM_FLAGS) $(OFLAGS) -fno-delete-null-pointer-checks -Wall -c -fshort-wchar -fshort-enums
LINK_SEARCH_PATH = -L "./tools/GCC/MIPS/4.9.2/linux/mips-mti-elf/lib/mipsel-r2-soft-newlib/lib" \
-L "./tools/GCC/MIPS/4.9.2/linux/lib/gcc/mips-mti-elf/4.9.2/mipsel-r2-soft-newlib/lib"
endif
endif
endif
endif
endif
CPLUSFLAGS := $(filter-out -fgnu89-inline -std=c11,$(CFLAGS))
CFLAGS += $(CUSTOM_CFLAGS)
CPLUSFLAGS += $(CUSTOM_CFLAGS)
BUILD_WARNING_CFLAGS :=
-include make/common/build_warning_def.mak
ifeq ($(strip $(NO_WARNING_AS_ERROR)),FALSE)
ifneq ($(strip $(BUILD_WARNING_CFLAGS)),)
ifeq ($(filter $(strip $(PROJECT_NAME))_$(strip $(FLAVOR)),$(CLOSE_WARNING_AS_ERROR_PROJECT)),)
CFLAGS += $(BUILD_WARNING_CFLAGS)
CPLUSFLAGS += $(BUILD_WARNING_CFLAGS)
endif
endif
endif
# *****************************
# assembly option AOPTION16 for Thumb mode and AOPTION32 for Arm mode
# *****************************
ifeq ($(strip $(COMPILER)),GCC)
AFLAGS := $(PLATFORM_AFLAGS) $(OAFLAGS) -g
endif # end of " COMPILER == GCC "
ifeq ($(strip $(LINK_BY_GCC)),TRUE)
LINK_OPTION_PREFIX := -Wl,
else
LINK_OPTION_PREFIX :=
endif
# *****************************
# Macros definition for GCC
# *****************************
ifeq ($(strip $(COMPILER)),GCC)
ifeq ($(strip $(COMPILER_ARCH)),ARM)
WRAP_LIST = --wrap=memcpy --wrap=memset --wrap=memclr --wrap=strcmp --wrap=sprintf --wrap=vsprintf --wrap=snprintf --wrap=vsnprintf --wrap=sscanf --wrap=vsscanf \
--wrap=raise --wrap=__aeabi_div0 --wrap=setlocale --wrap=on_exit --wrap=getenv --wrap=clock --wrap=puts \
--wrap=putchar --wrap=printf --wrap=vprintf --wrap=malloc --wrap=_malloc_r --wrap=calloc --wrap=_calloc_r --wrap=realloc --wrap=_realloc_r \
--wrap=free --wrap=_free_r --wrap=qsort --wrap=fprintf --wrap=fflush --wrap=_fflush_r --wrap=setbuf --wrap=setvbuf --wrap=fscanf \
--wrap=scanf --wrap=vfscanf --wrap=vscanf --wrap=vfprintf --wrap=fgetc --wrap=fgets --wrap=getc --wrap=getchar --wrap=gets \
--wrap=putc --wrap=ungetc --wrap=_ungetc_r --wrap=fgetpos --wrap=fseek --wrap=fsetpos --wrap=ftell --wrap=rewind --wrap=clearerr \
--wrap=feof --wrap=ferror --wrap=fopen --wrap=freopen --wrap=_fclose_r --wrap=fclose --wrap=fprintf --wrap=fread --wrap=fwrite \
--wrap=fputc --wrap=fputs --wrap=perror
else
WRAP_LIST = $(strip $(LINK_OPTION_PREFIX))--wrap=memset $(strip $(LINK_OPTION_PREFIX))--wrap=memcpy $(strip $(LINK_OPTION_PREFIX))--wrap=setlocale $(strip $(LINK_OPTION_PREFIX))--wrap=clock $(strip $(LINK_OPTION_PREFIX))--wrap=__cxa_atexit $(strip $(LINK_OPTION_PREFIX))--wrap=rand $(strip $(LINK_OPTION_PREFIX))--wrap=srand \
$(strip $(LINK_OPTION_PREFIX))--wrap=malloc $(strip $(LINK_OPTION_PREFIX))--wrap=_malloc_r $(strip $(LINK_OPTION_PREFIX))--wrap=calloc $(strip $(LINK_OPTION_PREFIX))--wrap=_calloc_r $(strip $(LINK_OPTION_PREFIX))--wrap=realloc $(strip $(LINK_OPTION_PREFIX))--wrap=_realloc_r $(strip $(LINK_OPTION_PREFIX))--wrap=free $(strip $(LINK_OPTION_PREFIX))--wrap=_free_r $(strip $(LINK_OPTION_PREFIX))--wrap=printf $(strip $(LINK_OPTION_PREFIX))--wrap=vprintf $(strip $(LINK_OPTION_PREFIX))--wrap=sprintf $(strip $(LINK_OPTION_PREFIX))--wrap=snprintf $(strip $(LINK_OPTION_PREFIX))--wrap=vsprintf $(strip $(LINK_OPTION_PREFIX))--wrap=vsnprintf
endif
# *************************
# Settings for TARGET
# *************************
ifeq ($(strip $(COMPILER_ARCH)),ARM)
LNKOPT = $(strip $(WRAP_LIST)) -Bstatic --cref --warn-common --gc-sections --nmagic --emit-relocs \
-o $(strip $(TARGDIR))\$(IMG_FILE) \
-Map $(strip $(TARGDIR))\$(MAP_FILE) \
-dT $(strip $(SCATTERFILE)) \
$(strip $(LINK_SEARCH_PATH))
else
LNKOPT = $(strip $(WRAP_LIST)) -EL $(strip $(LINK_OPTION_PREFIX))-Bstatic $(strip $(LINK_OPTION_PREFIX))--cref \
$(strip $(LINK_OPTION_PREFIX))--warn-common $(strip $(LINK_OPTION_PREFIX))--gc-sections \
$(strip $(LINK_OPTION_PREFIX))--nmagic \
$(strip $(LINK_OPTION_PREFIX))--threads \
$(strip $(LINK_OPTION_PREFIX))--thread-count-initial $(strip $(LINK_OPTION_PREFIX))10 \
$(strip $(LINK_OPTION_PREFIX))--thread-count-middle $(strip $(LINK_OPTION_PREFIX))1 \
$(strip $(LINK_OPTION_PREFIX))--thread-count-final $(strip $(LINK_OPTION_PREFIX))5 \
$(strip $(LINK_OPTION_PREFIX))--preread-archive-symbols \
-o $(strip $(TARGDIR))\$(IMG_FILE) \
$(strip $(LINK_SEARCH_PATH))
ifeq ($(strip $(LINK_BY_GCC)),TRUE)
LNKOPT += $(strip $(LINK_SEARCH_PATH)) $(filter-out -c,$(CFLAGS)) \
$(strip $(LINK_OPTION_PREFIX))-Map,$(strip $(TARGDIR))\$(MAP_FILE) \
$(strip $(LINK_OPTION_PREFIX))-dT,$(strip $(SCATTERFILE)) \
-nostartfiles
else
LNKOPT += $(strip $(LINK_OPTION_PREFIX))-Map $(strip $(TARGDIR))\$(MAP_FILE) \
$(strip $(LINK_OPTION_PREFIX))-dT $(strip $(SCATTERFILE))
endif
endif
ifeq ($(strip $(COMPILER_ISA)),NANOMIPS)
LNKOPT += $(strip $(LINK_OPTION_PREFIX))--discard-locals $(strip $(LINK_OPTION_PREFIX))--no-print-map-discarded
endif
ifeq ($(strip $(LTO_BUILD)),TRUE)
LNKOPT += -flto -fno-fat-lto-objects
endif
ifneq ($(filter $(strip $(SUPPORT_PLATFORM)), $(strip $(PLATFORM))),)
ifeq ($(strip $(COMPILER_ARCH)),ARM)
LNKOPT += --thumb-entry=INT_Vectors
else
LNKOPT += --entry=INT_Vectors
endif
endif
endif #ifeq ($(strip $(COMPILER)),GCC)