TARGET_linux-arm.mk revision efd2489b39a840a66baa06a2f333e7c15d4ba383
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 ARM.
18# Included by combo/select.mk
19
20# You can set TARGET_ARCH_VARIANT to use an arch version other
21# than ARMv5TE. Each value should correspond to a file named
22# $(BUILD_COMBOS)/arch/<name>.mk which must contain
23# makefile variable definitions similar to the preprocessor
24# defines in system/core/include/arch/<combo>/AndroidConfig.h. Their
25# purpose is to allow module Android.mk files to selectively compile
26# different versions of code based upon the funtionality and
27# instructions available in a given architecture version.
28#
29# The blocks also define specific arch_variant_cflags, which
30# include defines, and compiler settings for the given architecture
31# version.
32#
33ifeq ($(strip $(TARGET_ARCH_VARIANT)),)
34TARGET_ARCH_VARIANT := armv5te
35endif
36
37TARGET_ARCH_SPECIFIC_MAKEFILE := $(BUILD_COMBOS)/arch/$(TARGET_ARCH)/$(TARGET_ARCH_VARIANT).mk
38ifeq ($(strip $(wildcard $(TARGET_ARCH_SPECIFIC_MAKEFILE))),)
39$(error Unknown ARM architecture version: $(TARGET_ARCH_VARIANT))
40endif
41
42include $(TARGET_ARCH_SPECIFIC_MAKEFILE)
43
44# You can set TARGET_TOOLS_PREFIX to get gcc from somewhere else
45ifeq ($(strip $(TARGET_TOOLS_PREFIX)),)
46TARGET_TOOLS_PREFIX := \
47	prebuilt/$(HOST_PREBUILT_TAG)/toolchain/arm-linux-androideabi-4.4.x/bin/arm-linux-androideabi-
48endif
49
50TARGET_CC := $(TARGET_TOOLS_PREFIX)gcc$(HOST_EXECUTABLE_SUFFIX)
51TARGET_CXX := $(TARGET_TOOLS_PREFIX)g++$(HOST_EXECUTABLE_SUFFIX)
52TARGET_AR := $(TARGET_TOOLS_PREFIX)ar$(HOST_EXECUTABLE_SUFFIX)
53TARGET_OBJCOPY := $(TARGET_TOOLS_PREFIX)objcopy$(HOST_EXECUTABLE_SUFFIX)
54TARGET_LD := $(TARGET_TOOLS_PREFIX)ld$(HOST_EXECUTABLE_SUFFIX)
55TARGET_STRIP := $(HOST_OUT_EXECUTABLES)/soslim$(HOST_EXECUTABLE_SUFFIX)
56TARGET_STRIP_COMMAND = $(TARGET_STRIP) --strip --shady --quiet $< --outfile $@
57
58TARGET_NO_UNDEFINED_LDFLAGS := -Wl,--no-undefined
59
60TARGET_arm_CFLAGS :=    -O2 \
61                        -fomit-frame-pointer \
62                        -fstrict-aliasing    \
63                        -funswitch-loops     \
64                        -finline-limit=300
65
66# Modules can choose to compile some source as thumb. As
67# non-thumb enabled targets are supported, this is treated
68# as a 'hint'. If thumb is not enabled, these files are just
69# compiled as ARM.
70ifeq ($(ARCH_ARM_HAVE_THUMB_SUPPORT),true)
71TARGET_thumb_CFLAGS :=  -mthumb \
72                        -Os \
73                        -fomit-frame-pointer \
74                        -fno-strict-aliasing \
75                        -finline-limit=64
76else
77TARGET_thumb_CFLAGS := $(TARGET_arm_CFLAGS)
78endif
79
80# Set FORCE_ARM_DEBUGGING to "true" in your buildspec.mk
81# or in your environment to force a full arm build, even for
82# files that are normally built as thumb; this can make
83# gdb debugging easier.  Don't forget to do a clean build.
84#
85# NOTE: if you try to build a -O0 build with thumb, several
86# of the libraries (libpv, libwebcore, libkjs) need to be built
87# with -mlong-calls.  When built at -O0, those libraries are
88# too big for a thumb "BL <label>" to go from one end to the other.
89ifeq ($(FORCE_ARM_DEBUGGING),true)
90  TARGET_arm_CFLAGS += -fno-omit-frame-pointer -fno-strict-aliasing
91  TARGET_thumb_CFLAGS += -marm -fno-omit-frame-pointer
92endif
93
94android_config_h := $(call select-android-config-h,linux-arm)
95arch_include_dir := $(dir $(android_config_h))
96
97TARGET_GLOBAL_CFLAGS += \
98			-msoft-float -fpic \
99			-ffunction-sections \
100			-fdata-sections \
101			-funwind-tables \
102			-fstack-protector \
103			-Wa,--noexecstack \
104			-Werror=format-security \
105			-fno-short-enums \
106			$(arch_variant_cflags) \
107			-include $(android_config_h) \
108			-I $(arch_include_dir)
109
110# This is to avoid the dreaded warning compiler message:
111#   note: the mangling of 'va_list' has changed in GCC 4.4
112#
113# The fact that the mangling changed does not affect the NDK ABI
114# very fortunately (since none of the exposed APIs used va_list
115# in their exported C++ functions). Also, GCC 4.5 has already
116# removed the warning from the compiler.
117#
118TARGET_GLOBAL_CFLAGS += -Wno-psabi
119
120TARGET_GLOBAL_LDFLAGS += \
121			-Wl,-z,noexecstack \
122			-Wl,--icf=safe \
123			$(arch_variant_ldflags)
124
125# We only need thumb interworking in cases where thumb support
126# is available in the architecture, and just to be sure, (and
127# since sometimes thumb-interwork appears to be default), we
128# specifically disable when thumb support is unavailable.
129ifeq ($(ARCH_ARM_HAVE_THUMB_SUPPORT),true)
130TARGET_GLOBAL_CFLAGS +=	-mthumb-interwork
131else
132TARGET_GLOBAL_CFLAGS +=	-mno-thumb-interwork
133endif
134
135TARGET_GLOBAL_CPPFLAGS += -fvisibility-inlines-hidden
136
137# More flags/options can be added here
138ifeq ($(NEED_WORKAROUND_CORTEX_A9_745320),true)
139TARGET_GLOBAL_CFLAGS += -DWORKAROUND_CORTEX_A9_745320
140endif
141
142TARGET_RELEASE_CFLAGS := \
143			-DNDEBUG \
144			-g \
145			-Wstrict-aliasing=2 \
146			-finline-functions \
147			-fno-inline-functions-called-once \
148			-fgcse-after-reload \
149			-frerun-cse-after-loop \
150			-frename-registers
151
152libc_root := bionic/libc
153libm_root := bionic/libm
154libstdc++_root := bionic/libstdc++
155libthread_db_root := bionic/libthread_db
156
157
158## on some hosts, the target cross-compiler is not available so do not run this command
159ifneq ($(wildcard $(TARGET_CC)),)
160# We compile with the global cflags to ensure that
161# any flags which affect libgcc are correctly taken
162# into account.
163TARGET_LIBGCC := $(shell $(TARGET_CC) $(TARGET_GLOBAL_CFLAGS) -print-libgcc-file-name)
164endif
165
166# Define FDO (Feedback Directed Optimization) options.
167
168TARGET_FDO_CFLAGS:=
169TARGET_FDO_LIB:=
170
171target_libgcov := $(shell $(TARGET_CC) $(TARGET_GLOBAL_CFLAGS) \
172        --print-file-name=libgcov.a)
173ifneq ($(strip $(BUILD_FDO_INSTRUMENT)),)
174  # Set BUILD_FDO_INSTRUMENT=true to turn on FDO instrumentation.
175  # The profile will be generated on /data/local/tmp/profile on the device.
176  TARGET_FDO_CFLAGS := -fprofile-generate=/data/local/tmp/profile -DANDROID_FDO
177  TARGET_FDO_LIB := $(target_libgcov)
178else
179  # If BUILD_FDO_INSTRUMENT is turned off, then consider doing the FDO optimizations.
180  # Set TARGET_FDO_PROFILE_PATH to set a custom profile directory for your build.
181  ifeq ($(strip $(TARGET_FDO_PROFILE_PATH)),)
182    TARGET_FDO_PROFILE_PATH := fdo/profiles/$(TARGET_ARCH)/$(TARGET_ARCH_VARIANT)
183  else
184    ifeq ($(strip $(wildcard $(TARGET_FDO_PROFILE_PATH))),)
185      $(warning Custom TARGET_FDO_PROFILE_PATH supplied, but directory does not exist. Turn off FDO.)
186    endif
187  endif
188
189  # If the FDO profile directory can't be found, then FDO is off.
190  ifneq ($(strip $(wildcard $(TARGET_FDO_PROFILE_PATH))),)
191    TARGET_FDO_CFLAGS := -fprofile-use=$(TARGET_FDO_PROFILE_PATH) -DANDROID_FDO
192    TARGET_FDO_LIB := $(target_libgcov)
193  endif
194endif
195
196
197# unless CUSTOM_KERNEL_HEADERS is defined, we're going to use
198# symlinks located in out/ to point to the appropriate kernel
199# headers. see 'config/kernel_headers.make' for more details
200#
201ifneq ($(CUSTOM_KERNEL_HEADERS),)
202    KERNEL_HEADERS_COMMON := $(CUSTOM_KERNEL_HEADERS)
203    KERNEL_HEADERS_ARCH   := $(CUSTOM_KERNEL_HEADERS)
204else
205    KERNEL_HEADERS_COMMON := $(libc_root)/kernel/common
206    KERNEL_HEADERS_ARCH   := $(libc_root)/kernel/arch-$(TARGET_ARCH)
207endif
208KERNEL_HEADERS := $(KERNEL_HEADERS_COMMON) $(KERNEL_HEADERS_ARCH)
209
210TARGET_C_INCLUDES := \
211	$(libc_root)/arch-arm/include \
212	$(libc_root)/include \
213	$(libstdc++_root)/include \
214	$(KERNEL_HEADERS) \
215	$(libm_root)/include \
216	$(libm_root)/include/arm \
217	$(libthread_db_root)/include
218
219TARGET_CRTBEGIN_STATIC_O := $(TARGET_OUT_STATIC_LIBRARIES)/crtbegin_static.o
220TARGET_CRTBEGIN_DYNAMIC_O := $(TARGET_OUT_STATIC_LIBRARIES)/crtbegin_dynamic.o
221TARGET_CRTEND_O := $(TARGET_OUT_STATIC_LIBRARIES)/crtend_android.o
222
223TARGET_CRTBEGIN_SO_O := $(TARGET_OUT_STATIC_LIBRARIES)/crtbegin_so.o
224TARGET_CRTEND_SO_O := $(TARGET_OUT_STATIC_LIBRARIES)/crtend_so.o
225
226TARGET_STRIP_MODULE:=true
227
228TARGET_DEFAULT_SYSTEM_SHARED_LIBRARIES := libc libstdc++ libm
229
230TARGET_CUSTOM_LD_COMMAND := true
231
232# Enable the Dalvik JIT compiler if not already specified.
233ifeq ($(strip $(WITH_JIT)),)
234    WITH_JIT := true
235endif
236
237define transform-o-to-shared-lib-inner
238$(TARGET_CXX) \
239	-nostdlib -Wl,-soname,$(notdir $@) -Wl,-T,$(BUILD_SYSTEM)/armelf.xsc \
240	-Wl,--gc-sections \
241	-Wl,-shared,-Bsymbolic \
242	$(PRIVATE_TARGET_GLOBAL_LD_DIRS) \
243	$(PRIVATE_ALL_OBJECTS) \
244	$(PRIVATE_TARGET_CRTBEGIN_SO_O) \
245	-Wl,--whole-archive \
246	$(call normalize-host-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
247	-Wl,--no-whole-archive \
248	$(call normalize-target-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
249	$(call normalize-target-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
250	-o $@ \
251	$(PRIVATE_TARGET_GLOBAL_LDFLAGS) \
252	$(PRIVATE_LDFLAGS) \
253	$(PRIVATE_TARGET_FDO_LIB) \
254	$(PRIVATE_TARGET_LIBGCC) \
255	$(PRIVATE_TARGET_CRTEND_SO_O)
256endef
257
258define transform-o-to-executable-inner
259$(TARGET_CXX) -nostdlib -Bdynamic -Wl,-T,$(BUILD_SYSTEM)/armelf.x \
260	-Wl,-dynamic-linker,/system/bin/linker \
261    -Wl,--gc-sections \
262	-Wl,-z,nocopyreloc \
263	-o $@ \
264	$(TARGET_GLOBAL_LD_DIRS) \
265	-Wl,-rpath-link=$(TARGET_OUT_INTERMEDIATE_LIBRARIES) \
266	$(call normalize-target-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
267	$(TARGET_CRTBEGIN_DYNAMIC_O) \
268	$(PRIVATE_ALL_OBJECTS) \
269	$(call normalize-target-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
270	$(TARGET_GLOBAL_LDFLAGS) \
271	$(PRIVATE_LDFLAGS) \
272	$(TARGET_FDO_LIB) \
273	$(TARGET_LIBGCC) \
274	$(TARGET_CRTEND_O)
275endef
276
277define transform-o-to-static-executable-inner
278$(TARGET_CXX) -nostdlib -Bstatic -Wl,-T,$(BUILD_SYSTEM)/armelf.x \
279    -Wl,--gc-sections \
280	-o $@ \
281	$(TARGET_GLOBAL_LD_DIRS) \
282	$(TARGET_CRTBEGIN_STATIC_O) \
283	$(TARGET_GLOBAL_LDFLAGS) \
284	$(PRIVATE_LDFLAGS) \
285	$(PRIVATE_ALL_OBJECTS) \
286	$(call normalize-target-libraries,$(filter-out %libc_nomalloc.a,$(filter-out %libc.a,$(PRIVATE_ALL_STATIC_LIBRARIES)))) \
287	-Wl,--start-group \
288	$(call normalize-target-libraries,$(filter %libc.a,$(PRIVATE_ALL_STATIC_LIBRARIES))) \
289	$(call normalize-target-libraries,$(filter %libc_nomalloc.a,$(PRIVATE_ALL_STATIC_LIBRARIES))) \
290	$(TARGET_FDO_LIB) \
291	$(TARGET_LIBGCC) \
292	-Wl,--end-group \
293	$(TARGET_CRTEND_O)
294endef
295