TARGET_linux-x86.mk revision c3192b316474df4f01b635a50b8696f7821b781b
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# You can set TARGET_TOOLS_PREFIX to get gcc from somewhere else
26ifeq ($(strip $(TARGET_TOOLS_PREFIX)),)
27TARGET_TOOLS_PREFIX := \
28	prebuilts/gcc/$(HOST_PREBUILT_TAG)/x86/i686-linux-android-4.6/bin/i686-linux-android-
29endif
30
31TARGET_CC := $(TARGET_TOOLS_PREFIX)gcc$(HOST_EXECUTABLE_SUFFIX)
32TARGET_CXX := $(TARGET_TOOLS_PREFIX)g++$(HOST_EXECUTABLE_SUFFIX)
33TARGET_AR := $(TARGET_TOOLS_PREFIX)ar$(HOST_EXECUTABLE_SUFFIX)
34TARGET_OBJCOPY := $(TARGET_TOOLS_PREFIX)objcopy$(HOST_EXECUTABLE_SUFFIX)
35TARGET_LD := $(TARGET_TOOLS_PREFIX)ld$(HOST_EXECUTABLE_SUFFIX)
36TARGET_STRIP := $(TARGET_TOOLS_PREFIX)strip$(HOST_EXECUTABLE_SUFFIX)
37
38ifeq ($(TARGET_BUILD_VARIANT),user)
39TARGET_STRIP_COMMAND = $(TARGET_STRIP) --strip-debug $< -o $@
40else
41TARGET_STRIP_COMMAND = $(TARGET_STRIP) --strip-debug $< -o $@ && \
42	$(TARGET_OBJCOPY) --add-gnu-debuglink=$< $@
43endif
44
45ifneq ($(wildcard $(TARGET_CC)),)
46TARGET_LIBGCC := \
47	$(shell $(TARGET_CC) -m32 -print-file-name=libgcc.a)
48endif
49
50TARGET_NO_UNDEFINED_LDFLAGS := -Wl,--no-undefined
51
52libc_root := bionic/libc
53libm_root := bionic/libm
54libstdc++_root := bionic/libstdc++
55libthread_db_root := bionic/libthread_db
56
57# unless CUSTOM_KERNEL_HEADERS is defined, we're going to use
58# symlinks located in out/ to point to the appropriate kernel
59# headers. see 'config/kernel_headers.make' for more details
60#
61ifneq ($(CUSTOM_KERNEL_HEADERS),)
62    KERNEL_HEADERS_COMMON := $(CUSTOM_KERNEL_HEADERS)
63    KERNEL_HEADERS_ARCH   := $(CUSTOM_KERNEL_HEADERS)
64else
65    KERNEL_HEADERS_COMMON := $(libc_root)/kernel/common
66    KERNEL_HEADERS_ARCH   := $(libc_root)/kernel/arch-$(TARGET_ARCH)
67endif
68KERNEL_HEADERS := $(KERNEL_HEADERS_COMMON) $(KERNEL_HEADERS_ARCH)
69
70TARGET_GLOBAL_CFLAGS += \
71			-O2 \
72			-Ulinux \
73			-Wa,--noexecstack \
74			-Werror=format-security \
75			-Wstrict-aliasing=2 \
76			-fPIC \
77			-ffunction-sections \
78			-finline-functions \
79			-finline-limit=300 \
80			-fno-inline-functions-called-once \
81			-fno-short-enums \
82			-fstrict-aliasing \
83			-funswitch-loops \
84			-funwind-tables \
85			-include $(call select-android-config-h,target_linux-x86)
86
87# Needs to be fixed later
88#TARGET_GLOBAL_CFLAGS += \
89#			-fstack-protector
90
91# Needs to be added for RELEASE
92#TARGET_GLOBAL_CFLAGS += \
93#			-DNDEBUG
94
95TARGET_GLOBAL_CPPFLAGS += \
96			-fno-use-cxa-atexit
97
98ifeq ($(TARGET_ARCH_VARIANT),x86-atom)
99    # Basic ATOM flags - only use this if you have both ssse3 and movbe instructions
100    TARGET_GLOBAL_CFLAGS += -march=atom -mstackrealign -mfpmath=sse -m32
101
102    # There are various levels of ATOM processors out there. Different ones have different
103    # capabilities.
104    # Note: Not all of the flags set here are actually used in Android. They are provided
105    # to allow for the addition of corresponding optimizations.
106    TARGET_GLOBAL_CFLAGS += -DUSE_MMX -DUSE_SSE -DUSE_SSE2 -DUSE_SSE3 -DUSE_SSSE3
107else
108    # Plain 'x86' - Requires sse3, use if you have nossse3 or movbe
109    #
110    # Note: The NDK's ABI (see the NDK ABI documentation) requires many of the more recent
111    # instruction set additions. You can build an "x86" BSP that will run on very old hardware,
112    # but it won't be able to run much of the x86 NDK compliant code.
113    TARGET_GLOBAL_CFLAGS += -march=i686 -msse3 -mfpmath=sse -m32
114    TARGET_GLOBAL_CFLAGS += -DUSE_MMX -DUSE_SSE -DUSE_SSE2 -DUSE_SSE3
115endif
116
117TARGET_GLOBAL_CFLAGS += -mbionic
118TARGET_GLOBAL_CFLAGS += -D__ANDROID__
119
120TARGET_GLOBAL_LDFLAGS += -m32
121TARGET_GLOBAL_LDFLAGS += -Wl,-z,noexecstack
122TARGET_GLOBAL_LDFLAGS += -Wl,--gc-sections
123
124TARGET_C_INCLUDES := \
125	$(libc_root)/arch-x86/include \
126	$(libc_root)/include \
127	$(libstdc++_root)/include \
128	$(KERNEL_HEADERS) \
129	$(libm_root)/include \
130	$(libm_root)/include/i387 \
131	$(libthread_db_root)/include
132
133TARGET_CRTBEGIN_STATIC_O := $(TARGET_OUT_STATIC_LIBRARIES)/crtbegin_static.o
134TARGET_CRTBEGIN_DYNAMIC_O := $(TARGET_OUT_STATIC_LIBRARIES)/crtbegin_dynamic.o
135TARGET_CRTEND_O := $(TARGET_OUT_STATIC_LIBRARIES)/crtend_android.o
136
137TARGET_CRTBEGIN_SO_O := $(TARGET_OUT_STATIC_LIBRARIES)/crtbegin_so.o
138TARGET_CRTEND_SO_O := $(TARGET_OUT_STATIC_LIBRARIES)/crtend_so.o
139
140TARGET_STRIP_MODULE:=true
141
142TARGET_DEFAULT_SYSTEM_SHARED_LIBRARIES := libc libstdc++ libm
143
144TARGET_CUSTOM_LD_COMMAND := true
145define transform-o-to-shared-lib-inner
146$(hide) $(PRIVATE_CXX) \
147	$(PRIVATE_TARGET_GLOBAL_LDFLAGS) \
148	 -nostdlib -Wl,-soname,$(notdir $@) \
149	 -shared -Bsymbolic \
150	$(TARGET_GLOBAL_CFLAGS) \
151	$(PRIVATE_TARGET_GLOBAL_LD_DIRS) \
152	$(if $(filter true,$(PRIVATE_NO_CRT)),,$(PRIVATE_TARGET_CRTBEGIN_SO_O)) \
153	$(PRIVATE_ALL_OBJECTS) \
154	-Wl,--whole-archive \
155	$(call normalize-target-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
156	-Wl,--no-whole-archive \
157	$(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--start-group) \
158	$(call normalize-target-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
159	$(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--end-group) \
160	$(call normalize-target-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
161	-o $@ \
162	$(PRIVATE_LDFLAGS) \
163	$(PRIVATE_TARGET_LIBGCC) \
164	$(if $(filter true,$(PRIVATE_NO_CRT)),,$(PRIVATE_TARGET_CRTEND_SO_O))
165endef
166
167
168define transform-o-to-executable-inner
169$(hide) $(PRIVATE_CXX) \
170	$(TARGET_GLOBAL_LDFLAGS) \
171	-nostdlib -Bdynamic \
172	-Wl,-dynamic-linker,/system/bin/linker \
173	-Wl,-z,nocopyreloc \
174	-o $@ \
175	$(TARGET_GLOBAL_LD_DIRS) \
176	-Wl,-rpath-link=$(TARGET_OUT_INTERMEDIATE_LIBRARIES) \
177	$(call normalize-target-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
178	$(if $(filter true,$(PRIVATE_NO_CRT)),,$(TARGET_CRTBEGIN_DYNAMIC_O)) \
179	$(PRIVATE_ALL_OBJECTS) \
180	-Wl,--whole-archive \
181	$(call normalize-target-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
182	-Wl,--no-whole-archive \
183	$(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--start-group) \
184	$(call normalize-target-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
185	$(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--end-group) \
186	$(PRIVATE_LDFLAGS) \
187	$(TARGET_LIBGCC) \
188	$(if $(filter true,$(PRIVATE_NO_CRT)),,$(TARGET_CRTEND_O))
189endef
190
191define transform-o-to-static-executable-inner
192$(hide) $(PRIVATE_CXX) \
193	$(TARGET_GLOBAL_LDFLAGS) \
194	-nostdlib -Bstatic \
195	-o $@ \
196	$(TARGET_GLOBAL_LD_DIRS) \
197	$(if $(filter true,$(PRIVATE_NO_CRT)),,$(TARGET_CRTBEGIN_STATIC_O)) \
198	$(PRIVATE_LDFLAGS) \
199	$(PRIVATE_ALL_OBJECTS) \
200	-Wl,--whole-archive \
201	$(call normalize-target-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
202	-Wl,--no-whole-archive \
203	-Wl,--start-group \
204	$(call normalize-target-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
205	$(TARGET_LIBGCC) \
206	-Wl,--end-group \
207	$(if $(filter true,$(PRIVATE_NO_CRT)),,$(TARGET_CRTEND_O))
208endef
209