TARGET_linux-mips.mk revision a6e2f9322c47ac02546aa436341fa42afd0000c5
1# 2# Copyright (C) 2010 The Android Open Source Project 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15# 16 17# Configuration for Linux on MIPS. 18# Included by combo/select.mk 19 20# You can set TARGET_ARCH_VARIANT to use an arch version other 21# than mips32r2-fp. Each value should correspond to a file named 22# $(BUILD_COMBOS)/arch/<name>.mk which must contain 23# makefile variable definitions similar to the preprocessor 24# defines in build/core/combo/include/arch/<combo>/AndroidConfig.h. Their 25# purpose is to allow module Android.mk files to selectively compile 26# different versions of code based upon the funtionality and 27# instructions available in a given architecture version. 28# 29# The blocks also define specific arch_variant_cflags, which 30# include defines, and compiler settings for the given architecture 31# version. 32# 33ifeq ($(strip $(TARGET_$(combo_2nd_arch_prefix)ARCH_VARIANT)),) 34TARGET_$(combo_2nd_arch_prefix)ARCH_VARIANT := mips32r2-fp 35endif 36 37ifeq ($(strip $(TARGET_GCC_VERSION_EXP)),) 38$(combo_2nd_arch_prefix)TARGET_GCC_VERSION := 4.8 39else 40$(combo_2nd_arch_prefix)TARGET_GCC_VERSION := $(TARGET_GCC_VERSION_EXP) 41endif 42 43TARGET_ARCH_SPECIFIC_MAKEFILE := $(BUILD_COMBOS)/arch/$(TARGET_$(combo_2nd_arch_prefix)ARCH)/$(TARGET_$(combo_2nd_arch_prefix)ARCH_VARIANT).mk 44ifeq ($(strip $(wildcard $(TARGET_ARCH_SPECIFIC_MAKEFILE))),) 45$(error Unknown MIPS architecture variant: $(TARGET_$(combo_2nd_arch_prefix)ARCH_VARIANT)) 46endif 47 48include $(TARGET_ARCH_SPECIFIC_MAKEFILE) 49 50# You can set TARGET_TOOLS_PREFIX to get gcc from somewhere else 51ifeq ($(strip $($(combo_2nd_arch_prefix)TARGET_TOOLS_PREFIX)),) 52$(combo_2nd_arch_prefix)TARGET_TOOLCHAIN_ROOT := prebuilts/gcc/$(HOST_PREBUILT_TAG)/mips/mipsel-linux-android-$($(combo_2nd_arch_prefix)TARGET_GCC_VERSION) 53$(combo_2nd_arch_prefix)TARGET_TOOLS_PREFIX := $($(combo_2nd_arch_prefix)TARGET_TOOLCHAIN_ROOT)/bin/mipsel-linux-android- 54endif 55 56$(combo_2nd_arch_prefix)TARGET_CC := $($(combo_2nd_arch_prefix)TARGET_TOOLS_PREFIX)gcc$(HOST_EXECUTABLE_SUFFIX) 57$(combo_2nd_arch_prefix)TARGET_CXX := $($(combo_2nd_arch_prefix)TARGET_TOOLS_PREFIX)g++$(HOST_EXECUTABLE_SUFFIX) 58$(combo_2nd_arch_prefix)TARGET_AR := $($(combo_2nd_arch_prefix)TARGET_TOOLS_PREFIX)ar$(HOST_EXECUTABLE_SUFFIX) 59$(combo_2nd_arch_prefix)TARGET_OBJCOPY := $($(combo_2nd_arch_prefix)TARGET_TOOLS_PREFIX)objcopy$(HOST_EXECUTABLE_SUFFIX) 60$(combo_2nd_arch_prefix)TARGET_LD := $($(combo_2nd_arch_prefix)TARGET_TOOLS_PREFIX)ld$(HOST_EXECUTABLE_SUFFIX) 61$(combo_2nd_arch_prefix)TARGET_READELF := $($(combo_2nd_arch_prefix)TARGET_TOOLS_PREFIX)readelf$(HOST_EXECUTABLE_SUFFIX) 62$(combo_2nd_arch_prefix)TARGET_STRIP := $($(combo_2nd_arch_prefix)TARGET_TOOLS_PREFIX)strip$(HOST_EXECUTABLE_SUFFIX) 63include $(BUILD_SYSTEM)/strip.mk 64 65$(combo_2nd_arch_prefix)TARGET_NO_UNDEFINED_LDFLAGS := -Wl,--no-undefined 66 67TARGET_mips_CFLAGS := -O2 \ 68 -fomit-frame-pointer \ 69 -fno-strict-aliasing \ 70 -funswitch-loops 71 72# Set FORCE_MIPS_DEBUGGING to "true" in your buildspec.mk 73# or in your environment to gdb debugging easier. 74# Don't forget to do a clean build. 75ifeq ($(FORCE_MIPS_DEBUGGING),true) 76 TARGET_mips_CFLAGS += -fno-omit-frame-pointer 77endif 78 79android_config_h := $(call select-android-config-h,linux-mips) 80 81$(combo_2nd_arch_prefix)TARGET_GLOBAL_CFLAGS += \ 82 $(TARGET_mips_CFLAGS) \ 83 -Ulinux -U__unix -U__unix__ -Umips \ 84 -fpic -fPIE\ 85 -ffunction-sections \ 86 -fdata-sections \ 87 -funwind-tables \ 88 -Wa,--noexecstack \ 89 -Werror=format-security \ 90 -D_FORTIFY_SOURCE=2 \ 91 $(arch_variant_cflags) \ 92 -include $(android_config_h) \ 93 -I $(dir $(android_config_h)) 94 95# This warning causes dalvik not to build with gcc 4.6+ and -Werror. 96# We cannot turn it off blindly since the option is not available 97# in gcc-4.4.x. 98ifneq ($(filter 4.6 4.6.% 4.7 4.7.% 4.8, $($(combo_2nd_arch_prefix)TARGET_GCC_VERSION)),) 99$(combo_2nd_arch_prefix)TARGET_GLOBAL_CFLAGS += -Wno-unused-but-set-variable \ 100 -fno-strict-volatile-bitfields 101endif 102 103# This is to avoid the dreaded warning compiler message: 104# note: the mangling of 'va_list' has changed in GCC 4.4 105# 106# The fact that the mangling changed does not affect the NDK ABI 107# very fortunately (since none of the exposed APIs used va_list 108# in their exported C++ functions). Also, GCC 4.5 has already 109# removed the warning from the compiler. 110# 111$(combo_2nd_arch_prefix)TARGET_GLOBAL_CFLAGS += -Wno-psabi 112 113ifneq ($(ARCH_MIPS_PAGE_SHIFT),) 114$(combo_2nd_arch_prefix)TARGET_GLOBAL_CFLAGS += -DPAGE_SHIFT=$(ARCH_MIPS_PAGE_SHIFT) 115endif 116 117$(combo_2nd_arch_prefix)TARGET_GLOBAL_LDFLAGS += \ 118 -Wl,-z,noexecstack \ 119 -Wl,-z,relro \ 120 -Wl,-z,now \ 121 -Wl,--warn-shared-textrel \ 122 -Wl,--fatal-warnings \ 123 $(arch_variant_ldflags) 124 125$(combo_2nd_arch_prefix)TARGET_GLOBAL_CPPFLAGS += -fvisibility-inlines-hidden 126 127# More flags/options can be added here 128$(combo_2nd_arch_prefix)TARGET_RELEASE_CFLAGS := \ 129 -DNDEBUG \ 130 -g \ 131 -Wstrict-aliasing=2 \ 132 -fgcse-after-reload \ 133 -frerun-cse-after-loop \ 134 -frename-registers 135 136libc_root := bionic/libc 137libm_root := bionic/libm 138libstdc++_root := bionic/libstdc++ 139 140 141## on some hosts, the target cross-compiler is not available so do not run this command 142ifneq ($(wildcard $($(combo_2nd_arch_prefix)TARGET_CC)),) 143# We compile with the global cflags to ensure that 144# any flags which affect libgcc are correctly taken 145# into account. 146$(combo_2nd_arch_prefix)TARGET_LIBGCC := \ 147 $(shell $($(combo_2nd_arch_prefix)TARGET_CC) $($(combo_2nd_arch_prefix)TARGET_GLOBAL_CFLAGS) -print-file-name=libgcc.a) 148LIBGCC_EH := $(shell $($(combo_2nd_arch_prefix)TARGET_CC) $($(combo_2nd_arch_prefix)TARGET_GLOBAL_CFLAGS) -print-file-name=libgcc_eh.a) 149ifneq ($(LIBGCC_EH),libgcc_eh.a) 150 $(combo_2nd_arch_prefix)TARGET_LIBGCC += $(LIBGCC_EH) 151endif 152target_libgcov := $(shell $($(combo_2nd_arch_prefix)TARGET_CC) $($(combo_2nd_arch_prefix)TARGET_GLOBAL_CFLAGS) \ 153 --print-file-name=libgcov.a) 154endif 155 156# Define FDO (Feedback Directed Optimization) options. 157 158$(combo_2nd_arch_prefix)TARGET_FDO_CFLAGS:= 159$(combo_2nd_arch_prefix)TARGET_FDO_LIB:= 160 161ifneq ($(strip $(BUILD_FDO_INSTRUMENT)),) 162 # Set BUILD_FDO_INSTRUMENT=true to turn on FDO instrumentation. 163 # The profile will be generated on /data/local/tmp/profile on the device. 164 $(combo_2nd_arch_prefix)TARGET_FDO_CFLAGS := -fprofile-generate=/data/local/tmp/profile -DANDROID_FDO 165 $(combo_2nd_arch_prefix)TARGET_FDO_LIB := $(target_libgcov) 166else 167 # If BUILD_FDO_INSTRUMENT is turned off, then consider doing the FDO optimizations. 168 # Set TARGET_FDO_PROFILE_PATH to set a custom profile directory for your build. 169 ifeq ($(strip $($(combo_2nd_arch_prefix)TARGET_FDO_PROFILE_PATH)),) 170 $(combo_2nd_arch_prefix)TARGET_FDO_PROFILE_PATH := fdo/profiles/$(TARGET_$(combo_2nd_arch_prefix)ARCH)/$(TARGET_$(combo_2nd_arch_prefix)ARCH_VARIANT) 171 else 172 ifeq ($(strip $(wildcard $($(combo_2nd_arch_prefix)TARGET_FDO_PROFILE_PATH))),) 173 $(warning Custom $(combo_2nd_arch_prefix)TARGET_FDO_PROFILE_PATH supplied, but directory does not exist. Turn off FDO.) 174 endif 175 endif 176 177 # If the FDO profile directory can't be found, then FDO is off. 178 ifneq ($(strip $(wildcard $($(combo_2nd_arch_prefix)TARGET_FDO_PROFILE_PATH))),) 179 $(combo_2nd_arch_prefix)TARGET_FDO_CFLAGS := -fprofile-use=$($(combo_2nd_arch_prefix)TARGET_FDO_PROFILE_PATH) -DANDROID_FDO 180 $(combo_2nd_arch_prefix)TARGET_FDO_LIB := $(target_libgcov) 181 endif 182endif 183 184 185KERNEL_HEADERS_COMMON := $(libc_root)/kernel/uapi 186KERNEL_HEADERS_ARCH := $(libc_root)/kernel/uapi/asm-mips # mips covers both mips and mips64. 187KERNEL_HEADERS := $(KERNEL_HEADERS_COMMON) $(KERNEL_HEADERS_ARCH) 188 189$(combo_2nd_arch_prefix)TARGET_C_INCLUDES := \ 190 $(libc_root)/arch-mips/include \ 191 $(libc_root)/include \ 192 $(libstdc++_root)/include \ 193 $(KERNEL_HEADERS) \ 194 $(libm_root)/include \ 195 $(libm_root)/include/mips \ 196 197$(combo_2nd_arch_prefix)TARGET_CRTBEGIN_STATIC_O := $($(combo_2nd_arch_prefix)TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbegin_static.o 198$(combo_2nd_arch_prefix)TARGET_CRTBEGIN_DYNAMIC_O := $($(combo_2nd_arch_prefix)TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbegin_dynamic.o 199$(combo_2nd_arch_prefix)TARGET_CRTEND_O := $($(combo_2nd_arch_prefix)TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtend_android.o 200 201$(combo_2nd_arch_prefix)TARGET_CRTBEGIN_SO_O := $($(combo_2nd_arch_prefix)TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbegin_so.o 202$(combo_2nd_arch_prefix)TARGET_CRTEND_SO_O := $($(combo_2nd_arch_prefix)TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtend_so.o 203 204$(combo_2nd_arch_prefix)TARGET_STRIP_MODULE:=true 205 206$(combo_2nd_arch_prefix)TARGET_DEFAULT_SYSTEM_SHARED_LIBRARIES := libc libstdc++ libm 207 208$(combo_2nd_arch_prefix)TARGET_CUSTOM_LD_COMMAND := true 209 210define $(combo_2nd_arch_prefix)transform-o-to-shared-lib-inner 211$(hide) $(PRIVATE_CXX) \ 212 -nostdlib -Wl,-soname,$(notdir $@) \ 213 -Wl,--gc-sections \ 214 -Wl,-shared,-Bsymbolic \ 215 $(PRIVATE_TARGET_GLOBAL_LD_DIRS) \ 216 $(if $(filter true,$(PRIVATE_NO_CRT)),,$(PRIVATE_TARGET_CRTBEGIN_SO_O)) \ 217 $(PRIVATE_ALL_OBJECTS) \ 218 -Wl,--whole-archive \ 219 $(call normalize-target-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \ 220 -Wl,--no-whole-archive \ 221 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--start-group) \ 222 $(call normalize-target-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \ 223 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--end-group) \ 224 $(PRIVATE_TARGET_LIBGCC) \ 225 $(PRIVATE_TARGET_FDO_LIB) \ 226 $(call normalize-target-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \ 227 -o $@ \ 228 $(PRIVATE_TARGET_GLOBAL_LDFLAGS) \ 229 $(PRIVATE_LDFLAGS) \ 230 $(PRIVATE_TARGET_LIBGCC) \ 231 $(if $(filter true,$(PRIVATE_NO_CRT)),,$(PRIVATE_TARGET_CRTEND_SO_O)) 232endef 233 234define $(combo_2nd_arch_prefix)transform-o-to-executable-inner 235$(hide) $(PRIVATE_CXX) -nostdlib -Bdynamic -fPIE -pie \ 236 -Wl,-dynamic-linker,/system/bin/linker \ 237 -Wl,--gc-sections \ 238 -Wl,-z,nocopyreloc \ 239 $(PRIVATE_TARGET_GLOBAL_LD_DIRS) \ 240 -Wl,-rpath-link=$(PRIVATE_TARGET_OUT_INTERMEDIATE_LIBRARIES) \ 241 $(if $(filter true,$(PRIVATE_NO_CRT)),,$(PRIVATE_TARGET_CRTBEGIN_DYNAMIC_O)) \ 242 $(PRIVATE_ALL_OBJECTS) \ 243 -Wl,--whole-archive \ 244 $(call normalize-target-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \ 245 -Wl,--no-whole-archive \ 246 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--start-group) \ 247 $(call normalize-target-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \ 248 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--end-group) \ 249 $(PRIVATE_TARGET_LIBGCC) \ 250 $(PRIVATE_TARGET_FDO_LIB) \ 251 $(call normalize-target-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \ 252 -o $@ \ 253 $(PRIVATE_TARGET_GLOBAL_LDFLAGS) \ 254 $(PRIVATE_LDFLAGS) \ 255 $(PRIVATE_TARGET_LIBGCC) \ 256 $(if $(filter true,$(PRIVATE_NO_CRT)),,$(PRIVATE_TARGET_CRTEND_O)) 257endef 258 259define $(combo_2nd_arch_prefix)transform-o-to-static-executable-inner 260$(hide) $(PRIVATE_CXX) -nostdlib -Bstatic \ 261 -Wl,--gc-sections \ 262 -o $@ \ 263 $(PRIVATE_TARGET_GLOBAL_LD_DIRS) \ 264 $(if $(filter true,$(PRIVATE_NO_CRT)),,$(PRIVATE_TARGET_CRTBEGIN_STATIC_O)) \ 265 $(PRIVATE_TARGET_GLOBAL_LDFLAGS) \ 266 $(PRIVATE_LDFLAGS) \ 267 $(PRIVATE_ALL_OBJECTS) \ 268 -Wl,--whole-archive \ 269 $(call normalize-target-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \ 270 -Wl,--no-whole-archive \ 271 $(call normalize-target-libraries,$(filter-out %libc_nomalloc.a,$(filter-out %libc.a,$(PRIVATE_ALL_STATIC_LIBRARIES)))) \ 272 -Wl,--start-group \ 273 $(call normalize-target-libraries,$(filter %libc.a,$(PRIVATE_ALL_STATIC_LIBRARIES))) \ 274 $(call normalize-target-libraries,$(filter %libc_nomalloc.a,$(PRIVATE_ALL_STATIC_LIBRARIES))) \ 275 $(PRIVATE_TARGET_FDO_LIB) \ 276 $(PRIVATE_TARGET_LIBGCC) \ 277 -Wl,--end-group \ 278 $(if $(filter true,$(PRIVATE_NO_CRT)),,$(PRIVATE_TARGET_CRTEND_O)) 279endef 280