TARGET_linux-x86.mk revision ae5c0ab2726ed4b9ca7b08f9b29e3393aa0a5d40
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
25ifeq ($(strip $(TARGET_GCC_VERSION_EXP)),)
26TARGET_GCC_VERSION := 4.7
27else
28TARGET_GCC_VERSION := $(TARGET_GCC_VERSION_EXP)
29endif
30
31# Include the arch-variant-specific configuration file.
32# Its role is to define various ARCH_X86_HAVE_XXX feature macros,
33# plus initial values for TARGET_GLOBAL_CFLAGS
34#
35TARGET_ARCH_SPECIFIC_MAKEFILE := $(BUILD_COMBOS)/arch/$(TARGET_ARCH)/$(TARGET_ARCH_VARIANT).mk
36ifeq ($(strip $(wildcard $(TARGET_ARCH_SPECIFIC_MAKEFILE))),)
37$(error Unknown $(TARGET_ARCH) architecture version: $(TARGET_ARCH_VARIANT))
38endif
39
40include $(TARGET_ARCH_SPECIFIC_MAKEFILE)
41
42
43# You can set TARGET_TOOLS_PREFIX to get gcc from somewhere else
44ifeq ($(strip $(TARGET_TOOLS_PREFIX)),)
45TARGET_TOOLCHAIN_ROOT := prebuilts/gcc/$(HOST_PREBUILT_TAG)/x86/i686-linux-android-$(TARGET_GCC_VERSION)
46TARGET_TOOLS_PREFIX := $(TARGET_TOOLCHAIN_ROOT)/bin/i686-linux-android-
47endif
48
49TARGET_CC := $(TARGET_TOOLS_PREFIX)gcc$(HOST_EXECUTABLE_SUFFIX)
50TARGET_CXX := $(TARGET_TOOLS_PREFIX)g++$(HOST_EXECUTABLE_SUFFIX)
51TARGET_AR := $(TARGET_TOOLS_PREFIX)ar$(HOST_EXECUTABLE_SUFFIX)
52TARGET_OBJCOPY := $(TARGET_TOOLS_PREFIX)objcopy$(HOST_EXECUTABLE_SUFFIX)
53TARGET_LD := $(TARGET_TOOLS_PREFIX)ld$(HOST_EXECUTABLE_SUFFIX)
54TARGET_STRIP := $(TARGET_TOOLS_PREFIX)strip$(HOST_EXECUTABLE_SUFFIX)
55
56ifeq ($(TARGET_BUILD_VARIANT),user)
57TARGET_STRIP_COMMAND = $(TARGET_STRIP) --strip-debug $< -o $@
58else
59TARGET_STRIP_COMMAND = $(TARGET_STRIP) --strip-debug $< -o $@ && \
60	$(TARGET_OBJCOPY) --add-gnu-debuglink=$< $@
61endif
62
63ifneq ($(wildcard $(TARGET_CC)),)
64TARGET_LIBGCC := \
65	$(shell $(TARGET_CC) -m32 -print-file-name=libgcc.a)
66target_libgcov := $(shell $(TARGET_CC) $(TARGET_GLOBAL_CFLAGS) \
67	-print-file-name=libgcov.a)
68endif
69
70TARGET_NO_UNDEFINED_LDFLAGS := -Wl,--no-undefined
71
72libc_root := bionic/libc
73libm_root := bionic/libm
74libstdc++_root := bionic/libstdc++
75libthread_db_root := bionic/libthread_db
76
77# Define FDO (Feedback Directed Optimization) options.
78
79TARGET_FDO_CFLAGS:=
80TARGET_FDO_LIB:=
81
82ifneq ($(strip $(BUILD_FDO_INSTRUMENT)),)
83  # Set BUILD_FDO_INSTRUMENT=true to turn on FDO instrumentation.
84  # The profile will be generated on /data/local/tmp/profile on the device.
85  TARGET_FDO_CFLAGS := -fprofile-generate=/data/local/tmp/profile -DANDROID_FDO
86  TARGET_FDO_LIB := $(target_libgcov)
87else
88  # If BUILD_FDO_INSTRUMENT is turned off, then consider doing the FDO optimizations.
89  # Set TARGET_FDO_PROFILE_PATH to set a custom profile directory for your build.
90  ifeq ($(strip $(TARGET_FDO_PROFILE_PATH)),)
91    TARGET_FDO_PROFILE_PATH := fdo/profiles/$(TARGET_ARCH)/$(TARGET_ARCH_VARIANT)
92  else
93    ifeq ($(strip $(wildcard $(TARGET_FDO_PROFILE_PATH))),)
94      $(warning Custom TARGET_FDO_PROFILE_PATH supplied, but directory does not exist. Turn off FDO.)
95    endif
96  endif
97
98  # If the FDO profile directory can't be found, then FDO is off.
99  ifneq ($(strip $(wildcard $(TARGET_FDO_PROFILE_PATH))),)
100    TARGET_FDO_CFLAGS := -fprofile-use=$(TARGET_FDO_PROFILE_PATH) -DANDROID_FDO
101    TARGET_FDO_LIB := $(target_libgcov)
102  endif
103endif
104
105# unless CUSTOM_KERNEL_HEADERS is defined, we're going to use
106# symlinks located in out/ to point to the appropriate kernel
107# headers. see 'config/kernel_headers.make' for more details
108#
109ifneq ($(CUSTOM_KERNEL_HEADERS),)
110    KERNEL_HEADERS_COMMON := $(CUSTOM_KERNEL_HEADERS)
111    KERNEL_HEADERS_ARCH   := $(CUSTOM_KERNEL_HEADERS)
112else
113    KERNEL_HEADERS_COMMON := $(libc_root)/kernel/common
114    KERNEL_HEADERS_ARCH   := $(libc_root)/kernel/arch-$(TARGET_ARCH)
115endif
116KERNEL_HEADERS := $(KERNEL_HEADERS_COMMON) $(KERNEL_HEADERS_ARCH)
117
118TARGET_GLOBAL_CFLAGS += \
119			-O2 \
120			-Ulinux \
121			-Wa,--noexecstack \
122			-Werror=format-security \
123			-D_FORTIFY_SOURCE=2 \
124			-Wstrict-aliasing=2 \
125			-fPIC -fPIE \
126			-ffunction-sections \
127			-finline-functions \
128			-finline-limit=300 \
129			-fno-inline-functions-called-once \
130			-fno-short-enums \
131			-fstrict-aliasing \
132			-funswitch-loops \
133			-funwind-tables \
134			-fstack-protector \
135			-m32
136
137android_config_h := $(call select-android-config-h,target_linux-x86)
138TARGET_ANDROID_CONFIG_CFLAGS := -include $(android_config_h) -I $(dir $(android_config_h))
139TARGET_GLOBAL_CFLAGS += $(TARGET_ANDROID_CONFIG_CFLAGS)
140
141# XXX: Not sure this is still needed. Must check with our toolchains.
142TARGET_GLOBAL_CPPFLAGS += \
143			-fno-use-cxa-atexit
144
145TARGET_GLOBAL_CFLAGS += $(arch_variant_cflags)
146
147ifeq ($(ARCH_X86_HAVE_MMX),true)
148    TARGET_GLOBAL_CFLAGS += -DUSE_MMX -mmmx
149endif
150ifeq ($(ARCH_X86_HAVE_SSE),true)
151    TARGET_GLOBAL_CFLAGS += -DUSE_SSE -msse
152endif
153ifeq ($(ARCH_X86_HAVE_SSE2),true)
154    TARGET_GLOBAL_CFLAGS += -DUSE_SSE2 -msse2
155endif
156ifeq ($(ARCH_X86_HAVE_SSE3),true)
157    TARGET_GLOBAL_CFLAGS += -DUSE_SSE3 -msse3
158endif
159ifeq ($(ARCH_X86_HAVE_SSSE3),true)   # yes, really SSSE3, not SSE3!
160    TARGET_GLOBAL_CFLAGS += -DUSE_SSSE3 -mssse3
161endif
162ifeq ($(ARCH_X86_HAVE_SSE4),true)
163    TARGET_GLOBAL_CFLAGS += -msse4
164endif
165ifeq ($(ARCH_X86_HAVE_SSE4_1),true)
166    TARGET_GLOBAL_CFLAGS += -msse4.1
167endif
168ifeq ($(ARCH_X86_HAVE_SSE4_2),true)
169    TARGET_GLOBAL_CFLAGS += -msse4.2
170endif
171ifeq ($(ARCH_X86_HAVE_AVX),true)
172    TARGET_GLOBAL_CFLAGS += -mavx
173endif
174ifeq ($(ARCH_X86_HAVE_AES_NI),true)
175    TARGET_GLOBAL_CFLAGS += -maes
176endif
177
178# XXX: This flag is probably redundant. I believe our toolchain always sets
179# it by default. Consider for removal.
180#
181TARGET_GLOBAL_CFLAGS += -mbionic
182
183# XXX: This flag is probably redundant. The macro should be defined by our
184# toolchain binaries automatically (as a compiler built-in).
185# Check with: $BINPREFIX-gcc -dM -E < /dev/null
186#
187# Consider for removal.
188#
189TARGET_GLOBAL_CFLAGS += -D__ANDROID__
190
191# XXX: This flag is probably redundant since our toolchain binaries already
192# generate 32-bit machine code. It probably dates back to the old days
193# where we were using the host toolchain on Linux to build the platform
194# images. Consider it for removal.
195TARGET_GLOBAL_LDFLAGS += -m32
196
197TARGET_GLOBAL_LDFLAGS += -Wl,-z,noexecstack
198TARGET_GLOBAL_LDFLAGS += -Wl,-z,relro -Wl,-z,now
199TARGET_GLOBAL_LDFLAGS += -Wl,--warn-shared-textrel
200TARGET_GLOBAL_LDFLAGS += -Wl,--gc-sections
201
202TARGET_C_INCLUDES := \
203	$(libc_root)/arch-x86/include \
204	$(libc_root)/include \
205	$(libstdc++_root)/include \
206	$(KERNEL_HEADERS) \
207	$(libm_root)/include \
208	$(libm_root)/include/i387 \
209	$(libthread_db_root)/include
210
211TARGET_CRTBEGIN_STATIC_O := $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbegin_static.o
212TARGET_CRTBEGIN_DYNAMIC_O := $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbegin_dynamic.o
213TARGET_CRTEND_O := $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtend_android.o
214
215TARGET_CRTBEGIN_SO_O := $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbegin_so.o
216TARGET_CRTEND_SO_O := $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtend_so.o
217
218TARGET_STRIP_MODULE:=true
219
220TARGET_DEFAULT_SYSTEM_SHARED_LIBRARIES := libc libstdc++ libm
221
222TARGET_CUSTOM_LD_COMMAND := true
223define transform-o-to-shared-lib-inner
224$(hide) $(PRIVATE_CXX) \
225	$(PRIVATE_TARGET_GLOBAL_LDFLAGS) \
226	 -nostdlib -Wl,-soname,$(notdir $@) \
227	 -shared -Bsymbolic \
228	$(TARGET_GLOBAL_CFLAGS) \
229	$(PRIVATE_TARGET_GLOBAL_LD_DIRS) \
230	$(if $(filter true,$(PRIVATE_NO_CRT)),,$(PRIVATE_TARGET_CRTBEGIN_SO_O)) \
231	$(PRIVATE_ALL_OBJECTS) \
232	-Wl,--whole-archive \
233	$(call normalize-target-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
234	-Wl,--no-whole-archive \
235	$(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--start-group) \
236	$(call normalize-target-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
237	$(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--end-group) \
238	$(PRIVATE_TARGET_LIBGCC) \
239	$(PRIVATE_TARGET_FDO_LIB) \
240	$(call normalize-target-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
241	-o $@ \
242	$(PRIVATE_LDFLAGS) \
243	$(PRIVATE_TARGET_LIBGCC) \
244	$(if $(filter true,$(PRIVATE_NO_CRT)),,$(PRIVATE_TARGET_CRTEND_SO_O))
245endef
246
247define transform-o-to-executable-inner
248$(hide) $(PRIVATE_CXX) \
249	$(PRIVATE_TARGET_GLOBAL_LDFLAGS) \
250	-nostdlib -Bdynamic \
251	-Wl,-dynamic-linker,/system/bin/linker \
252	-Wl,-z,nocopyreloc \
253	-fPIE -pie \
254	$(PRIVATE_TARGET_GLOBAL_LD_DIRS) \
255	-Wl,-rpath-link=$(TARGET_OUT_INTERMEDIATE_LIBRARIES) \
256	$(if $(filter true,$(PRIVATE_NO_CRT)),,$(PRIVATE_TARGET_CRTBEGIN_DYNAMIC_O)) \
257	$(PRIVATE_ALL_OBJECTS) \
258	-Wl,--whole-archive \
259	$(call normalize-target-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
260	-Wl,--no-whole-archive \
261	$(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--start-group) \
262	$(call normalize-target-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
263	$(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--end-group) \
264	$(PRIVATE_TARGET_LIBGCC) \
265	$(PRIVATE_TARGET_FDO_LIB) \
266	$(call normalize-target-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
267	-o $@ \
268	$(PRIVATE_LDFLAGS) \
269	$(PRIVATE_TARGET_LIBGCC) \
270	$(if $(filter true,$(PRIVATE_NO_CRT)),,$(PRIVATE_TARGET_CRTEND_O))
271endef
272
273define transform-o-to-static-executable-inner
274$(hide) $(PRIVATE_CXX) \
275	$(PRIVATE_TARGET_GLOBAL_LDFLAGS) \
276	-nostdlib -Bstatic \
277	-o $@ \
278	$(PRIVATE_TARGET_GLOBAL_LD_DIRS) \
279	$(if $(filter true,$(PRIVATE_NO_CRT)),,$(PRIVATE_TARGET_CRTBEGIN_STATIC_O)) \
280	$(PRIVATE_LDFLAGS) \
281	$(PRIVATE_ALL_OBJECTS) \
282	-Wl,--whole-archive \
283	$(call normalize-target-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
284	-Wl,--no-whole-archive \
285	-Wl,--start-group \
286	$(call normalize-target-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
287	$(PRIVATE_TARGET_FDO_LIB) \
288	$(PRIVATE_TARGET_LIBGCC) \
289	-Wl,--end-group \
290	$(if $(filter true,$(PRIVATE_NO_CRT)),,$(PRIVATE_TARGET_CRTEND_O))
291endef
292
293# Special check for x86 NDK ABI compatibility.
294# The TARGET_CPU_ABI variable should be defined in BoardConfig.mk to 'x86'
295# *only* if the platform image is compatible with the NDK x86 ABI.
296#
297# We perform a small check here to ensure that nothing bad can happen.
298#
299ifeq ($(TARGET_CPU_ABI),x86)
300  ifneq (true-true-true-true,$(ARCH_X86_HAVE_MMX)-$(ARCH_X86_HAVE_SSE)-$(ARCH_X86_HAVE_SSE2)-$(ARCH_X86_HAVE_SSE3))
301    $(info ERROR: Your x86 platform image is not compatible with the NDK x86 ABI)
302    $(info As such, you should *not* define TARGET_CPU_ABI to 'x86' in your BoardConfig.mk)
303    $(info to ensure that your device will not be mistakenly listed as compatible by
304    $(info the Android Market. Also, it is likely that the image will fail the CTS tests)
305    $(info Please undefine TARGET_CPU_ABI in your BoardConfig.mk, or select the value 'none')
306    $(info The corresponding image will still be able to run Dalvik-based Android applications)
307    $(error Aborting build! Please fix your BoardConfig.mk)
308  endif
309endif
310