TARGET_linux-x86.mk revision f6771f631b814189d83b9b16cfa73d1466f932af
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_$(combo_2nd_arch_prefix)ARCH_VARIANT)),)
22TARGET_$(combo_2nd_arch_prefix)ARCH_VARIANT := x86
23endif
24
25# Decouple NDK library selection with platform compiler version
26$(combo_2nd_arch_prefix)TARGET_NDK_GCC_VERSION := 4.8
27
28ifeq ($(strip $(TARGET_GCC_VERSION_EXP)),)
29$(combo_2nd_arch_prefix)TARGET_GCC_VERSION := 4.8
30else
31$(combo_2nd_arch_prefix)TARGET_GCC_VERSION := $(TARGET_GCC_VERSION_EXP)
32endif
33
34# Include the arch-variant-specific configuration file.
35# Its role is to define various ARCH_X86_HAVE_XXX feature macros,
36# plus initial values for TARGET_GLOBAL_CFLAGS
37#
38TARGET_ARCH_SPECIFIC_MAKEFILE := $(BUILD_COMBOS)/arch/$(TARGET_$(combo_2nd_arch_prefix)ARCH)/$(TARGET_$(combo_2nd_arch_prefix)ARCH_VARIANT).mk
39ifeq ($(strip $(wildcard $(TARGET_ARCH_SPECIFIC_MAKEFILE))),)
40$(error Unknown $(TARGET_$(combo_2nd_arch_prefix)ARCH) architecture version: $(TARGET_$(combo_2nd_arch_prefix)ARCH_VARIANT))
41endif
42
43include $(TARGET_ARCH_SPECIFIC_MAKEFILE)
44
45
46# You can set TARGET_TOOLS_PREFIX to get gcc from somewhere else
47ifeq ($(strip $($(combo_2nd_arch_prefix)TARGET_TOOLS_PREFIX)),)
48$(combo_2nd_arch_prefix)TARGET_TOOLCHAIN_ROOT := prebuilts/gcc/$(HOST_PREBUILT_TAG)/x86/x86_64-linux-android-$($(combo_2nd_arch_prefix)TARGET_GCC_VERSION)
49$(combo_2nd_arch_prefix)TARGET_TOOLS_PREFIX := $($(combo_2nd_arch_prefix)TARGET_TOOLCHAIN_ROOT)/bin/x86_64-linux-android-
50endif
51
52$(combo_2nd_arch_prefix)TARGET_CC := $($(combo_2nd_arch_prefix)TARGET_TOOLS_PREFIX)gcc$(HOST_EXECUTABLE_SUFFIX)
53$(combo_2nd_arch_prefix)TARGET_CXX := $($(combo_2nd_arch_prefix)TARGET_TOOLS_PREFIX)g++$(HOST_EXECUTABLE_SUFFIX)
54$(combo_2nd_arch_prefix)TARGET_AR := $($(combo_2nd_arch_prefix)TARGET_TOOLS_PREFIX)ar$(HOST_EXECUTABLE_SUFFIX)
55$(combo_2nd_arch_prefix)TARGET_OBJCOPY := $($(combo_2nd_arch_prefix)TARGET_TOOLS_PREFIX)objcopy$(HOST_EXECUTABLE_SUFFIX)
56$(combo_2nd_arch_prefix)TARGET_LD := $($(combo_2nd_arch_prefix)TARGET_TOOLS_PREFIX)ld$(HOST_EXECUTABLE_SUFFIX)
57$(combo_2nd_arch_prefix)TARGET_READELF := $($(combo_2nd_arch_prefix)TARGET_TOOLS_PREFIX)readelf$(HOST_EXECUTABLE_SUFFIX)
58$(combo_2nd_arch_prefix)TARGET_STRIP := $($(combo_2nd_arch_prefix)TARGET_TOOLS_PREFIX)strip$(HOST_EXECUTABLE_SUFFIX)
59
60ifneq ($(wildcard $($(combo_2nd_arch_prefix)TARGET_CC)),)
61$(combo_2nd_arch_prefix)TARGET_LIBGCC := \
62	$(shell $($(combo_2nd_arch_prefix)TARGET_CC) -m32 -print-file-name=libgcc.a)
63$(combo_2nd_arch_prefix)TARGET_LIBATOMIC := \
64	$(shell $($(combo_2nd_arch_prefix)TARGET_CC) -m32 -print-file-name=libatomic.a)
65target_libgcov := $(shell $($(combo_2nd_arch_prefix)TARGET_CC) $($(combo_2nd_arch_prefix)TARGET_GLOBAL_CFLAGS) \
66	-print-file-name=libgcov.a)
67endif
68
69$(combo_2nd_arch_prefix)TARGET_NO_UNDEFINED_LDFLAGS := -Wl,--no-undefined
70
71libc_root := bionic/libc
72libm_root := bionic/libm
73libstdc++_root := bionic/libstdc++
74
75# Define FDO (Feedback Directed Optimization) options.
76
77$(combo_2nd_arch_prefix)TARGET_FDO_CFLAGS:=
78$(combo_2nd_arch_prefix)TARGET_FDO_LIB:=
79
80ifneq ($(strip $(BUILD_FDO_INSTRUMENT)),)
81  # Set BUILD_FDO_INSTRUMENT=true to turn on FDO instrumentation.
82  # The profile will be generated on /data/local/tmp/profile on the device.
83  $(combo_2nd_arch_prefix)TARGET_FDO_CFLAGS := -fprofile-generate=/data/local/tmp/profile -DANDROID_FDO
84  $(combo_2nd_arch_prefix)TARGET_FDO_LIB := $(target_libgcov)
85else
86  # If BUILD_FDO_INSTRUMENT is turned off, then consider doing the FDO optimizations.
87  # Set TARGET_FDO_PROFILE_PATH to set a custom profile directory for your build.
88  ifeq ($(strip $($(combo_2nd_arch_prefix)TARGET_FDO_PROFILE_PATH)),)
89    $(combo_2nd_arch_prefix)TARGET_FDO_PROFILE_PATH := fdo/profiles/$(TARGET_$(combo_2nd_arch_prefix)ARCH)/$(TARGET_$(combo_2nd_arch_prefix)ARCH_VARIANT)
90  else
91    ifeq ($(strip $(wildcard $($(combo_2nd_arch_prefix)TARGET_FDO_PROFILE_PATH))),)
92      $(warning Custom $(combo_2nd_arch_prefix)TARGET_FDO_PROFILE_PATH supplied, but directory does not exist. Turn off FDO.)
93    endif
94  endif
95
96  # If the FDO profile directory can't be found, then FDO is off.
97  ifneq ($(strip $(wildcard $($(combo_2nd_arch_prefix)TARGET_FDO_PROFILE_PATH))),)
98    $(combo_2nd_arch_prefix)TARGET_FDO_CFLAGS := -fprofile-use=$($(combo_2nd_arch_prefix)TARGET_FDO_PROFILE_PATH) -DANDROID_FDO
99    $(combo_2nd_arch_prefix)TARGET_FDO_LIB := $(target_libgcov)
100  endif
101endif
102
103KERNEL_HEADERS_COMMON := $(libc_root)/kernel/uapi
104KERNEL_HEADERS_ARCH   := $(libc_root)/kernel/uapi/asm-x86 # x86 covers both x86 and x86_64.
105KERNEL_HEADERS := $(KERNEL_HEADERS_COMMON) $(KERNEL_HEADERS_ARCH)
106
107android_config_h := $(call select-android-config-h,target_linux-x86)
108
109$(combo_2nd_arch_prefix)TARGET_GLOBAL_CFLAGS += \
110			-O2 \
111			-Wa,--noexecstack \
112			-Werror=format-security \
113			-D_FORTIFY_SOURCE=2 \
114			-Wstrict-aliasing=2 \
115			-fPIC \
116			-ffunction-sections \
117			-finline-functions \
118			-finline-limit=300 \
119			-fno-inline-functions-called-once \
120			-fno-short-enums \
121			-fstrict-aliasing \
122			-funswitch-loops \
123			-funwind-tables \
124			-fstack-protector \
125			-m32 \
126			-msse2 \
127			-no-canonical-prefixes \
128			-fno-canonical-system-headers \
129			-include $(android_config_h) \
130			-I $(dir $(android_config_h))
131
132$(combo_2nd_arch_prefix)TARGET_GLOBAL_CFLAGS += $(arch_variant_cflags)
133
134ifeq ($(ARCH_X86_HAVE_SSSE3),true)   # yes, really SSSE3, not SSE3!
135    $(combo_2nd_arch_prefix)TARGET_GLOBAL_CFLAGS += -DUSE_SSSE3 -mssse3
136endif
137ifeq ($(ARCH_X86_HAVE_SSE4),true)
138    $(combo_2nd_arch_prefix)TARGET_GLOBAL_CFLAGS += -msse4
139endif
140ifeq ($(ARCH_X86_HAVE_SSE4_1),true)
141    $(combo_2nd_arch_prefix)TARGET_GLOBAL_CFLAGS += -msse4.1
142endif
143ifeq ($(ARCH_X86_HAVE_SSE4_2),true)
144    $(combo_2nd_arch_prefix)TARGET_GLOBAL_CFLAGS += -msse4.2
145endif
146ifeq ($(ARCH_X86_HAVE_AVX),true)
147    $(combo_2nd_arch_prefix)TARGET_GLOBAL_CFLAGS += -mavx
148endif
149ifeq ($(ARCH_X86_HAVE_AES_NI),true)
150    $(combo_2nd_arch_prefix)TARGET_GLOBAL_CFLAGS += -maes
151endif
152
153$(combo_2nd_arch_prefix)TARGET_GLOBAL_LDFLAGS += -m32
154
155$(combo_2nd_arch_prefix)TARGET_GLOBAL_LDFLAGS += -Wl,-z,noexecstack
156$(combo_2nd_arch_prefix)TARGET_GLOBAL_LDFLAGS += -Wl,-z,relro -Wl,-z,now
157$(combo_2nd_arch_prefix)TARGET_GLOBAL_LDFLAGS += -Wl,--warn-shared-textrel
158$(combo_2nd_arch_prefix)TARGET_GLOBAL_LDFLAGS += -Wl,--fatal-warnings
159$(combo_2nd_arch_prefix)TARGET_GLOBAL_LDFLAGS += -Wl,--gc-sections
160
161$(combo_2nd_arch_prefix)TARGET_C_INCLUDES := \
162	$(libc_root)/arch-x86/include \
163	$(libc_root)/include \
164	$(libstdc++_root)/include \
165	$(KERNEL_HEADERS) \
166	$(libm_root)/include \
167	$(libm_root)/include/i387 \
168
169$(combo_2nd_arch_prefix)TARGET_CRTBEGIN_STATIC_O := $($(combo_2nd_arch_prefix)TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbegin_static.o
170$(combo_2nd_arch_prefix)TARGET_CRTBEGIN_DYNAMIC_O := $($(combo_2nd_arch_prefix)TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbegin_dynamic.o
171$(combo_2nd_arch_prefix)TARGET_CRTEND_O := $($(combo_2nd_arch_prefix)TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtend_android.o
172
173$(combo_2nd_arch_prefix)TARGET_CRTBEGIN_SO_O := $($(combo_2nd_arch_prefix)TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbegin_so.o
174$(combo_2nd_arch_prefix)TARGET_CRTEND_SO_O := $($(combo_2nd_arch_prefix)TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtend_so.o
175
176$(combo_2nd_arch_prefix)TARGET_STRIP_MODULE:=true
177
178$(combo_2nd_arch_prefix)TARGET_DEFAULT_SYSTEM_SHARED_LIBRARIES := libc libstdc++ libm
179
180$(combo_2nd_arch_prefix)TARGET_CUSTOM_LD_COMMAND := true
181define $(combo_2nd_arch_prefix)transform-o-to-shared-lib-inner
182$(hide) $(PRIVATE_CXX) \
183	$(PRIVATE_TARGET_GLOBAL_LDFLAGS) \
184	 -nostdlib -Wl,-soname,$(notdir $@) \
185	 -shared \
186	$(PRIVATE_TARGET_GLOBAL_LD_DIRS) \
187	$(if $(filter true,$(PRIVATE_NO_CRT)),,$(PRIVATE_TARGET_CRTBEGIN_SO_O)) \
188	$(PRIVATE_ALL_OBJECTS) \
189	-Wl,--whole-archive \
190	$(call normalize-target-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
191	-Wl,--no-whole-archive \
192	$(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--start-group) \
193	$(call normalize-target-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
194	$(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--end-group) \
195	$(if $(TARGET_BUILD_APPS),$(PRIVATE_TARGET_LIBGCC)) \
196	$(PRIVATE_TARGET_FDO_LIB) \
197	$(call normalize-target-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
198	-o $@ \
199	$(PRIVATE_LDFLAGS) \
200	$(PRIVATE_TARGET_LIBATOMIC) \
201	$(if $(PRIVATE_LIBCXX),,$(PRIVATE_TARGET_LIBGCC)) \
202	$(if $(filter true,$(PRIVATE_NO_CRT)),,$(PRIVATE_TARGET_CRTEND_SO_O)) \
203	$(PRIVATE_LDLIBS)
204endef
205
206define $(combo_2nd_arch_prefix)transform-o-to-executable-inner
207$(hide) $(PRIVATE_CXX) \
208	$(PRIVATE_TARGET_GLOBAL_LDFLAGS) \
209	-nostdlib -Bdynamic \
210	-Wl,-z,nocopyreloc \
211	-fPIE -pie \
212	$(PRIVATE_TARGET_GLOBAL_LD_DIRS) \
213	-Wl,-rpath-link=$(PRIVATE_TARGET_OUT_INTERMEDIATE_LIBRARIES) \
214	$(if $(filter true,$(PRIVATE_NO_CRT)),,$(PRIVATE_TARGET_CRTBEGIN_DYNAMIC_O)) \
215	$(PRIVATE_ALL_OBJECTS) \
216	-Wl,--whole-archive \
217	$(call normalize-target-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
218	-Wl,--no-whole-archive \
219	$(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--start-group) \
220	$(call normalize-target-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
221	$(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--end-group) \
222	$(if $(TARGET_BUILD_APPS),$(PRIVATE_TARGET_LIBGCC)) \
223	$(PRIVATE_TARGET_FDO_LIB) \
224	$(call normalize-target-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
225	-o $@ \
226	$(PRIVATE_LDFLAGS) \
227	$(PRIVATE_TARGET_LIBATOMIC) \
228	$(if $(PRIVATE_LIBCXX),,$(PRIVATE_TARGET_LIBGCC)) \
229	$(if $(filter true,$(PRIVATE_NO_CRT)),,$(PRIVATE_TARGET_CRTEND_O)) \
230	$(PRIVATE_LDLIBS)
231endef
232
233define $(combo_2nd_arch_prefix)transform-o-to-static-executable-inner
234$(hide) $(PRIVATE_CXX) \
235	$(PRIVATE_TARGET_GLOBAL_LDFLAGS) \
236	-nostdlib -Bstatic \
237	-o $@ \
238	$(PRIVATE_TARGET_GLOBAL_LD_DIRS) \
239	$(if $(filter true,$(PRIVATE_NO_CRT)),,$(PRIVATE_TARGET_CRTBEGIN_STATIC_O)) \
240	$(PRIVATE_LDFLAGS) \
241	$(PRIVATE_ALL_OBJECTS) \
242	-Wl,--whole-archive \
243	$(call normalize-target-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
244	-Wl,--no-whole-archive \
245	-Wl,--start-group \
246	$(call normalize-target-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
247	$(PRIVATE_TARGET_FDO_LIB) \
248	$(PRIVATE_TARGET_LIBATOMIC) \
249	$(if $(PRIVATE_LIBCXX),,$(PRIVATE_TARGET_LIBGCC)) \
250	-Wl,--end-group \
251	$(if $(filter true,$(PRIVATE_NO_CRT)),,$(PRIVATE_TARGET_CRTEND_O))
252endef
253