OSDN Git Service

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