1555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew Hsieh# Copyright (C) 2009 The Android Open Source Project
2555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew Hsieh#
3555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew Hsieh# Licensed under the Apache License, Version 2.0 (the "License");
4555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew Hsieh# you may not use this file except in compliance with the License.
5555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew Hsieh# You may obtain a copy of the License at
6555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew Hsieh#
7555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew Hsieh#      http://www.apache.org/licenses/LICENSE-2.0
8555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew Hsieh#
9555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew Hsieh# Unless required by applicable law or agreed to in writing, software
10555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew Hsieh# distributed under the License is distributed on an "AS IS" BASIS,
11555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew Hsieh# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew Hsieh# See the License for the specific language governing permissions and
13555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew Hsieh# limitations under the License.
14555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew Hsieh#
15555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew Hsieh
16555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew Hsieh# this file is used to prepare the NDK to build with the arm gcc-4.8
17555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew Hsieh# toolchain any number of source files
18555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew Hsieh#
19555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew Hsieh# its purpose is to define (or re-define) templates used to build
20555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew Hsieh# various sources into target object files, libraries or executables.
21555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew Hsieh#
22555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew Hsieh# Note that this file may end up being parsed several times in future
23555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew Hsieh# revisions of the NDK.
24555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew Hsieh#
25555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew Hsieh
26555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew HsiehTARGET_CFLAGS := \
27555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew Hsieh    -fpic \
28555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew Hsieh    -ffunction-sections \
29555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew Hsieh    -funwind-tables \
30555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew Hsieh    -fstack-protector \
31555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew Hsieh    -no-canonical-prefixes
32555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew Hsieh
33555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew HsiehTARGET_LDFLAGS := -no-canonical-prefixes
34555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew Hsieh
35555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew HsiehTARGET_C_INCLUDES := \
36555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew Hsieh    $(SYSROOT_INC)/usr/include
37555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew Hsieh
38748416e5a7654ce6cfce9f680cf4e7a9728bd6beAndrew Hsiehifneq ($(filter $(TARGET_ARCH_ABI), armeabi-v7a armeabi-v7a-hard),)
39555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew Hsieh    TARGET_CFLAGS += -march=armv7-a \
40555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew Hsieh                     -mfpu=vfpv3-d16
41555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew Hsieh    TARGET_LDFLAGS += -march=armv7-a \
42555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew Hsieh                     -Wl,--fix-cortex-a8
43748416e5a7654ce6cfce9f680cf4e7a9728bd6beAndrew Hsiehifeq ($(TARGET_ARCH_ABI),armeabi-v7a)
44748416e5a7654ce6cfce9f680cf4e7a9728bd6beAndrew Hsieh    TARGET_CFLAGS += -mfloat-abi=softfp
45748416e5a7654ce6cfce9f680cf4e7a9728bd6beAndrew Hsiehelse
46748416e5a7654ce6cfce9f680cf4e7a9728bd6beAndrew Hsieh    TARGET_CFLAGS += -mhard-float \
47748416e5a7654ce6cfce9f680cf4e7a9728bd6beAndrew Hsieh                     -D_NDK_MATH_NO_SOFTFP=1
48748416e5a7654ce6cfce9f680cf4e7a9728bd6beAndrew Hsieh    TARGET_LDFLAGS += -Wl,--no-warn-mismatch \
49748416e5a7654ce6cfce9f680cf4e7a9728bd6beAndrew Hsieh                     -lm_hard
50748416e5a7654ce6cfce9f680cf4e7a9728bd6beAndrew Hsiehendif
51748416e5a7654ce6cfce9f680cf4e7a9728bd6beAndrew Hsieh
52555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew Hsiehelse
53555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew Hsieh    TARGET_CFLAGS += -march=armv5te \
54555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew Hsieh                            -mtune=xscale \
55555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew Hsieh                            -msoft-float
56555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew Hsiehendif
57555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew Hsieh
58555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew HsiehTARGET_CFLAGS.neon := -mfpu=neon
59555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew Hsieh
60555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew HsiehTARGET_arm_release_CFLAGS :=  -O2 \
61555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew Hsieh                              -g \
62555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew Hsieh                              -DNDEBUG \
63555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew Hsieh                              -fomit-frame-pointer \
64555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew Hsieh                              -fstrict-aliasing    \
65555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew Hsieh                              -funswitch-loops     \
66555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew Hsieh                              -finline-limit=300
67555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew Hsieh
68555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew HsiehTARGET_thumb_release_CFLAGS := -mthumb \
69555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew Hsieh                               -Os \
70555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew Hsieh                               -g \
71555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew Hsieh                               -DNDEBUG \
72555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew Hsieh                               -fomit-frame-pointer \
73555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew Hsieh                               -fno-strict-aliasing \
74555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew Hsieh                               -finline-limit=64
75555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew Hsieh
76555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew Hsieh# When building for debug, compile everything as arm.
77555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew HsiehTARGET_arm_debug_CFLAGS := $(TARGET_arm_release_CFLAGS) \
78555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew Hsieh                           -O0 \
79555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew Hsieh                           -UNDEBUG \
80555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew Hsieh                           -fno-omit-frame-pointer \
81555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew Hsieh                           -fno-strict-aliasing
82555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew Hsieh
83555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew HsiehTARGET_thumb_debug_CFLAGS := $(TARGET_thumb_release_CFLAGS) \
84555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew Hsieh                             -O0 \
85555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew Hsieh                             -UNDEBUG \
86555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew Hsieh                             -marm \
87555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew Hsieh                             -fno-omit-frame-pointer
88555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew Hsieh
89555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew Hsieh# This function will be called to determine the target CFLAGS used to build
90555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew Hsieh# a C or Assembler source file, based on its tags.
91555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew Hsieh#
92555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew HsiehTARGET-process-src-files-tags = \
93555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew Hsieh$(eval __arm_sources := $(call get-src-files-with-tag,arm)) \
94555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew Hsieh$(eval __thumb_sources := $(call get-src-files-without-tag,arm)) \
95555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew Hsieh$(eval __debug_sources := $(call get-src-files-with-tag,debug)) \
96555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew Hsieh$(eval __release_sources := $(call get-src-files-without-tag,debug)) \
97555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew Hsieh$(call set-src-files-target-cflags, \
98555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew Hsieh    $(call set_intersection,$(__arm_sources),$(__debug_sources)), \
99555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew Hsieh    $(TARGET_arm_debug_CFLAGS)) \
100555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew Hsieh$(call set-src-files-target-cflags,\
101555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew Hsieh    $(call set_intersection,$(__arm_sources),$(__release_sources)),\
102555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew Hsieh    $(TARGET_arm_release_CFLAGS)) \
103555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew Hsieh$(call set-src-files-target-cflags,\
104555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew Hsieh    $(call set_intersection,$(__arm_sources),$(__debug_sources)),\
105555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew Hsieh    $(TARGET_arm_debug_CFLAGS)) \
106555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew Hsieh$(call set-src-files-target-cflags,\
107555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew Hsieh    $(call set_intersection,$(__thumb_sources),$(__release_sources)),\
108555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew Hsieh    $(TARGET_thumb_release_CFLAGS)) \
109555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew Hsieh$(call set-src-files-target-cflags,\
110555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew Hsieh    $(call set_intersection,$(__thumb_sources),$(__debug_sources)),\
111555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew Hsieh    $(TARGET_thumb_debug_CFLAGS)) \
112555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew Hsieh$(call add-src-files-target-cflags,\
113555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew Hsieh    $(call get-src-files-with-tag,neon),\
114555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew Hsieh    $(TARGET_CFLAGS.neon)) \
1152f84ee41d7f2388e65aa829f93165e1ae461c873David 'Digit' Turner$(call set-src-files-text,$(__arm_sources),arm) \
116555abe49d62a14f3c741e44d9122d7e6430fdc8aAndrew Hsieh$(call set-src-files-text,$(__thumb_sources),thumb)
117