blob: 1b078471577740fe35a69bef4fe0eb241b8fa69f [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
Ben Cheng4de6fa42014-04-10 22:46:26 -070037# Decouple NDK library selection with platform compiler version
38TARGET_NDK_GCC_VERSION := 4.8
39
Chris Dearman1efd9e42014-02-03 15:01:24 -080040ifeq ($(strip $(TARGET_GCC_VERSION_EXP)),)
41TARGET_GCC_VERSION := 4.8
42else
43TARGET_GCC_VERSION := $(TARGET_GCC_VERSION_EXP)
44endif
45
Chris Dearman1efd9e42014-02-03 15:01:24 -080046TARGET_ARCH_SPECIFIC_MAKEFILE := $(BUILD_COMBOS)/arch/$(TARGET_ARCH)/$(TARGET_ARCH_VARIANT).mk
47ifeq ($(strip $(wildcard $(TARGET_ARCH_SPECIFIC_MAKEFILE))),)
48$(error Unknown MIPS architecture variant: $(TARGET_ARCH_VARIANT))
49endif
50
Chris Dearman1efd9e42014-02-03 15:01:24 -080051include $(TARGET_ARCH_SPECIFIC_MAKEFILE)
52
53# You can set TARGET_TOOLS_PREFIX to get gcc from somewhere else
54ifeq ($(strip $(TARGET_TOOLS_PREFIX)),)
55TARGET_TOOLCHAIN_ROOT := prebuilts/gcc/$(HOST_PREBUILT_TAG)/mips/mips64el-linux-android-$(TARGET_GCC_VERSION)
56TARGET_TOOLS_PREFIX := $(TARGET_TOOLCHAIN_ROOT)/bin/mips64el-linux-android-
57endif
58
59TARGET_CC := $(TARGET_TOOLS_PREFIX)gcc$(HOST_EXECUTABLE_SUFFIX)
60TARGET_CXX := $(TARGET_TOOLS_PREFIX)g++$(HOST_EXECUTABLE_SUFFIX)
61TARGET_AR := $(TARGET_TOOLS_PREFIX)ar$(HOST_EXECUTABLE_SUFFIX)
62TARGET_OBJCOPY := $(TARGET_TOOLS_PREFIX)objcopy$(HOST_EXECUTABLE_SUFFIX)
63TARGET_LD := $(TARGET_TOOLS_PREFIX)ld$(HOST_EXECUTABLE_SUFFIX)
Christopher Ferrisa6e2f932014-03-18 14:50:09 -070064TARGET_READELF := $(TARGET_TOOLS_PREFIX)readelf$(HOST_EXECUTABLE_SUFFIX)
Chris Dearman1efd9e42014-02-03 15:01:24 -080065TARGET_STRIP := $(TARGET_TOOLS_PREFIX)strip$(HOST_EXECUTABLE_SUFFIX)
Chris Dearman1efd9e42014-02-03 15:01:24 -080066
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-mips64)
82
83TARGET_GLOBAL_CFLAGS += \
84 $(TARGET_mips_CFLAGS) \
Elliott Hughes1acd8b02014-04-23 23:24:36 -070085 -U__unix -U__unix__ -Umips \
Chris Dearman1efd9e42014-02-03 15:01:24 -080086 -fpic -fPIE\
87 -ffunction-sections \
88 -fdata-sections \
89 -funwind-tables \
90 -Wa,--noexecstack \
91 -Werror=format-security \
92 -D_FORTIFY_SOURCE=2 \
Andrew Hsieh48f239c2014-05-09 14:13:13 +080093 -no-canonical-prefixes \
94 -fno-canonical-system-headers \
Chris Dearman1efd9e42014-02-03 15:01:24 -080095 $(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++
143libthread_db_root := bionic/libthread_db
144
145
146## on some hosts, the target cross-compiler is not available so do not run this command
147ifneq ($(wildcard $(TARGET_CC)),)
148# We compile with the global cflags to ensure that
149# any flags which affect libgcc are correctly taken
150# into account.
151TARGET_LIBGCC := \
152 $(shell $(TARGET_CC) $(TARGET_GLOBAL_CFLAGS) -print-file-name=libgcc.a)
Andrew Hsieh4c952d72014-05-29 02:47:27 -0700153TARGET_LIBATOMIC := \
154 $(shell $(TARGET_CC) $(TARGET_GLOBAL_CFLAGS) -print-file-name=libatomic.a)
Chris Dearman1efd9e42014-02-03 15:01:24 -0800155LIBGCC_EH := $(shell $(TARGET_CC) $(TARGET_GLOBAL_CFLAGS) -print-file-name=libgcc_eh.a)
156ifneq ($(LIBGCC_EH),libgcc_eh.a)
157 TARGET_LIBGCC += $(LIBGCC_EH)
158endif
159target_libgcov := $(shell $(TARGET_CC) $(TARGET_GLOBAL_CFLAGS) \
160 --print-file-name=libgcov.a)
161endif
162
163# Define FDO (Feedback Directed Optimization) options.
164
165TARGET_FDO_CFLAGS:=
166TARGET_FDO_LIB:=
167
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
192KERNEL_HEADERS_COMMON := $(libc_root)/kernel/uapi
193KERNEL_HEADERS_ARCH := $(libc_root)/kernel/uapi/asm-mips
194# TODO: perhaps use $(libc_root)/kernel/uapi/asm-$(TARGET_ARCH) instead of asm-mips ?
195KERNEL_HEADERS := $(KERNEL_HEADERS_COMMON) $(KERNEL_HEADERS_ARCH)
196
197TARGET_C_INCLUDES := \
198 $(libc_root)/arch-mips64/include \
199 $(libc_root)/include \
200 $(libstdc++_root)/include \
201 $(KERNEL_HEADERS) \
202 $(libm_root)/include \
203 $(libm_root)/include/mips \
204 $(libthread_db_root)/include
205# TODO: perhaps use $(libm_root)/include/mips64 instead of mips ?
206
207TARGET_CRTBEGIN_STATIC_O := $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbegin_static.o
208TARGET_CRTBEGIN_DYNAMIC_O := $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbegin_dynamic.o
209TARGET_CRTEND_O := $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtend_android.o
210
211TARGET_CRTBEGIN_SO_O := $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbegin_so.o
212TARGET_CRTEND_SO_O := $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtend_so.o
213
214TARGET_STRIP_MODULE:=true
215
216TARGET_DEFAULT_SYSTEM_SHARED_LIBRARIES := libc libstdc++ libm
217
218TARGET_CUSTOM_LD_COMMAND := true
219
220define transform-o-to-shared-lib-inner
221$(hide) $(PRIVATE_CXX) \
222 -nostdlib -Wl,-soname,$(notdir $@) \
223 -Wl,--gc-sections \
Tim Murray0f9276d2014-05-29 15:10:44 -0700224 -shared \
Chris Dearman1efd9e42014-02-03 15:01:24 -0800225 $(PRIVATE_TARGET_GLOBAL_LD_DIRS) \
226 $(if $(filter true,$(PRIVATE_NO_CRT)),,$(PRIVATE_TARGET_CRTBEGIN_SO_O)) \
227 $(PRIVATE_ALL_OBJECTS) \
228 -Wl,--whole-archive \
229 $(call normalize-target-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
230 -Wl,--no-whole-archive \
231 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--start-group) \
232 $(call normalize-target-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
233 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--end-group) \
Ying Wangd90de322014-05-23 16:42:37 -0700234 $(if $(TARGET_BUILD_APPS),$(PRIVATE_TARGET_LIBGCC)) \
Chris Dearman1efd9e42014-02-03 15:01:24 -0800235 $(PRIVATE_TARGET_FDO_LIB) \
236 $(call normalize-target-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
237 -o $@ \
238 $(PRIVATE_TARGET_GLOBAL_LDFLAGS) \
239 $(PRIVATE_LDFLAGS) \
Andrew Hsieh4c952d72014-05-29 02:47:27 -0700240 $(PRIVATE_TARGET_LIBATOMIC) \
Ying Wangd90de322014-05-23 16:42:37 -0700241 $(if $(PRIVATE_LIBCXX),,$(PRIVATE_TARGET_LIBGCC)) \
Ying Wangde36cd72014-05-07 11:33:19 -0700242 $(if $(filter true,$(PRIVATE_NO_CRT)),,$(PRIVATE_TARGET_CRTEND_SO_O)) \
243 $(PRIVATE_LDLIBS)
Chris Dearman1efd9e42014-02-03 15:01:24 -0800244endef
245
246define transform-o-to-executable-inner
247$(hide) $(PRIVATE_CXX) -nostdlib -Bdynamic -fPIE -pie \
248 -Wl,-dynamic-linker,/system/bin/linker64 \
249 -Wl,--gc-sections \
250 -Wl,-z,nocopyreloc \
251 $(PRIVATE_TARGET_GLOBAL_LD_DIRS) \
Ying Wang9fb35262014-02-21 16:17:05 -0800252 -Wl,-rpath-link=$(PRIVATE_TARGET_OUT_INTERMEDIATE_LIBRARIES) \
Chris Dearman1efd9e42014-02-03 15:01:24 -0800253 $(if $(filter true,$(PRIVATE_NO_CRT)),,$(PRIVATE_TARGET_CRTBEGIN_DYNAMIC_O)) \
254 $(PRIVATE_ALL_OBJECTS) \
255 -Wl,--whole-archive \
256 $(call normalize-target-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
257 -Wl,--no-whole-archive \
258 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--start-group) \
259 $(call normalize-target-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
260 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--end-group) \
Ying Wangd90de322014-05-23 16:42:37 -0700261 $(if $(TARGET_BUILD_APPS),$(PRIVATE_TARGET_LIBGCC)) \
Chris Dearman1efd9e42014-02-03 15:01:24 -0800262 $(PRIVATE_TARGET_FDO_LIB) \
263 $(call normalize-target-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
264 -o $@ \
265 $(PRIVATE_TARGET_GLOBAL_LDFLAGS) \
266 $(PRIVATE_LDFLAGS) \
Andrew Hsieh4c952d72014-05-29 02:47:27 -0700267 $(PRIVATE_TARGET_LIBATOMIC) \
Ying Wangd90de322014-05-23 16:42:37 -0700268 $(if $(PRIVATE_LIBCXX),,$(PRIVATE_TARGET_LIBGCC)) \
Ying Wangde36cd72014-05-07 11:33:19 -0700269 $(if $(filter true,$(PRIVATE_NO_CRT)),,$(PRIVATE_TARGET_CRTEND_O)) \
270 $(PRIVATE_LDLIBS)
Chris Dearman1efd9e42014-02-03 15:01:24 -0800271endef
272
273define transform-o-to-static-executable-inner
274$(hide) $(PRIVATE_CXX) -nostdlib -Bstatic \
275 -Wl,--gc-sections \
276 -o $@ \
277 $(PRIVATE_TARGET_GLOBAL_LD_DIRS) \
278 $(if $(filter true,$(PRIVATE_NO_CRT)),,$(PRIVATE_TARGET_CRTBEGIN_STATIC_O)) \
279 $(PRIVATE_TARGET_GLOBAL_LDFLAGS) \
280 $(PRIVATE_LDFLAGS) \
281 $(PRIVATE_ALL_OBJECTS) \
282 -Wl,--whole-archive \
283 $(call normalize-target-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
284 -Wl,--no-whole-archive \
285 $(call normalize-target-libraries,$(filter-out %libc_nomalloc.a,$(filter-out %libc.a,$(PRIVATE_ALL_STATIC_LIBRARIES)))) \
286 -Wl,--start-group \
287 $(call normalize-target-libraries,$(filter %libc.a,$(PRIVATE_ALL_STATIC_LIBRARIES))) \
288 $(call normalize-target-libraries,$(filter %libc_nomalloc.a,$(PRIVATE_ALL_STATIC_LIBRARIES))) \
289 $(PRIVATE_TARGET_FDO_LIB) \
Andrew Hsieh4c952d72014-05-29 02:47:27 -0700290 $(PRIVATE_TARGET_LIBATOMIC) \
Ying Wangd90de322014-05-23 16:42:37 -0700291 $(if $(PRIVATE_LIBCXX),,$(PRIVATE_TARGET_LIBGCC)) \
Chris Dearman1efd9e42014-02-03 15:01:24 -0800292 -Wl,--end-group \
293 $(if $(filter true,$(PRIVATE_NO_CRT)),,$(PRIVATE_TARGET_CRTEND_O))
294endef