blob: 187e2c2de4926f95377e6b2f9c9508ca71cb59d6 [file] [log] [blame]
Jean-Baptiste Queru9b4a8122010-02-23 12:36:56 -08001#
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
The Android Open Source Project88b60792009-03-03 19:28:42 -080017# Configuration for Linux on x86 as a target.
Jean-Baptiste Queru9b4a8122010-02-23 12:36:56 -080018# Included by combo/select.mk
19
Jean-Baptiste Queru9b4a8122010-02-23 12:36:56 -080020# Provide a default variant.
21ifeq ($(strip $(TARGET_ARCH_VARIANT)),)
22TARGET_ARCH_VARIANT := x86
23endif
The Android Open Source Project88b60792009-03-03 19:28:42 -080024
Ben Cheng054ffd22012-12-11 14:01:10 -080025ifeq ($(strip $(TARGET_GCC_VERSION)),)
26TARGET_GCC_VERSION := 4.6
27endif
28
David 'Digit' Turner6371da12011-12-13 17:21:56 +010029# Include the arch-variant-specific configuration file.
30# Its role is to define various ARCH_X86_HAVE_XXX feature macros,
31# plus initial values for TARGET_GLOBAL_CFLAGS
32#
33TARGET_ARCH_SPECIFIC_MAKEFILE := $(BUILD_COMBOS)/arch/$(TARGET_ARCH)/$(TARGET_ARCH_VARIANT).mk
34ifeq ($(strip $(wildcard $(TARGET_ARCH_SPECIFIC_MAKEFILE))),)
35$(error Unknown $(TARGET_ARCH) architecture version: $(TARGET_ARCH_VARIANT))
36endif
37
38include $(TARGET_ARCH_SPECIFIC_MAKEFILE)
39
40
The Android Open Source Project88b60792009-03-03 19:28:42 -080041# You can set TARGET_TOOLS_PREFIX to get gcc from somewhere else
Jean-Baptiste Queru9b4a8122010-02-23 12:36:56 -080042ifeq ($(strip $(TARGET_TOOLS_PREFIX)),)
Andrew Hsieh06b63ba2012-10-23 12:06:01 +080043TARGET_TOOLCHAIN_ROOT := prebuilts/gcc/$(HOST_PREBUILT_TAG)/x86/i686-linux-android-$(TARGET_GCC_VERSION)
Jean-Baptiste Querufeec98b2012-05-16 13:18:39 -070044TARGET_TOOLS_PREFIX := $(TARGET_TOOLCHAIN_ROOT)/bin/i686-linux-android-
The Android Open Source Project88b60792009-03-03 19:28:42 -080045endif
46
Jean-Baptiste Queru9b4a8122010-02-23 12:36:56 -080047TARGET_CC := $(TARGET_TOOLS_PREFIX)gcc$(HOST_EXECUTABLE_SUFFIX)
48TARGET_CXX := $(TARGET_TOOLS_PREFIX)g++$(HOST_EXECUTABLE_SUFFIX)
49TARGET_AR := $(TARGET_TOOLS_PREFIX)ar$(HOST_EXECUTABLE_SUFFIX)
50TARGET_OBJCOPY := $(TARGET_TOOLS_PREFIX)objcopy$(HOST_EXECUTABLE_SUFFIX)
51TARGET_LD := $(TARGET_TOOLS_PREFIX)ld$(HOST_EXECUTABLE_SUFFIX)
Bruce Beare45ac4342010-06-24 14:02:00 -070052TARGET_STRIP := $(TARGET_TOOLS_PREFIX)strip$(HOST_EXECUTABLE_SUFFIX)
Evgeniy Stepanov8f77c9d2011-06-21 17:08:49 +040053
54ifeq ($(TARGET_BUILD_VARIANT),user)
Bruce Beare45ac4342010-06-24 14:02:00 -070055TARGET_STRIP_COMMAND = $(TARGET_STRIP) --strip-debug $< -o $@
Evgeniy Stepanov8f77c9d2011-06-21 17:08:49 +040056else
57TARGET_STRIP_COMMAND = $(TARGET_STRIP) --strip-debug $< -o $@ && \
58 $(TARGET_OBJCOPY) --add-gnu-debuglink=$< $@
59endif
The Android Open Source Project88b60792009-03-03 19:28:42 -080060
Jean-Baptiste Queru9b4a8122010-02-23 12:36:56 -080061ifneq ($(wildcard $(TARGET_CC)),)
62TARGET_LIBGCC := \
Bruce Bearea17b91f2011-01-26 18:43:15 -080063 $(shell $(TARGET_CC) -m32 -print-file-name=libgcc.a)
The Android Open Source Project88b60792009-03-03 19:28:42 -080064endif
65
Jean-Baptiste Queru9b4a8122010-02-23 12:36:56 -080066TARGET_NO_UNDEFINED_LDFLAGS := -Wl,--no-undefined
The Android Open Source Project88b60792009-03-03 19:28:42 -080067
68libc_root := bionic/libc
69libm_root := bionic/libm
70libstdc++_root := bionic/libstdc++
71libthread_db_root := bionic/libthread_db
72
73# unless CUSTOM_KERNEL_HEADERS is defined, we're going to use
74# symlinks located in out/ to point to the appropriate kernel
75# headers. see 'config/kernel_headers.make' for more details
76#
77ifneq ($(CUSTOM_KERNEL_HEADERS),)
78 KERNEL_HEADERS_COMMON := $(CUSTOM_KERNEL_HEADERS)
79 KERNEL_HEADERS_ARCH := $(CUSTOM_KERNEL_HEADERS)
80else
81 KERNEL_HEADERS_COMMON := $(libc_root)/kernel/common
82 KERNEL_HEADERS_ARCH := $(libc_root)/kernel/arch-$(TARGET_ARCH)
83endif
84KERNEL_HEADERS := $(KERNEL_HEADERS_COMMON) $(KERNEL_HEADERS_ARCH)
85
Jean-Baptiste Queru9b4a8122010-02-23 12:36:56 -080086TARGET_GLOBAL_CFLAGS += \
Mark D Horn5812d7b2011-04-26 14:15:26 -070087 -O2 \
Bruce Beareccec9c42010-10-14 14:12:46 -070088 -Ulinux \
Mark D Horn5812d7b2011-04-26 14:15:26 -070089 -Wa,--noexecstack \
90 -Werror=format-security \
Nick Kralevich40febca2012-12-07 17:20:28 -080091 -D_FORTIFY_SOURCE=1 \
Mark D Horn5812d7b2011-04-26 14:15:26 -070092 -Wstrict-aliasing=2 \
Nick Kralevichd9d2e7a2011-11-04 13:07:26 -070093 -fPIC -fPIE \
Mark D Horn5812d7b2011-04-26 14:15:26 -070094 -ffunction-sections \
95 -finline-functions \
96 -finline-limit=300 \
97 -fno-inline-functions-called-once \
98 -fno-short-enums \
99 -fstrict-aliasing \
100 -funswitch-loops \
101 -funwind-tables \
Andrew Hsieh56305212012-09-12 15:27:59 -0700102 -fstack-protector
Ying Wangda4bf422012-08-16 16:45:01 -0700103
104android_config_h := $(call select-android-config-h,target_linux-x86)
105TARGET_ANDROID_CONFIG_CFLAGS := -include $(android_config_h) -I $(dir $(android_config_h))
106TARGET_GLOBAL_CFLAGS += $(TARGET_ANDROID_CONFIG_CFLAGS)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800107
David 'Digit' Turner6371da12011-12-13 17:21:56 +0100108# XXX: Not sure this is still needed. Must check with our toolchains.
Jean-Baptiste Queru9b4a8122010-02-23 12:36:56 -0800109TARGET_GLOBAL_CPPFLAGS += \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800110 -fno-use-cxa-atexit
111
David 'Digit' Turner6371da12011-12-13 17:21:56 +0100112# XXX: Our toolchain is normally configured to always set these flags by default
113# however, there have been reports that this is sometimes not the case. So make
114# them explicit here unless we have the time to carefully check it
115#
Jean-Baptiste Queru6e207822012-06-13 07:42:04 -0700116TARGET_GLOBAL_CFLAGS += -mstackrealign -msse3 -mfpmath=sse -m32
Bruce Beare3343b272011-12-09 13:27:08 -0800117
David 'Digit' Turner6371da12011-12-13 17:21:56 +0100118# XXX: These flags should not be defined here anymore. Instead, the Android.mk
119# of the modules that depend on these features should instead check the
120# corresponding macros (e.g. ARCH_X86_HAVE_SSE2 and ARCH_X86_HAVE_SSSE3)
121# Keep them here until this is all cleared up.
122#
123ifeq ($(ARCH_X86_HAVE_SSE2),true)
124TARGET_GLOBAL_CFLAGS += -DUSE_SSE2
Bruce Beareccec9c42010-10-14 14:12:46 -0700125endif
126
David 'Digit' Turner6371da12011-12-13 17:21:56 +0100127ifeq ($(ARCH_X86_HAVE_SSSE3),true) # yes, really SSSE3, not SSE3!
128TARGET_GLOBAL_CFLAGS += -DUSE_SSSE3
129endif
130
131# XXX: This flag is probably redundant. I believe our toolchain always sets
132# it by default. Consider for removal.
133#
Bruce Beare2e8283d2011-02-01 08:00:09 -0800134TARGET_GLOBAL_CFLAGS += -mbionic
David 'Digit' Turner6371da12011-12-13 17:21:56 +0100135
136# XXX: This flag is probably redundant. The macro should be defined by our
137# toolchain binaries automatically (as a compiler built-in).
138# Check with: $BINPREFIX-gcc -dM -E < /dev/null
139#
140# Consider for removal.
141#
Bruce Beareccec9c42010-10-14 14:12:46 -0700142TARGET_GLOBAL_CFLAGS += -D__ANDROID__
Bruce Beareccec9c42010-10-14 14:12:46 -0700143
David 'Digit' Turner6371da12011-12-13 17:21:56 +0100144# XXX: This flag is probably redundant since our toolchain binaries already
145# generate 32-bit machine code. It probably dates back to the old days
146# where we were using the host toolchain on Linux to build the platform
147# images. Consider it for removal.
Mark D Horn5812d7b2011-04-26 14:15:26 -0700148TARGET_GLOBAL_LDFLAGS += -m32
David 'Digit' Turner6371da12011-12-13 17:21:56 +0100149
Mark D Horn5812d7b2011-04-26 14:15:26 -0700150TARGET_GLOBAL_LDFLAGS += -Wl,-z,noexecstack
Nick Kralevichecb1a562012-05-09 14:49:04 -0700151TARGET_GLOBAL_LDFLAGS += -Wl,-z,relro -Wl,-z,now
Nick Kralevich4f2f16d2012-10-19 13:36:49 -0700152TARGET_GLOBAL_LDFLAGS += -Wl,--warn-shared-textrel
Mark D Horn5812d7b2011-04-26 14:15:26 -0700153TARGET_GLOBAL_LDFLAGS += -Wl,--gc-sections
Bruce Beareccec9c42010-10-14 14:12:46 -0700154
Jean-Baptiste Queru9b4a8122010-02-23 12:36:56 -0800155TARGET_C_INCLUDES := \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800156 $(libc_root)/arch-x86/include \
157 $(libc_root)/include \
158 $(libstdc++_root)/include \
159 $(KERNEL_HEADERS) \
160 $(libm_root)/include \
161 $(libm_root)/include/i387 \
162 $(libthread_db_root)/include
163
Ying Wangb1a4e4e2012-05-15 15:31:41 -0700164TARGET_CRTBEGIN_STATIC_O := $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbegin_static.o
165TARGET_CRTBEGIN_DYNAMIC_O := $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbegin_dynamic.o
166TARGET_CRTEND_O := $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtend_android.o
The Android Open Source Project88b60792009-03-03 19:28:42 -0800167
Ying Wangb1a4e4e2012-05-15 15:31:41 -0700168TARGET_CRTBEGIN_SO_O := $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbegin_so.o
169TARGET_CRTEND_SO_O := $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtend_so.o
The Android Open Source Project88b60792009-03-03 19:28:42 -0800170
Bruce Beare45ac4342010-06-24 14:02:00 -0700171TARGET_STRIP_MODULE:=true
The Android Open Source Project88b60792009-03-03 19:28:42 -0800172
Jean-Baptiste Queru9b4a8122010-02-23 12:36:56 -0800173TARGET_DEFAULT_SYSTEM_SHARED_LIBRARIES := libc libstdc++ libm
The Android Open Source Project88b60792009-03-03 19:28:42 -0800174
Jean-Baptiste Queru9b4a8122010-02-23 12:36:56 -0800175TARGET_CUSTOM_LD_COMMAND := true
The Android Open Source Project88b60792009-03-03 19:28:42 -0800176define transform-o-to-shared-lib-inner
Ying Wang3a7e4cc2011-01-28 14:14:47 -0800177$(hide) $(PRIVATE_CXX) \
Ying Wang1a081002010-07-13 14:55:47 -0700178 $(PRIVATE_TARGET_GLOBAL_LDFLAGS) \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800179 -nostdlib -Wl,-soname,$(notdir $@) \
180 -shared -Bsymbolic \
Bruce Beareccec9c42010-10-14 14:12:46 -0700181 $(TARGET_GLOBAL_CFLAGS) \
Ying Wang1a081002010-07-13 14:55:47 -0700182 $(PRIVATE_TARGET_GLOBAL_LD_DIRS) \
Jeff Brown703e7c62011-02-04 20:15:00 -0800183 $(if $(filter true,$(PRIVATE_NO_CRT)),,$(PRIVATE_TARGET_CRTBEGIN_SO_O)) \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800184 $(PRIVATE_ALL_OBJECTS) \
185 -Wl,--whole-archive \
Ying Wang80e6cce2011-01-24 23:25:36 -0800186 $(call normalize-target-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800187 -Wl,--no-whole-archive \
Ying Wangfcdabd42011-04-25 14:22:41 -0700188 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--start-group) \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800189 $(call normalize-target-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
Ying Wangfcdabd42011-04-25 14:22:41 -0700190 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--end-group) \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800191 $(call normalize-target-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
192 -o $@ \
193 $(PRIVATE_LDFLAGS) \
Ying Wang1a081002010-07-13 14:55:47 -0700194 $(PRIVATE_TARGET_LIBGCC) \
Jeff Brown703e7c62011-02-04 20:15:00 -0800195 $(if $(filter true,$(PRIVATE_NO_CRT)),,$(PRIVATE_TARGET_CRTEND_SO_O))
The Android Open Source Project88b60792009-03-03 19:28:42 -0800196endef
197
The Android Open Source Project88b60792009-03-03 19:28:42 -0800198define transform-o-to-executable-inner
Ying Wang3a7e4cc2011-01-28 14:14:47 -0800199$(hide) $(PRIVATE_CXX) \
Ying Wang91fd1232012-09-25 17:52:10 -0700200 $(PRIVATE_TARGET_GLOBAL_LDFLAGS) \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800201 -nostdlib -Bdynamic \
202 -Wl,-dynamic-linker,/system/bin/linker \
203 -Wl,-z,nocopyreloc \
Nick Kralevichd9d2e7a2011-11-04 13:07:26 -0700204 -fPIE -pie \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800205 -o $@ \
Ying Wang91fd1232012-09-25 17:52:10 -0700206 $(PRIVATE_TARGET_GLOBAL_LD_DIRS) \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800207 -Wl,-rpath-link=$(TARGET_OUT_INTERMEDIATE_LIBRARIES) \
208 $(call normalize-target-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
Ying Wang91fd1232012-09-25 17:52:10 -0700209 $(if $(filter true,$(PRIVATE_NO_CRT)),,$(PRIVATE_TARGET_CRTBEGIN_DYNAMIC_O)) \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800210 $(PRIVATE_ALL_OBJECTS) \
Kito Cheng61c37e72012-01-20 19:21:46 +0800211 -Wl,--whole-archive \
212 $(call normalize-target-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
213 -Wl,--no-whole-archive \
Ying Wangfcdabd42011-04-25 14:22:41 -0700214 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--start-group) \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800215 $(call normalize-target-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
Ying Wangfcdabd42011-04-25 14:22:41 -0700216 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--end-group) \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800217 $(PRIVATE_LDFLAGS) \
Ying Wang91fd1232012-09-25 17:52:10 -0700218 $(PRIVATE_TARGET_LIBGCC) \
219 $(if $(filter true,$(PRIVATE_NO_CRT)),,$(PRIVATE_TARGET_CRTEND_O))
The Android Open Source Project88b60792009-03-03 19:28:42 -0800220endef
221
222define transform-o-to-static-executable-inner
Ying Wang3a7e4cc2011-01-28 14:14:47 -0800223$(hide) $(PRIVATE_CXX) \
Ying Wang91fd1232012-09-25 17:52:10 -0700224 $(PRIVATE_TARGET_GLOBAL_LDFLAGS) \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800225 -nostdlib -Bstatic \
226 -o $@ \
Ying Wang91fd1232012-09-25 17:52:10 -0700227 $(PRIVATE_TARGET_GLOBAL_LD_DIRS) \
228 $(if $(filter true,$(PRIVATE_NO_CRT)),,$(PRIVATE_TARGET_CRTBEGIN_STATIC_O)) \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800229 $(PRIVATE_LDFLAGS) \
230 $(PRIVATE_ALL_OBJECTS) \
Kito Cheng61c37e72012-01-20 19:21:46 +0800231 -Wl,--whole-archive \
232 $(call normalize-target-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
233 -Wl,--no-whole-archive \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800234 -Wl,--start-group \
235 $(call normalize-target-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
Ying Wang91fd1232012-09-25 17:52:10 -0700236 $(PRIVATE_TARGET_LIBGCC) \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800237 -Wl,--end-group \
Ying Wang91fd1232012-09-25 17:52:10 -0700238 $(if $(filter true,$(PRIVATE_NO_CRT)),,$(PRIVATE_TARGET_CRTEND_O))
The Android Open Source Project88b60792009-03-03 19:28:42 -0800239endef
David 'Digit' Turner6371da12011-12-13 17:21:56 +0100240
241# Special check for x86 NDK ABI compatibility.
242# The TARGET_CPU_ABI variable should be defined in BoardConfig.mk to 'x86'
243# *only* if the platform image is compatible with the NDK x86 ABI.
244#
245# We perform a small check here to ensure that nothing bad can happen.
246#
247ifeq ($(TARGET_CPU_ABI),x86)
248 ifneq (true-true-true-true,$(ARCH_X86_HAVE_MMX)-$(ARCH_X86_HAVE_SSE)-$(ARCH_X86_HAVE_SSE2)-$(ARCH_X86_HAVE_SSE3))
249 $(info ERROR: Your x86 platform image is not compatible with the NDK x86 ABI)
250 $(info As such, you should *not* define TARGET_CPU_ABI to 'x86' in your BoardConfig.mk)
251 $(info to ensure that your device will not be mistakenly listed as compatible by
252 $(info the Android Market. Also, it is likely that the image will fail the CTS tests)
253 $(info Please undefine TARGET_CPU_ABI in your BoardConfig.mk, or select the value 'none')
254 $(info The corresponding image will still be able to run Dalvik-based Android applications)
255 $(error Aborting build! Please fix your BoardConfig.mk)
256 endif
257endif