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