TARGET_linux-x86.mk revision da4bf4251451d2da8883d636849b65fcc368a575
1# 2# Copyright (C) 2006 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 x86 as a target. 18# Included by combo/select.mk 19 20# Provide a default variant. 21ifeq ($(strip $(TARGET_ARCH_VARIANT)),) 22TARGET_ARCH_VARIANT := x86 23endif 24 25# Include the arch-variant-specific configuration file. 26# Its role is to define various ARCH_X86_HAVE_XXX feature macros, 27# plus initial values for TARGET_GLOBAL_CFLAGS 28# 29TARGET_ARCH_SPECIFIC_MAKEFILE := $(BUILD_COMBOS)/arch/$(TARGET_ARCH)/$(TARGET_ARCH_VARIANT).mk 30ifeq ($(strip $(wildcard $(TARGET_ARCH_SPECIFIC_MAKEFILE))),) 31$(error Unknown $(TARGET_ARCH) architecture version: $(TARGET_ARCH_VARIANT)) 32endif 33 34include $(TARGET_ARCH_SPECIFIC_MAKEFILE) 35 36 37# You can set TARGET_TOOLS_PREFIX to get gcc from somewhere else 38ifeq ($(strip $(TARGET_TOOLS_PREFIX)),) 39TARGET_TOOLCHAIN_ROOT := prebuilts/gcc/$(HOST_PREBUILT_TAG)/x86/i686-linux-android-4.6 40TARGET_TOOLS_PREFIX := $(TARGET_TOOLCHAIN_ROOT)/bin/i686-linux-android- 41endif 42 43TARGET_CC := $(TARGET_TOOLS_PREFIX)gcc$(HOST_EXECUTABLE_SUFFIX) 44TARGET_CXX := $(TARGET_TOOLS_PREFIX)g++$(HOST_EXECUTABLE_SUFFIX) 45TARGET_AR := $(TARGET_TOOLS_PREFIX)ar$(HOST_EXECUTABLE_SUFFIX) 46TARGET_OBJCOPY := $(TARGET_TOOLS_PREFIX)objcopy$(HOST_EXECUTABLE_SUFFIX) 47TARGET_LD := $(TARGET_TOOLS_PREFIX)ld$(HOST_EXECUTABLE_SUFFIX) 48TARGET_STRIP := $(TARGET_TOOLS_PREFIX)strip$(HOST_EXECUTABLE_SUFFIX) 49 50ifeq ($(TARGET_BUILD_VARIANT),user) 51TARGET_STRIP_COMMAND = $(TARGET_STRIP) --strip-debug $< -o $@ 52else 53TARGET_STRIP_COMMAND = $(TARGET_STRIP) --strip-debug $< -o $@ && \ 54 $(TARGET_OBJCOPY) --add-gnu-debuglink=$< $@ 55endif 56 57ifneq ($(wildcard $(TARGET_CC)),) 58TARGET_LIBGCC := \ 59 $(shell $(TARGET_CC) -m32 -print-file-name=libgcc.a) 60endif 61 62TARGET_NO_UNDEFINED_LDFLAGS := -Wl,--no-undefined 63 64libc_root := bionic/libc 65libm_root := bionic/libm 66libstdc++_root := bionic/libstdc++ 67libthread_db_root := bionic/libthread_db 68 69# unless CUSTOM_KERNEL_HEADERS is defined, we're going to use 70# symlinks located in out/ to point to the appropriate kernel 71# headers. see 'config/kernel_headers.make' for more details 72# 73ifneq ($(CUSTOM_KERNEL_HEADERS),) 74 KERNEL_HEADERS_COMMON := $(CUSTOM_KERNEL_HEADERS) 75 KERNEL_HEADERS_ARCH := $(CUSTOM_KERNEL_HEADERS) 76else 77 KERNEL_HEADERS_COMMON := $(libc_root)/kernel/common 78 KERNEL_HEADERS_ARCH := $(libc_root)/kernel/arch-$(TARGET_ARCH) 79endif 80KERNEL_HEADERS := $(KERNEL_HEADERS_COMMON) $(KERNEL_HEADERS_ARCH) 81 82TARGET_GLOBAL_CFLAGS += \ 83 -O2 \ 84 -Ulinux \ 85 -Wa,--noexecstack \ 86 -Werror=format-security \ 87 -Wstrict-aliasing=2 \ 88 -fPIC -fPIE \ 89 -ffunction-sections \ 90 -finline-functions \ 91 -finline-limit=300 \ 92 -fno-inline-functions-called-once \ 93 -fno-short-enums \ 94 -fstrict-aliasing \ 95 -funswitch-loops \ 96 -funwind-tables 97 98android_config_h := $(call select-android-config-h,target_linux-x86) 99TARGET_ANDROID_CONFIG_CFLAGS := -include $(android_config_h) -I $(dir $(android_config_h)) 100TARGET_GLOBAL_CFLAGS += $(TARGET_ANDROID_CONFIG_CFLAGS) 101 102# XXX: Not sure this is still needed. Must check with our toolchains. 103TARGET_GLOBAL_CPPFLAGS += \ 104 -fno-use-cxa-atexit 105 106# XXX: Our toolchain is normally configured to always set these flags by default 107# however, there have been reports that this is sometimes not the case. So make 108# them explicit here unless we have the time to carefully check it 109# 110TARGET_GLOBAL_CFLAGS += -mstackrealign -msse3 -mfpmath=sse -m32 111 112# XXX: These flags should not be defined here anymore. Instead, the Android.mk 113# of the modules that depend on these features should instead check the 114# corresponding macros (e.g. ARCH_X86_HAVE_SSE2 and ARCH_X86_HAVE_SSSE3) 115# Keep them here until this is all cleared up. 116# 117ifeq ($(ARCH_X86_HAVE_SSE2),true) 118TARGET_GLOBAL_CFLAGS += -DUSE_SSE2 119endif 120 121ifeq ($(ARCH_X86_HAVE_SSSE3),true) # yes, really SSSE3, not SSE3! 122TARGET_GLOBAL_CFLAGS += -DUSE_SSSE3 123endif 124 125# XXX: This flag is probably redundant. I believe our toolchain always sets 126# it by default. Consider for removal. 127# 128TARGET_GLOBAL_CFLAGS += -mbionic 129 130# XXX: This flag is probably redundant. The macro should be defined by our 131# toolchain binaries automatically (as a compiler built-in). 132# Check with: $BINPREFIX-gcc -dM -E < /dev/null 133# 134# Consider for removal. 135# 136TARGET_GLOBAL_CFLAGS += -D__ANDROID__ 137 138# XXX: This flag is probably redundant since our toolchain binaries already 139# generate 32-bit machine code. It probably dates back to the old days 140# where we were using the host toolchain on Linux to build the platform 141# images. Consider it for removal. 142TARGET_GLOBAL_LDFLAGS += -m32 143 144TARGET_GLOBAL_LDFLAGS += -Wl,-z,noexecstack 145TARGET_GLOBAL_LDFLAGS += -Wl,-z,relro -Wl,-z,now 146TARGET_GLOBAL_LDFLAGS += -Wl,--gc-sections 147 148TARGET_C_INCLUDES := \ 149 $(libc_root)/arch-x86/include \ 150 $(libc_root)/include \ 151 $(libstdc++_root)/include \ 152 $(KERNEL_HEADERS) \ 153 $(libm_root)/include \ 154 $(libm_root)/include/i387 \ 155 $(libthread_db_root)/include 156 157TARGET_CRTBEGIN_STATIC_O := $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbegin_static.o 158TARGET_CRTBEGIN_DYNAMIC_O := $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbegin_dynamic.o 159TARGET_CRTEND_O := $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtend_android.o 160 161TARGET_CRTBEGIN_SO_O := $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbegin_so.o 162TARGET_CRTEND_SO_O := $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtend_so.o 163 164TARGET_STRIP_MODULE:=true 165 166TARGET_DEFAULT_SYSTEM_SHARED_LIBRARIES := libc libstdc++ libm 167 168TARGET_CUSTOM_LD_COMMAND := true 169define transform-o-to-shared-lib-inner 170$(hide) $(PRIVATE_CXX) \ 171 $(PRIVATE_TARGET_GLOBAL_LDFLAGS) \ 172 -nostdlib -Wl,-soname,$(notdir $@) \ 173 -shared -Bsymbolic \ 174 $(TARGET_GLOBAL_CFLAGS) \ 175 $(PRIVATE_TARGET_GLOBAL_LD_DIRS) \ 176 $(if $(filter true,$(PRIVATE_NO_CRT)),,$(PRIVATE_TARGET_CRTBEGIN_SO_O)) \ 177 $(PRIVATE_ALL_OBJECTS) \ 178 -Wl,--whole-archive \ 179 $(call normalize-target-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \ 180 -Wl,--no-whole-archive \ 181 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--start-group) \ 182 $(call normalize-target-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \ 183 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--end-group) \ 184 $(call normalize-target-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \ 185 -o $@ \ 186 $(PRIVATE_LDFLAGS) \ 187 $(PRIVATE_TARGET_LIBGCC) \ 188 $(if $(filter true,$(PRIVATE_NO_CRT)),,$(PRIVATE_TARGET_CRTEND_SO_O)) 189endef 190 191# Add -fuse-ld=bfd because ld.gold doesn't support "--copy-dt-needed-entries". 192define transform-o-to-executable-inner 193$(hide) $(PRIVATE_CXX) \ 194 $(TARGET_GLOBAL_LDFLAGS) \ 195 -nostdlib -Bdynamic \ 196 -Wl,-dynamic-linker,/system/bin/linker \ 197 -Wl,--copy-dt-needed-entries \ 198 -fuse-ld=bfd \ 199 -Wl,-z,nocopyreloc \ 200 -fPIE -pie \ 201 -o $@ \ 202 $(TARGET_GLOBAL_LD_DIRS) \ 203 -Wl,-rpath-link=$(TARGET_OUT_INTERMEDIATE_LIBRARIES) \ 204 $(call normalize-target-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \ 205 $(if $(filter true,$(PRIVATE_NO_CRT)),,$(TARGET_CRTBEGIN_DYNAMIC_O)) \ 206 $(PRIVATE_ALL_OBJECTS) \ 207 -Wl,--whole-archive \ 208 $(call normalize-target-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \ 209 -Wl,--no-whole-archive \ 210 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--start-group) \ 211 $(call normalize-target-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \ 212 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--end-group) \ 213 $(PRIVATE_LDFLAGS) \ 214 $(TARGET_LIBGCC) \ 215 $(if $(filter true,$(PRIVATE_NO_CRT)),,$(TARGET_CRTEND_O)) 216endef 217 218define transform-o-to-static-executable-inner 219$(hide) $(PRIVATE_CXX) \ 220 $(TARGET_GLOBAL_LDFLAGS) \ 221 -nostdlib -Bstatic \ 222 -o $@ \ 223 $(TARGET_GLOBAL_LD_DIRS) \ 224 $(if $(filter true,$(PRIVATE_NO_CRT)),,$(TARGET_CRTBEGIN_STATIC_O)) \ 225 $(PRIVATE_LDFLAGS) \ 226 $(PRIVATE_ALL_OBJECTS) \ 227 -Wl,--whole-archive \ 228 $(call normalize-target-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \ 229 -Wl,--no-whole-archive \ 230 -Wl,--start-group \ 231 $(call normalize-target-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \ 232 $(TARGET_LIBGCC) \ 233 -Wl,--end-group \ 234 $(if $(filter true,$(PRIVATE_NO_CRT)),,$(TARGET_CRTEND_O)) 235endef 236 237# Special check for x86 NDK ABI compatibility. 238# The TARGET_CPU_ABI variable should be defined in BoardConfig.mk to 'x86' 239# *only* if the platform image is compatible with the NDK x86 ABI. 240# 241# We perform a small check here to ensure that nothing bad can happen. 242# 243ifeq ($(TARGET_CPU_ABI),x86) 244 ifneq (true-true-true-true,$(ARCH_X86_HAVE_MMX)-$(ARCH_X86_HAVE_SSE)-$(ARCH_X86_HAVE_SSE2)-$(ARCH_X86_HAVE_SSE3)) 245 $(info ERROR: Your x86 platform image is not compatible with the NDK x86 ABI) 246 $(info As such, you should *not* define TARGET_CPU_ABI to 'x86' in your BoardConfig.mk) 247 $(info to ensure that your device will not be mistakenly listed as compatible by 248 $(info the Android Market. Also, it is likely that the image will fail the CTS tests) 249 $(info Please undefine TARGET_CPU_ABI in your BoardConfig.mk, or select the value 'none') 250 $(info The corresponding image will still be able to run Dalvik-based Android applications) 251 $(error Aborting build! Please fix your BoardConfig.mk) 252 endif 253endif 254