TARGET_linux-arm.mk revision 6d98f5f4d6a25b03c7322ed596ab377ef65cf1fd
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
137TARGET_RELEASE_CFLAGS := \
138			-DNDEBUG \
139			-g \
140			-Wstrict-aliasing=2 \
141			-finline-functions \
142			-fno-inline-functions-called-once \
143			-fgcse-after-reload \
144			-frerun-cse-after-loop \
145			-frename-registers
146
147libc_root := bionic/libc
148libm_root := bionic/libm
149libstdc++_root := bionic/libstdc++
150libthread_db_root := bionic/libthread_db
151
152
153## on some hosts, the target cross-compiler is not available so do not run this command
154ifneq ($(wildcard $(TARGET_CC)),)
155# We compile with the global cflags to ensure that
156# any flags which affect libgcc are correctly taken
157# into account.
158TARGET_LIBGCC := $(shell $(TARGET_CC) $(TARGET_GLOBAL_CFLAGS) -print-libgcc-file-name)
159endif
160
161# Define FDO (Feedback Directed Optimization) options.
162
163TARGET_FDO_CFLAGS:=
164TARGET_FDO_LIB:=
165
166target_libgcov := $(shell $(TARGET_CC) $(TARGET_GLOBAL_CFLAGS) \
167        --print-file-name=libgcov.a)
168ifneq ($(strip $(BUILD_FDO_INSTRUMENT)),)
169  # Set BUILD_FDO_INSTRUMENT=true to turn on FDO instrumentation.
170  # The profile will be generated on /data/local/tmp/profile on the device.
171  TARGET_FDO_CFLAGS := -fprofile-generate=/data/local/tmp/profile -DANDROID_FDO
172  TARGET_FDO_LIB := $(target_libgcov)
173else
174  # If BUILD_FDO_INSTRUMENT is turned off, then consider doing the FDO optimizations.
175  # Set TARGET_FDO_PROFILE_PATH to set a custom profile directory for your build.
176  ifeq ($(strip $(TARGET_FDO_PROFILE_PATH)),)
177    TARGET_FDO_PROFILE_PATH := fdo/profiles/$(TARGET_ARCH)/$(TARGET_ARCH_VARIANT)
178  else
179    ifeq ($(strip $(wildcard $(TARGET_FDO_PROFILE_PATH))),)
180      $(warning Custom TARGET_FDO_PROFILE_PATH supplied, but directory does not exist. Turn off FDO.)
181    endif
182  endif
183
184  # If the FDO profile directory can't be found, then FDO is off.
185  ifneq ($(strip $(wildcard $(TARGET_FDO_PROFILE_PATH))),)
186    TARGET_FDO_CFLAGS := -fprofile-use=$(TARGET_FDO_PROFILE_PATH) -DANDROID_FDO
187    TARGET_FDO_LIB := $(target_libgcov)
188  endif
189endif
190
191
192# unless CUSTOM_KERNEL_HEADERS is defined, we're going to use
193# symlinks located in out/ to point to the appropriate kernel
194# headers. see 'config/kernel_headers.make' for more details
195#
196ifneq ($(CUSTOM_KERNEL_HEADERS),)
197    KERNEL_HEADERS_COMMON := $(CUSTOM_KERNEL_HEADERS)
198    KERNEL_HEADERS_ARCH   := $(CUSTOM_KERNEL_HEADERS)
199else
200    KERNEL_HEADERS_COMMON := $(libc_root)/kernel/common
201    KERNEL_HEADERS_ARCH   := $(libc_root)/kernel/arch-$(TARGET_ARCH)
202endif
203KERNEL_HEADERS := $(KERNEL_HEADERS_COMMON) $(KERNEL_HEADERS_ARCH)
204
205TARGET_C_INCLUDES := \
206	$(libc_root)/arch-arm/include \
207	$(libc_root)/include \
208	$(libstdc++_root)/include \
209	$(KERNEL_HEADERS) \
210	$(libm_root)/include \
211	$(libm_root)/include/arm \
212	$(libthread_db_root)/include
213
214TARGET_CRTBEGIN_STATIC_O := $(TARGET_OUT_STATIC_LIBRARIES)/crtbegin_static.o
215TARGET_CRTBEGIN_DYNAMIC_O := $(TARGET_OUT_STATIC_LIBRARIES)/crtbegin_dynamic.o
216TARGET_CRTEND_O := $(TARGET_OUT_STATIC_LIBRARIES)/crtend_android.o
217
218TARGET_CRTBEGIN_SO_O := $(TARGET_OUT_STATIC_LIBRARIES)/crtbegin_so.o
219TARGET_CRTEND_SO_O := $(TARGET_OUT_STATIC_LIBRARIES)/crtend_so.o
220
221TARGET_STRIP_MODULE:=true
222
223TARGET_DEFAULT_SYSTEM_SHARED_LIBRARIES := libc libstdc++ libm
224
225TARGET_CUSTOM_LD_COMMAND := true
226
227# Enable the Dalvik JIT compiler if not already specified.
228ifeq ($(strip $(WITH_JIT)),)
229    WITH_JIT := true
230endif
231
232define transform-o-to-shared-lib-inner
233$(TARGET_CXX) \
234	-nostdlib -Wl,-soname,$(notdir $@) -Wl,-T,$(BUILD_SYSTEM)/armelf.xsc \
235	-Wl,--gc-sections \
236	-Wl,-shared,-Bsymbolic \
237	$(PRIVATE_TARGET_GLOBAL_LD_DIRS) \
238	$(PRIVATE_ALL_OBJECTS) \
239	$(PRIVATE_TARGET_CRTBEGIN_SO_O) \
240	-Wl,--whole-archive \
241	$(call normalize-host-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
242	-Wl,--no-whole-archive \
243	$(call normalize-target-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
244	$(call normalize-target-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
245	-o $@ \
246	$(PRIVATE_TARGET_GLOBAL_LDFLAGS) \
247	$(PRIVATE_LDFLAGS) \
248	$(PRIVATE_TARGET_FDO_LIB) \
249	$(PRIVATE_TARGET_LIBGCC) \
250	$(PRIVATE_TARGET_CRTEND_SO_O)
251endef
252
253define transform-o-to-executable-inner
254$(TARGET_CXX) -nostdlib -Bdynamic -Wl,-T,$(BUILD_SYSTEM)/armelf.x \
255	-Wl,-dynamic-linker,/system/bin/linker \
256    -Wl,--gc-sections \
257	-Wl,-z,nocopyreloc \
258	-o $@ \
259	$(TARGET_GLOBAL_LD_DIRS) \
260	-Wl,-rpath-link=$(TARGET_OUT_INTERMEDIATE_LIBRARIES) \
261	$(call normalize-target-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
262	$(TARGET_CRTBEGIN_DYNAMIC_O) \
263	$(PRIVATE_ALL_OBJECTS) \
264	$(call normalize-target-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
265	$(TARGET_GLOBAL_LDFLAGS) \
266	$(PRIVATE_LDFLAGS) \
267	$(TARGET_FDO_LIB) \
268	$(TARGET_LIBGCC) \
269	$(TARGET_CRTEND_O)
270endef
271
272define transform-o-to-static-executable-inner
273$(TARGET_CXX) -nostdlib -Bstatic -Wl,-T,$(BUILD_SYSTEM)/armelf.x \
274    -Wl,--gc-sections \
275	-o $@ \
276	$(TARGET_GLOBAL_LD_DIRS) \
277	$(TARGET_CRTBEGIN_STATIC_O) \
278	$(TARGET_GLOBAL_LDFLAGS) \
279	$(PRIVATE_LDFLAGS) \
280	$(PRIVATE_ALL_OBJECTS) \
281	$(call normalize-target-libraries,$(filter-out %libc_nomalloc.a,$(filter-out %libc.a,$(PRIVATE_ALL_STATIC_LIBRARIES)))) \
282	-Wl,--start-group \
283	$(call normalize-target-libraries,$(filter %libc.a,$(PRIVATE_ALL_STATIC_LIBRARIES))) \
284	$(call normalize-target-libraries,$(filter %libc_nomalloc.a,$(PRIVATE_ALL_STATIC_LIBRARIES))) \
285	$(TARGET_FDO_LIB) \
286	$(TARGET_LIBGCC) \
287	-Wl,--end-group \
288	$(TARGET_CRTEND_O)
289endef
290