TARGET_linux-x86.mk revision 52b63178d9e7da82301ecbc7d673154242b1c9a6
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.
100    TARGET_GLOBAL_CFLAGS += -march=atom -mstackrealign -mfpmath=sse
101
102    # There are various levels of ATOM processors out there. Different ones have different
103    # capabilities. This first define matches the NDK's minimum ABI requirements.
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
107
108    # If you wish to build a BSP that will only be used on hardware that has additional
109    # available instructions, enable them here. By default, this is commented off so that
110    # the default images can run on all processors that are NDK ABI compliant.
111    # TARGET_GLOBAL_CFLAGS += -DUSE_SSSE3
112else
113    # Plain 'x86' - lowest common denominator. This should run pretty much on any hardware.
114    #
115    # Note: The NDK's ABI (see the NDK ABI documentation) requires many of the more recent
116    # instruction set additions. You can build an "x86" BSP that will run on very old hardware,
117    # but it won't be able to run much of the x86 NDK compliant code.
118    TARGET_GLOBAL_CFLAGS += -march=i686
119endif
120
121TARGET_GLOBAL_CFLAGS += -mbionic
122TARGET_GLOBAL_CFLAGS += -D__ANDROID__
123
124TARGET_GLOBAL_LDFLAGS += -m32
125TARGET_GLOBAL_LDFLAGS += -Wl,-z,noexecstack
126TARGET_GLOBAL_LDFLAGS += -Wl,--gc-sections
127
128TARGET_C_INCLUDES := \
129	$(libc_root)/arch-x86/include \
130	$(libc_root)/include \
131	$(libstdc++_root)/include \
132	$(KERNEL_HEADERS) \
133	$(libm_root)/include \
134	$(libm_root)/include/i387 \
135	$(libthread_db_root)/include
136
137TARGET_CRTBEGIN_STATIC_O := $(TARGET_OUT_STATIC_LIBRARIES)/crtbegin_static.o
138TARGET_CRTBEGIN_DYNAMIC_O := $(TARGET_OUT_STATIC_LIBRARIES)/crtbegin_dynamic.o
139TARGET_CRTEND_O := $(TARGET_OUT_STATIC_LIBRARIES)/crtend_android.o
140
141TARGET_CRTBEGIN_SO_O := $(TARGET_OUT_STATIC_LIBRARIES)/crtbegin_so.o
142TARGET_CRTEND_SO_O := $(TARGET_OUT_STATIC_LIBRARIES)/crtend_so.o
143
144TARGET_STRIP_MODULE:=true
145
146TARGET_DEFAULT_SYSTEM_SHARED_LIBRARIES := libc libstdc++ libm
147
148TARGET_CUSTOM_LD_COMMAND := true
149define transform-o-to-shared-lib-inner
150$(hide) $(PRIVATE_CXX) \
151	$(PRIVATE_TARGET_GLOBAL_LDFLAGS) \
152	 -nostdlib -Wl,-soname,$(notdir $@) \
153	 -shared -Bsymbolic \
154	$(TARGET_GLOBAL_CFLAGS) \
155	$(PRIVATE_TARGET_GLOBAL_LD_DIRS) \
156	$(if $(filter true,$(PRIVATE_NO_CRT)),,$(PRIVATE_TARGET_CRTBEGIN_SO_O)) \
157	$(PRIVATE_ALL_OBJECTS) \
158	-Wl,--whole-archive \
159	$(call normalize-target-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
160	-Wl,--no-whole-archive \
161	$(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--start-group) \
162	$(call normalize-target-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
163	$(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--end-group) \
164	$(call normalize-target-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
165	-o $@ \
166	$(PRIVATE_LDFLAGS) \
167	$(PRIVATE_TARGET_LIBGCC) \
168	$(if $(filter true,$(PRIVATE_NO_CRT)),,$(PRIVATE_TARGET_CRTEND_SO_O))
169endef
170
171
172define transform-o-to-executable-inner
173$(hide) $(PRIVATE_CXX) \
174	$(TARGET_GLOBAL_LDFLAGS) \
175	-nostdlib -Bdynamic \
176	-Wl,-dynamic-linker,/system/bin/linker \
177	-Wl,--copy-dt-needed-entries \
178	-Wl,-z,nocopyreloc \
179	-o $@ \
180	$(TARGET_GLOBAL_LD_DIRS) \
181	-Wl,-rpath-link=$(TARGET_OUT_INTERMEDIATE_LIBRARIES) \
182	$(call normalize-target-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
183	$(if $(filter true,$(PRIVATE_NO_CRT)),,$(TARGET_CRTBEGIN_DYNAMIC_O)) \
184	$(PRIVATE_ALL_OBJECTS) \
185	-Wl,--whole-archive \
186	$(call normalize-target-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
187	-Wl,--no-whole-archive \
188	$(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--start-group) \
189	$(call normalize-target-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
190	$(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--end-group) \
191	$(PRIVATE_LDFLAGS) \
192	$(TARGET_LIBGCC) \
193	$(if $(filter true,$(PRIVATE_NO_CRT)),,$(TARGET_CRTEND_O))
194endef
195
196define transform-o-to-static-executable-inner
197$(hide) $(PRIVATE_CXX) \
198	$(TARGET_GLOBAL_LDFLAGS) \
199	-nostdlib -Bstatic \
200	-o $@ \
201	$(TARGET_GLOBAL_LD_DIRS) \
202	$(if $(filter true,$(PRIVATE_NO_CRT)),,$(TARGET_CRTBEGIN_STATIC_O)) \
203	$(PRIVATE_LDFLAGS) \
204	$(PRIVATE_ALL_OBJECTS) \
205	-Wl,--whole-archive \
206	$(call normalize-target-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
207	-Wl,--no-whole-archive \
208	-Wl,--start-group \
209	$(call normalize-target-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
210	$(TARGET_LIBGCC) \
211	-Wl,--end-group \
212	$(if $(filter true,$(PRIVATE_NO_CRT)),,$(TARGET_CRTEND_O))
213endef
214