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