yu.dong | c33b307 | 2024-08-21 23:14:49 -0700 | [diff] [blame^] | 1 | # Copyright Statement: |
| 2 | # -------------------- |
| 3 | # This software is protected by Copyright and the information contained |
| 4 | # herein is confidential. The software may not be copied and the information |
| 5 | # contained herein may not be used or disclosed except with the written |
| 6 | # permission of MediaTek Inc. (C) 2015 |
| 7 | # |
| 8 | # BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES |
| 9 | # THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE") |
| 10 | # RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON |
| 11 | # AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES, |
| 12 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF |
| 13 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT. |
| 14 | # NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE |
| 15 | # SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR |
| 16 | # SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH |
| 17 | # THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO |
| 18 | # NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S |
| 19 | # SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM. |
| 20 | # |
| 21 | # BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE |
| 22 | # LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE, |
| 23 | # AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE, |
| 24 | # OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO |
| 25 | # MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. |
| 26 | # |
| 27 | # THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE |
| 28 | # WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF |
| 29 | # LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND |
| 30 | # RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER |
| 31 | # THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC). |
| 32 | |
| 33 | # ***************************** |
| 34 | # Environment and Tools |
| 35 | # ***************************** |
| 36 | ifndef COMPILER_VER |
| 37 | COMPILER_VER = MIPS_GCCV4 |
| 38 | endif |
| 39 | |
| 40 | ifeq ($(strip $(LTO_BUILD)),TRUE) |
| 41 | LINK_BY_GCC = TRUE |
| 42 | else |
| 43 | LINK_BY_GCC = FALSE |
| 44 | LTO_BUILD = FALSE |
| 45 | endif |
| 46 | |
| 47 | ifdef COMPILER |
| 48 | ifeq ($(strip $(COMPILER)),GCC) |
| 49 | ifeq ($(strip $(COMPILER_VER)),MIPS_GCCV6) |
| 50 | ifneq ($(strip $(COMPILER_ISA)),NANOMIPS) |
| 51 | GCC_TOOL_CHAIN := ./tools/GCC/MIPS/6.3.0/linux |
| 52 | else |
| 53 | GCC_TOOL_CHAIN := ./tools/GCC/NANOMIPS/6.3.0/linux |
| 54 | endif |
| 55 | else ifeq ($(strip $(COMPILER_VER)),MIPS_GCCV4) |
| 56 | GCC_TOOL_CHAIN := ./tools/GCC/MIPS/4.9.2/linux |
| 57 | endif |
| 58 | ifeq ($(strip $(COMPILER_ARCH)),ARM) |
| 59 | VIA = @ |
| 60 | DEPEND = -MMD -MF |
| 61 | BIN_FORMAT = -O binary |
| 62 | DIR_TOOL = $(strip $(DIR_TOOL)) |
| 63 | ifeq ($(strip $(OS_VERSION)),MSWin32) |
| 64 | CROSS = .\mtk_tools\GCC\ARM\bin\arm-none-eabi- |
| 65 | CPL = $(CROSS)gcc.exe # compiler |
| 66 | CC = $(CROSS)gcc.exe -mthumb # compiler |
| 67 | CC32 = $(CROSS)gcc.exe -marm # compiler |
| 68 | CPPC = $(CROSS)g++.exe # C++ compiler |
| 69 | CPPC32 = $(CROSS)g++.exe -marm # compiler |
| 70 | LINK = $(CROSS)ld.exe # Linker |
| 71 | DUMP = $(CROSS)objdump.exe # Linker |
| 72 | ASM = $(CROSS)as # ARM assembler |
| 73 | LIB = $(CROSS)ar.exe # Library tool |
| 74 | BIN_CREATE = $(CROSS)objcopy # Binary tool |
| 75 | CPLUSFLAGS = $(CFLAGS) |
| 76 | MD = "" |
| 77 | endif |
| 78 | else |
| 79 | VIA = @ |
| 80 | DEPEND = -MMD -MP -MF |
| 81 | BIN_FORMAT = -O binary |
| 82 | DIR_TOOL = $(strip $(DIR_TOOL)) |
| 83 | ifeq ($(strip $(OS_VERSION)),MSWin32) |
| 84 | CROSS = .\mtk_tools\GCC\ARM\bin\arm-none-eabi- |
| 85 | CPL = $(CROSS)gcc.exe # compiler |
| 86 | CC = $(CROSS)gcc.exe -mthumb # compiler |
| 87 | CC32 = $(CROSS)gcc.exe -marm # compiler |
| 88 | CPPC = $(CROSS)g++.exe # C++ compiler |
| 89 | CPPC32 = $(CROSS)g++.exe -marm # compiler |
| 90 | LINK = $(CROSS)ld.exe # Linker |
| 91 | DUMP = $(CROSS)objdump.exe # Linker |
| 92 | ASM = $(CROSS)as # ARM assembler |
| 93 | LIB = $(CROSS)ar.exe # Library tool |
| 94 | BIN_CREATE = $(CROSS)objcopy # Binary tool |
| 95 | CPLUSFLAGS = $(CFLAGS) |
| 96 | MD = "" |
| 97 | else |
| 98 | ifeq ($(strip $(COMPILER_ISA)),NANOMIPS) |
| 99 | CROSS = $(strip $(GCC_TOOL_CHAIN))/bin/nanomips-elf- |
| 100 | else |
| 101 | CROSS = $(strip $(GCC_TOOL_CHAIN))/bin/mips-mti-elf- |
| 102 | endif |
| 103 | CPL = $(CROSS)gcc # compiler |
| 104 | CC = $(CROSS)gcc # compiler |
| 105 | CC32 = $(CROSS)gcc # compiler |
| 106 | CPPC = $(CROSS)g++ # C++ compiler |
| 107 | CPPC32 = $(CROSS)g++ # compiler |
| 108 | LINK = $(CROSS)ld # Linker |
| 109 | DUMP = $(CROSS)objdump # Linker |
| 110 | ASM = $(CROSS)as # ARM assembler |
| 111 | LIB = $(CROSS)ar # Library tool |
| 112 | BIN_CREATE = $(CROSS)objcopy # Binary tool |
| 113 | GDB_CREATE = $(CROSS)gdb # Gdb tool |
| 114 | CPLUSFLAGS = $(CFLAGS) |
| 115 | MD = "" |
| 116 | endif |
| 117 | endif |
| 118 | endif |
| 119 | endif |
| 120 | |
| 121 | ifeq ($(strip $(LINK_BY_GCC)),TRUE) |
| 122 | LINK := $(CROSS)gcc |
| 123 | LIB := $(CROSS)gcc-ar |
| 124 | endif |
| 125 | |
| 126 | # ***************************** |
| 127 | # C options COPTION16 for thumb mode and COPTION32 for arm mode |
| 128 | # ***************************** |
| 129 | ifeq ($(strip $(COMPILER)),GCC) |
| 130 | CFLAGS := -Wno-attributes -Wno-pragmas -fstrict-volatile-bitfields |
| 131 | ifeq ($(strip $(GCC_WARN_AS_ERROR)),TRUE) |
| 132 | ifeq ($(strip $(NO_WARNING_AS_ERROR)),FALSE) |
| 133 | CFLAGS += -Werror |
| 134 | endif |
| 135 | endif |
| 136 | endif |
| 137 | |
| 138 | ifneq ($(filter $(strip $(SUPPORT_PLATFORM)), $(strip $(PLATFORM))),) |
| 139 | ifeq ($(strip $(COMPILER)),GCC) |
| 140 | ifeq ($(strip $(COMPILER_ARCH)),ARM) |
| 141 | DWARF_FLAGS := -gdwarf-4 |
| 142 | PLATFORM_FLAGS := -march=armv7-r -mcpu=cortex-r4 -mlittle-endian -Wa,-mimplicit-it=always -mabi=aapcs |
| 143 | PLATFORM_AFLAGS := -march=armv7-r -mcpu=cortex-r4 -mlittle-endian -mimplicit-it=always -mapcs-32 |
| 144 | OFLAGS := -Os -fno-strict-aliasing -fno-common -fno-exceptions -ffunction-sections -fdata-sections |
| 145 | OAFLAGS := $(DWARF_FLAGS) |
| 146 | CFLAGS += $(PLATFORM_FLAGS) $(OFLAGS) -fno-delete-null-pointer-checks -Wall -c -mno-unaligned-access -fshort-wchar |
| 147 | ifeq ($(strip $(OS_VERSION)),MSWin32) |
| 148 | LINK_SEARCH_PATH = -L "./tools/GCC/ARM/4.9.3/win/arm-none-eabi/lib/armv7-ar/thumb" \ |
| 149 | -L "./tools/GCC/ARM/4.9.3/win/lib/gcc/arm-none-eabi/4.9.3/armv7-ar/thumb" |
| 150 | endif |
| 151 | else |
| 152 | ifneq ($(strip $(OS_VERSION)),MSWin32) |
| 153 | DWARF_FLAGS := -gdwarf-4 |
| 154 | ifeq ($(strip $(COMPILER_ISA)),MIPS16) |
| 155 | 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 |
| 156 | PLATFORM_AFLAGS := -march=interAptiv-mr2 -mips16 -mmips16e2 -EL -msoft-float -mno-dsp -mmt -G0 |
| 157 | else ifeq ($(strip $(COMPILER_ISA)),MIPS32) |
| 158 | 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 |
| 159 | PLATFORM_AFLAGS := -march=interAptiv-mr2 -EL -msoft-float -mno-dsp -mmt -G0 |
| 160 | else #nanomips |
| 161 | PLATFORM_FLAGS := -std=c11 -march=i7200 -EL -msoft-float -mmt -mno-gpopt -mno-long-calls -G0 -mblockmov-limit=0 -mno-dsp |
| 162 | PLATFORM_AFLAGS := -march=i7200 -EL -msoft-float -mmt -G0 -mno-dsp |
| 163 | EXTRA_AFLAGS := |
| 164 | endif |
| 165 | OFLAGS := -Os -fno-builtin-printf -fstrict-aliasing -fno-common -fno-exceptions -ffunction-sections -fdata-sections |
| 166 | OAFLAGS := $(DWARF_FLAGS) |
| 167 | ifeq ($(strip $(COMPILER_VER)),MIPS_GCCV6) |
| 168 | CFLAGS += $(PLATFORM_FLAGS) $(OFLAGS) -fno-delete-null-pointer-checks -Wall -c -fshort-wchar -fshort-enums -std=c11 -D_GNU_SOURCE |
| 169 | ifeq ($(strip $(COMPILER_ISA)),NANOMIPS) |
| 170 | LINK_SEARCH_PATH = -L "./tools/GCC/NANOMIPS/6.3.0/linux/nanomips-elf/lib/nanomips-r6-soft-newlib/lib" \ |
| 171 | -L "./tools/GCC/NANOMIPS/6.3.0/linux/lib/gcc/nanomips-elf/6.3.0/nanomips-r6-soft-newlib/lib" |
| 172 | else |
| 173 | LINK_SEARCH_PATH = -L "./tools/GCC/MIPS/6.3.0/linux/mips-mti-elf/lib/mipsel-r2-soft-newlib/lib" \ |
| 174 | -L "./tools/GCC/MIPS/6.3.0/linux/lib/gcc/mips-mti-elf/6.3.0/mipsel-r2-soft-newlib/lib" |
| 175 | endif |
| 176 | else ifeq ($(strip $(COMPILER_VER)),MIPS_GCCV4) |
| 177 | CFLAGS += $(PLATFORM_FLAGS) $(OFLAGS) -fno-delete-null-pointer-checks -Wall -c -fshort-wchar -fshort-enums |
| 178 | LINK_SEARCH_PATH = -L "./tools/GCC/MIPS/4.9.2/linux/mips-mti-elf/lib/mipsel-r2-soft-newlib/lib" \ |
| 179 | -L "./tools/GCC/MIPS/4.9.2/linux/lib/gcc/mips-mti-elf/4.9.2/mipsel-r2-soft-newlib/lib" |
| 180 | endif |
| 181 | endif |
| 182 | endif |
| 183 | endif |
| 184 | endif |
| 185 | |
| 186 | CPLUSFLAGS := $(filter-out -fgnu89-inline -std=c11,$(CFLAGS)) |
| 187 | |
| 188 | CFLAGS += $(CUSTOM_CFLAGS) |
| 189 | CPLUSFLAGS += $(CUSTOM_CFLAGS) |
| 190 | |
| 191 | BUILD_WARNING_CFLAGS := |
| 192 | -include make/common/build_warning_def.mak |
| 193 | ifeq ($(strip $(NO_WARNING_AS_ERROR)),FALSE) |
| 194 | ifneq ($(strip $(BUILD_WARNING_CFLAGS)),) |
| 195 | ifeq ($(filter $(strip $(PROJECT_NAME))_$(strip $(FLAVOR)),$(CLOSE_WARNING_AS_ERROR_PROJECT)),) |
| 196 | CFLAGS += $(BUILD_WARNING_CFLAGS) |
| 197 | CPLUSFLAGS += $(BUILD_WARNING_CFLAGS) |
| 198 | endif |
| 199 | endif |
| 200 | endif |
| 201 | |
| 202 | # ***************************** |
| 203 | # assembly option AOPTION16 for Thumb mode and AOPTION32 for Arm mode |
| 204 | # ***************************** |
| 205 | ifeq ($(strip $(COMPILER)),GCC) |
| 206 | AFLAGS := $(PLATFORM_AFLAGS) $(OAFLAGS) -g |
| 207 | endif # end of " COMPILER == GCC " |
| 208 | |
| 209 | ifeq ($(strip $(LINK_BY_GCC)),TRUE) |
| 210 | LINK_OPTION_PREFIX := -Wl, |
| 211 | else |
| 212 | LINK_OPTION_PREFIX := |
| 213 | endif |
| 214 | |
| 215 | # ***************************** |
| 216 | # Macros definition for GCC |
| 217 | # ***************************** |
| 218 | ifeq ($(strip $(COMPILER)),GCC) |
| 219 | ifeq ($(strip $(COMPILER_ARCH)),ARM) |
| 220 | WRAP_LIST = --wrap=memcpy --wrap=memset --wrap=memclr --wrap=strcmp --wrap=sprintf --wrap=vsprintf --wrap=snprintf --wrap=vsnprintf --wrap=sscanf --wrap=vsscanf \ |
| 221 | --wrap=raise --wrap=__aeabi_div0 --wrap=setlocale --wrap=on_exit --wrap=getenv --wrap=clock --wrap=puts \ |
| 222 | --wrap=putchar --wrap=printf --wrap=vprintf --wrap=malloc --wrap=_malloc_r --wrap=calloc --wrap=_calloc_r --wrap=realloc --wrap=_realloc_r \ |
| 223 | --wrap=free --wrap=_free_r --wrap=qsort --wrap=fprintf --wrap=fflush --wrap=_fflush_r --wrap=setbuf --wrap=setvbuf --wrap=fscanf \ |
| 224 | --wrap=scanf --wrap=vfscanf --wrap=vscanf --wrap=vfprintf --wrap=fgetc --wrap=fgets --wrap=getc --wrap=getchar --wrap=gets \ |
| 225 | --wrap=putc --wrap=ungetc --wrap=_ungetc_r --wrap=fgetpos --wrap=fseek --wrap=fsetpos --wrap=ftell --wrap=rewind --wrap=clearerr \ |
| 226 | --wrap=feof --wrap=ferror --wrap=fopen --wrap=freopen --wrap=_fclose_r --wrap=fclose --wrap=fprintf --wrap=fread --wrap=fwrite \ |
| 227 | --wrap=fputc --wrap=fputs --wrap=perror |
| 228 | else |
| 229 | 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 \ |
| 230 | $(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 |
| 231 | endif |
| 232 | |
| 233 | # ************************* |
| 234 | # Settings for TARGET |
| 235 | # ************************* |
| 236 | ifeq ($(strip $(COMPILER_ARCH)),ARM) |
| 237 | LNKOPT = $(strip $(WRAP_LIST)) -Bstatic --cref --warn-common --gc-sections --nmagic --emit-relocs \ |
| 238 | -o $(strip $(TARGDIR))\$(IMG_FILE) \ |
| 239 | -Map $(strip $(TARGDIR))\$(MAP_FILE) \ |
| 240 | -dT $(strip $(SCATTERFILE)) \ |
| 241 | $(strip $(LINK_SEARCH_PATH)) |
| 242 | else |
| 243 | LNKOPT = $(strip $(WRAP_LIST)) -EL $(strip $(LINK_OPTION_PREFIX))-Bstatic $(strip $(LINK_OPTION_PREFIX))--cref \ |
| 244 | $(strip $(LINK_OPTION_PREFIX))--warn-common $(strip $(LINK_OPTION_PREFIX))--gc-sections \ |
| 245 | $(strip $(LINK_OPTION_PREFIX))--nmagic \ |
| 246 | $(strip $(LINK_OPTION_PREFIX))--threads \ |
| 247 | $(strip $(LINK_OPTION_PREFIX))--thread-count-initial $(strip $(LINK_OPTION_PREFIX))10 \ |
| 248 | $(strip $(LINK_OPTION_PREFIX))--thread-count-middle $(strip $(LINK_OPTION_PREFIX))1 \ |
| 249 | $(strip $(LINK_OPTION_PREFIX))--thread-count-final $(strip $(LINK_OPTION_PREFIX))5 \ |
| 250 | $(strip $(LINK_OPTION_PREFIX))--preread-archive-symbols \ |
| 251 | -o $(strip $(TARGDIR))\$(IMG_FILE) \ |
| 252 | $(strip $(LINK_SEARCH_PATH)) |
| 253 | ifeq ($(strip $(LINK_BY_GCC)),TRUE) |
| 254 | LNKOPT += $(strip $(LINK_SEARCH_PATH)) $(filter-out -c,$(CFLAGS)) \ |
| 255 | $(strip $(LINK_OPTION_PREFIX))-Map,$(strip $(TARGDIR))\$(MAP_FILE) \ |
| 256 | $(strip $(LINK_OPTION_PREFIX))-dT,$(strip $(SCATTERFILE)) \ |
| 257 | -nostartfiles |
| 258 | else |
| 259 | LNKOPT += $(strip $(LINK_OPTION_PREFIX))-Map $(strip $(TARGDIR))\$(MAP_FILE) \ |
| 260 | $(strip $(LINK_OPTION_PREFIX))-dT $(strip $(SCATTERFILE)) |
| 261 | endif |
| 262 | endif |
| 263 | |
| 264 | ifeq ($(strip $(COMPILER_ISA)),NANOMIPS) |
| 265 | LNKOPT += $(strip $(LINK_OPTION_PREFIX))--discard-locals $(strip $(LINK_OPTION_PREFIX))--no-print-map-discarded |
| 266 | endif |
| 267 | |
| 268 | ifeq ($(strip $(LTO_BUILD)),TRUE) |
| 269 | LNKOPT += -flto -fno-fat-lto-objects |
| 270 | endif |
| 271 | |
| 272 | ifneq ($(filter $(strip $(SUPPORT_PLATFORM)), $(strip $(PLATFORM))),) |
| 273 | ifeq ($(strip $(COMPILER_ARCH)),ARM) |
| 274 | LNKOPT += --thumb-entry=INT_Vectors |
| 275 | else |
| 276 | LNKOPT += --entry=INT_Vectors |
| 277 | endif |
| 278 | endif |
| 279 | endif #ifeq ($(strip $(COMPILER)),GCC) |