TARGET_linux-mips.mk revision 06afc1c5ab9e07094832e790249586a7619d9539
1#
2# Copyright (C) 2010 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 MIPS.
18# Included by combo/select.mk
19
20# You can set TARGET_ARCH_VARIANT to use an arch version other
21# than mips32r2-fp. 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 := mips32r2-fp
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 MIPS architecture variant: $(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_TOOLCHAIN_ROOT := prebuilts/gcc/$(HOST_PREBUILT_TAG)/mips/mipsel-linux-android-4.6
47TARGET_TOOLS_PREFIX := $(TARGET_TOOLCHAIN_ROOT)/bin/mipsel-linux-android-
48endif
49
50# Only define these if there's actually a gcc in there.
51# The gcc toolchain does not exists for windows/cygwin. In this case, do not reference it.
52ifneq ($(wildcard $(TARGET_TOOLS_PREFIX)gcc$(HOST_EXECUTABLE_SUFFIX)),)
53    TARGET_CC := $(TARGET_TOOLS_PREFIX)gcc$(HOST_EXECUTABLE_SUFFIX)
54    TARGET_CXX := $(TARGET_TOOLS_PREFIX)g++$(HOST_EXECUTABLE_SUFFIX)
55    TARGET_AR := $(TARGET_TOOLS_PREFIX)ar$(HOST_EXECUTABLE_SUFFIX)
56    TARGET_OBJCOPY := $(TARGET_TOOLS_PREFIX)objcopy$(HOST_EXECUTABLE_SUFFIX)
57    TARGET_LD := $(TARGET_TOOLS_PREFIX)ld$(HOST_EXECUTABLE_SUFFIX)
58    TARGET_STRIP := $(TARGET_TOOLS_PREFIX)strip$(HOST_EXECUTABLE_SUFFIX)
59    ifeq ($(TARGET_BUILD_VARIANT),user)
60        TARGET_STRIP_COMMAND = $(TARGET_STRIP) --strip-all $< -o $@
61    else
62        TARGET_STRIP_COMMAND = $(TARGET_STRIP) --strip-all $< -o $@ && \
63	    $(TARGET_OBJCOPY) --add-gnu-debuglink=$< $@
64    endif
65endif
66
67TARGET_NO_UNDEFINED_LDFLAGS := -Wl,--no-undefined
68
69TARGET_mips_CFLAGS :=	-O2 \
70			-fomit-frame-pointer \
71			-fno-strict-aliasing    \
72			-funswitch-loops
73
74# Set FORCE_MIPS_DEBUGGING to "true" in your buildspec.mk
75# or in your environment to gdb debugging easier.
76# Don't forget to do a clean build.
77ifeq ($(FORCE_MIPS_DEBUGGING),true)
78  TARGET_mips_CFLAGS += -fno-omit-frame-pointer
79endif
80
81android_config_h := $(call select-android-config-h,linux-mips)
82arch_include_dir := $(dir $(android_config_h))
83
84TARGET_GLOBAL_CFLAGS += \
85			$(TARGET_mips_CFLAGS) \
86			-Ulinux -U__unix -U__unix__ -Umips \
87			-fpic \
88			-ffunction-sections \
89			-fdata-sections \
90			-funwind-tables \
91			-Werror=format-security \
92			$(arch_variant_cflags) \
93			-include $(android_config_h) \
94			-I $(arch_include_dir)
95
96# This warning causes dalvik not to build with gcc 4.6.x and -Werror.
97# We cannot turn it off blindly since the option is not available
98# in gcc-4.4.x.
99ifneq ($(filter 4.6.%, $(shell $(TARGET_CC) --version)),)
100TARGET_GLOBAL_CFLAGS += -Wno-unused-but-set-variable \
101                        -fno-strict-volatile-bitfields
102endif
103
104# This is to avoid the dreaded warning compiler message:
105#   note: the mangling of 'va_list' has changed in GCC 4.4
106#
107# The fact that the mangling changed does not affect the NDK ABI
108# very fortunately (since none of the exposed APIs used va_list
109# in their exported C++ functions). Also, GCC 4.5 has already
110# removed the warning from the compiler.
111#
112TARGET_GLOBAL_CFLAGS += -Wno-psabi
113
114ifneq ($(ARCH_MIPS_PAGE_SHIFT),)
115TARGET_GLOBAL_CFLAGS += -DPAGE_SHIFT=$(ARCH_MIPS_PAGE_SHIFT)
116endif
117
118TARGET_GLOBAL_LDFLAGS += \
119			$(arch_variant_ldflags)
120
121TARGET_GLOBAL_CPPFLAGS += -fvisibility-inlines-hidden \
122				-fno-use-cxa-atexit
123
124# More flags/options can be added here
125TARGET_RELEASE_CFLAGS := \
126			-DNDEBUG \
127			-g \
128			-Wstrict-aliasing=2 \
129			-fgcse-after-reload \
130			-frerun-cse-after-loop \
131			-frename-registers
132
133libc_root := bionic/libc
134libm_root := bionic/libm
135libstdc++_root := bionic/libstdc++
136libthread_db_root := bionic/libthread_db
137
138
139## on some hosts, the target cross-compiler is not available so do not run this command
140ifneq ($(wildcard $(TARGET_CC)),)
141# We compile with the global cflags to ensure that
142# any flags which affect libgcc are correctly taken
143# into account.
144TARGET_LIBGCC := \
145  $(shell $(TARGET_CC) $(TARGET_GLOBAL_CFLAGS) -print-file-name=libgcc.a)
146LIBGCC_EH := $(shell $(TARGET_CC) $(TARGET_GLOBAL_CFLAGS) -print-file-name=libgcc_eh.a)
147ifneq ($(LIBGCC_EH),libgcc_eh.a)
148  TARGET_LIBGCC += $(LIBGCC_EH)
149endif
150endif
151
152# Define FDO (Feedback Directed Optimization) options.
153
154TARGET_FDO_CFLAGS:=
155TARGET_FDO_LIB:=
156
157target_libgcov := $(shell $(TARGET_CC) $(TARGET_GLOBAL_CFLAGS) \
158        --print-file-name=libgcov.a)
159ifneq ($(strip $(BUILD_FDO_INSTRUMENT)),)
160  # Set BUILD_FDO_INSTRUMENT=true to turn on FDO instrumentation.
161  # The profile will be generated on /data/local/tmp/profile on the device.
162  TARGET_FDO_CFLAGS := -fprofile-generate=/data/local/tmp/profile -DANDROID_FDO
163  TARGET_FDO_LIB := $(target_libgcov)
164else
165  # If BUILD_FDO_INSTRUMENT is turned off, then consider doing the FDO optimizations.
166  # Set TARGET_FDO_PROFILE_PATH to set a custom profile directory for your build.
167  ifeq ($(strip $(TARGET_FDO_PROFILE_PATH)),)
168    TARGET_FDO_PROFILE_PATH := fdo/profiles/$(TARGET_ARCH)/$(TARGET_ARCH_VARIANT)
169  else
170    ifeq ($(strip $(wildcard $(TARGET_FDO_PROFILE_PATH))),)
171      $(warning Custom TARGET_FDO_PROFILE_PATH supplied, but directory does not exist. Turn off FDO.)
172    endif
173  endif
174
175  # If the FDO profile directory can't be found, then FDO is off.
176  ifneq ($(strip $(wildcard $(TARGET_FDO_PROFILE_PATH))),)
177    TARGET_FDO_CFLAGS := -fprofile-use=$(TARGET_FDO_PROFILE_PATH) -DANDROID_FDO
178    TARGET_FDO_LIB := $(target_libgcov)
179  endif
180endif
181
182
183# unless CUSTOM_KERNEL_HEADERS is defined, we're going to use
184# symlinks located in out/ to point to the appropriate kernel
185# headers. see 'config/kernel_headers.make' for more details
186#
187ifneq ($(CUSTOM_KERNEL_HEADERS),)
188    KERNEL_HEADERS_COMMON := $(CUSTOM_KERNEL_HEADERS)
189    KERNEL_HEADERS_ARCH   := $(CUSTOM_KERNEL_HEADERS)
190else
191    KERNEL_HEADERS_COMMON := $(libc_root)/kernel/common
192    KERNEL_HEADERS_ARCH   := $(libc_root)/kernel/arch-$(TARGET_ARCH)
193endif
194KERNEL_HEADERS := $(KERNEL_HEADERS_COMMON) $(KERNEL_HEADERS_ARCH)
195
196TARGET_C_INCLUDES := \
197	$(libc_root)/arch-mips/include \
198	$(libc_root)/include \
199	$(libstdc++_root)/include \
200	$(KERNEL_HEADERS) \
201	$(libm_root)/include \
202	$(libm_root)/include/mips \
203	$(libthread_db_root)/include
204
205TARGET_CRTBEGIN_STATIC_O := $(TARGET_OUT_STATIC_LIBRARIES)/crtbegin_static.o
206TARGET_CRTBEGIN_DYNAMIC_O := $(TARGET_OUT_STATIC_LIBRARIES)/crtbegin_dynamic.o
207TARGET_CRTEND_O := $(TARGET_OUT_STATIC_LIBRARIES)/crtend_android.o
208
209TARGET_CRTBEGIN_SO_O := $(TARGET_OUT_STATIC_LIBRARIES)/crtbegin_so.o
210TARGET_CRTEND_SO_O := $(TARGET_OUT_STATIC_LIBRARIES)/crtend_so.o
211
212TARGET_STRIP_MODULE:=true
213
214TARGET_DEFAULT_SYSTEM_SHARED_LIBRARIES := libc libstdc++ libm
215
216TARGET_CUSTOM_LD_COMMAND := true
217
218# Enable the Dalvik JIT compiler if not already specified.
219ifeq ($(strip $(WITH_JIT)),)
220    WITH_JIT := true
221endif
222
223define transform-o-to-shared-lib-inner
224$(hide) $(PRIVATE_CXX) \
225	-nostdlib -Wl,-soname,$(notdir $@) \
226	-Wl,--gc-sections \
227	-shared -Bsymbolic \
228	$(PRIVATE_TARGET_GLOBAL_LD_DIRS) \
229	$(if $(filter true,$(PRIVATE_NO_CRT)),,$(PRIVATE_TARGET_CRTBEGIN_SO_O)) \
230	$(PRIVATE_ALL_OBJECTS) \
231	-Wl,--whole-archive \
232	$(call normalize-target-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
233	-Wl,--no-whole-archive \
234	$(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--start-group) \
235	$(call normalize-target-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
236	$(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--end-group) \
237	$(call normalize-target-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
238	-o $@ \
239	$(PRIVATE_TARGET_GLOBAL_LDFLAGS) \
240	$(PRIVATE_LDFLAGS) \
241	$(PRIVATE_TARGET_FDO_LIB) \
242	$(PRIVATE_TARGET_LIBGCC) \
243	$(if $(filter true,$(PRIVATE_NO_CRT)),,$(PRIVATE_TARGET_CRTEND_SO_O))
244endef
245
246define transform-o-to-executable-inner
247$(hide) $(PRIVATE_CXX) -nostdlib -Bdynamic \
248	-Wl,-dynamic-linker,/system/bin/linker \
249	-Wl,--gc-sections \
250	-Wl,-z,nocopyreloc \
251	-o $@ \
252	$(TARGET_GLOBAL_LD_DIRS) \
253	-Wl,-rpath-link=$(TARGET_OUT_INTERMEDIATE_LIBRARIES) \
254	$(call normalize-target-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
255	$(if $(filter true,$(PRIVATE_NO_CRT)),,$(TARGET_CRTBEGIN_DYNAMIC_O)) \
256	$(PRIVATE_ALL_OBJECTS) \
257	$(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--start-group) \
258	$(call normalize-target-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
259	$(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--end-group) \
260	$(TARGET_GLOBAL_LDFLAGS) \
261	$(PRIVATE_LDFLAGS) \
262	$(TARGET_FDO_LIB) \
263	$(TARGET_LIBGCC) \
264	$(if $(filter true,$(PRIVATE_NO_CRT)),,$(TARGET_CRTEND_O))
265endef
266
267define transform-o-to-static-executable-inner
268$(hide) $(PRIVATE_CXX) -nostdlib -Bstatic \
269	-Wl,--gc-sections \
270	-o $@ \
271	$(TARGET_GLOBAL_LD_DIRS) \
272	$(if $(filter true,$(PRIVATE_NO_CRT)),,$(TARGET_CRTBEGIN_STATIC_O)) \
273	$(TARGET_GLOBAL_LDFLAGS) \
274	$(PRIVATE_LDFLAGS) \
275	$(PRIVATE_ALL_OBJECTS) \
276	$(call normalize-target-libraries,$(filter-out %libc_nomalloc.a,$(filter-out %libc.a,$(PRIVATE_ALL_STATIC_LIBRARIES)))) \
277	-Wl,--start-group \
278	$(call normalize-target-libraries,$(filter %libc.a,$(PRIVATE_ALL_STATIC_LIBRARIES))) \
279	$(call normalize-target-libraries,$(filter %libc_nomalloc.a,$(PRIVATE_ALL_STATIC_LIBRARIES))) \
280	$(TARGET_FDO_LIB) \
281	$(TARGET_LIBGCC) \
282	-Wl,--end-group \
283	$(if $(filter true,$(PRIVATE_NO_CRT)),,$(TARGET_CRTEND_O))
284endef
285