blob: f9c351e4625c3d3776572f9e2c560cf98ae8f7d4 [file] [log] [blame]
Lai Wei-Chih4c1d6fa2013-12-03 16:42:58 +08001# Copyright (C) 2009 The Android Open Source Project
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14#
15
16# this file is used to prepare the NDK to build with the arm clang-3.4
17# toolchain any number of source files
18#
19# its purpose is to define (or re-define) templates used to build
20# various sources into target object files, libraries or executables.
21#
22# Note that this file may end up being parsed several times in future
23# revisions of the NDK.
24#
25
26#
27# Override the toolchain prefix
28#
29
30LLVM_VERSION := 3.4
31LLVM_NAME := llvm-$(LLVM_VERSION)
32LLVM_TOOLCHAIN_ROOT := $(NDK_ROOT)/toolchains/$(LLVM_NAME)
33LLVM_TOOLCHAIN_PREBUILT_ROOT := $(call host-prebuilt-tag,$(LLVM_TOOLCHAIN_ROOT))
34LLVM_TOOLCHAIN_PREFIX := $(LLVM_TOOLCHAIN_PREBUILT_ROOT)/bin/
35
36TOOLCHAIN_VERSION := 4.8
37TOOLCHAIN_NAME := arm-linux-androideabi-$(TOOLCHAIN_VERSION)
38TOOLCHAIN_ROOT := $(NDK_ROOT)/toolchains/$(TOOLCHAIN_NAME)
39TOOLCHAIN_PREBUILT_ROOT := $(call host-prebuilt-tag,$(TOOLCHAIN_ROOT))
40TOOLCHAIN_PREFIX := $(TOOLCHAIN_PREBUILT_ROOT)/bin/arm-linux-androideabi-
41
42TARGET_CC := $(LLVM_TOOLCHAIN_PREFIX)clang$(HOST_EXEEXT)
43TARGET_CXX := $(LLVM_TOOLCHAIN_PREFIX)clang++$(HOST_EXEEXT)
44
45#
46# CFLAGS and LDFLAGS
47#
48
49TARGET_CFLAGS := \
50 -gcc-toolchain $(call host-path,$(TOOLCHAIN_PREBUILT_ROOT)) \
51 -fpic \
52 -ffunction-sections \
53 -funwind-tables \
54 -fstack-protector \
55 -no-canonical-prefixes
56
57TARGET_LDFLAGS += \
58 -gcc-toolchain $(call host-path,$(TOOLCHAIN_PREBUILT_ROOT)) \
59 -no-canonical-prefixes
60
61TARGET_C_INCLUDES := \
62 $(SYSROOT_INC)/usr/include
63
64ifneq ($(filter %armeabi-v7a,$(TARGET_ARCH_ABI)),)
65 LLVM_TRIPLE := armv7-none-linux-androideabi
66
67 TARGET_CFLAGS += -target $(LLVM_TRIPLE) \
68 -march=armv7-a \
69 -mfloat-abi=softfp \
70 -mfpu=vfpv3-d16
71
72 TARGET_LDFLAGS += -target $(LLVM_TRIPLE) \
73 -Wl,--fix-cortex-a8
74else
Andrew Hsieh748416e2014-01-22 18:21:18 -080075ifneq ($(filter %armeabi-v7a-hard,$(TARGET_ARCH_ABI)),)
76 LLVM_TRIPLE := armv7-none-linux-androideabi
77
78 TARGET_CFLAGS += -target $(LLVM_TRIPLE) \
79 -march=armv7-a \
80 -mfpu=vfpv3-d16 \
81 -mhard-float \
82 -D_NDK_MATH_NO_SOFTFP=1
83
84 TARGET_LDFLAGS += -target $(LLVM_TRIPLE) \
85 -Wl,--fix-cortex-a8 \
86 -Wl,--no-warn-mismatch \
87 -lm_hard
88else
Lai Wei-Chih4c1d6fa2013-12-03 16:42:58 +080089 LLVM_TRIPLE := armv5te-none-linux-androideabi
90
91 TARGET_CFLAGS += -target $(LLVM_TRIPLE) \
92 -march=armv5te \
93 -mtune=xscale \
94 -msoft-float
95
96 TARGET_LDFLAGS += -target $(LLVM_TRIPLE)
97endif
Andrew Hsieh748416e2014-01-22 18:21:18 -080098endif
Lai Wei-Chih4c1d6fa2013-12-03 16:42:58 +080099
100TARGET_CFLAGS.neon := -mfpu=neon
101
102TARGET_arm_release_CFLAGS := -O2 \
103 -g \
104 -DNDEBUG \
105 -fomit-frame-pointer \
106 -fstrict-aliasing
107
108TARGET_thumb_release_CFLAGS := -mthumb \
109 -Os \
110 -g \
111 -DNDEBUG \
112 -fomit-frame-pointer \
113 -fno-strict-aliasing
114
115# When building for debug, compile everything as arm.
116TARGET_arm_debug_CFLAGS := $(TARGET_arm_release_CFLAGS) \
117 -O0 \
118 -UNDEBUG \
119 -fno-omit-frame-pointer \
120 -fno-strict-aliasing
121
122TARGET_thumb_debug_CFLAGS := $(TARGET_thumb_release_CFLAGS) \
123 -O0 \
124 -UNDEBUG \
125 -marm \
126 -fno-omit-frame-pointer
127
128# This function will be called to determine the target CFLAGS used to build
129# a C or Assembler source file, based on its tags.
130#
131TARGET-process-src-files-tags = \
132$(eval __arm_sources := $(call get-src-files-with-tag,arm)) \
133$(eval __thumb_sources := $(call get-src-files-without-tag,arm)) \
134$(eval __debug_sources := $(call get-src-files-with-tag,debug)) \
135$(eval __release_sources := $(call get-src-files-without-tag,debug)) \
136$(call set-src-files-target-cflags, \
137 $(call set_intersection,$(__arm_sources),$(__debug_sources)), \
138 $(TARGET_arm_debug_CFLAGS)) \
139$(call set-src-files-target-cflags,\
140 $(call set_intersection,$(__arm_sources),$(__release_sources)),\
141 $(TARGET_arm_release_CFLAGS)) \
142$(call set-src-files-target-cflags,\
143 $(call set_intersection,$(__arm_sources),$(__debug_sources)),\
144 $(TARGET_arm_debug_CFLAGS)) \
145$(call set-src-files-target-cflags,\
146 $(call set_intersection,$(__thumb_sources),$(__release_sources)),\
147 $(TARGET_thumb_release_CFLAGS)) \
148$(call set-src-files-target-cflags,\
149 $(call set_intersection,$(__thumb_sources),$(__debug_sources)),\
150 $(TARGET_thumb_debug_CFLAGS)) \
151$(call add-src-files-target-cflags,\
152 $(call get-src-files-with-tag,neon),\
153 $(TARGET_CFLAGS.neon)) \
154$(call set-src-files-text,$(__arm_sources),arm) \
155$(call set-src-files-text,$(__thumb_sources),thumb)