• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (C) 2014 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.5
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.5
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-strong \
55    -Wno-invalid-command-line-argument \
56    -Wno-unused-command-line-argument \
57    -no-canonical-prefixes
58
59# Disable integrated-as for better compatibility
60TARGET_CFLAGS += \
61    -fno-integrated-as
62
63TARGET_LDFLAGS += \
64    -gcc-toolchain $(call host-path,$(TOOLCHAIN_PREBUILT_ROOT)) \
65    -no-canonical-prefixes
66
67TARGET_C_INCLUDES := \
68    $(SYSROOT_INC)/usr/include
69
70ifneq ($(filter %armeabi-v7a,$(TARGET_ARCH_ABI)),)
71    LLVM_TRIPLE := armv7-none-linux-androideabi
72
73    TARGET_CFLAGS += -target $(LLVM_TRIPLE) \
74                     -march=armv7-a \
75                     -mfloat-abi=softfp \
76                     -mfpu=vfpv3-d16
77
78    TARGET_LDFLAGS += -target $(LLVM_TRIPLE) \
79                      -Wl,--fix-cortex-a8
80else
81ifneq ($(filter %armeabi-v7a-hard,$(TARGET_ARCH_ABI)),)
82    LLVM_TRIPLE := armv7-none-linux-androideabi
83
84    TARGET_CFLAGS += -target $(LLVM_TRIPLE) \
85                     -march=armv7-a \
86                     -mfpu=vfpv3-d16 \
87                     -mhard-float \
88                     -D_NDK_MATH_NO_SOFTFP=1
89
90    TARGET_LDFLAGS += -target $(LLVM_TRIPLE) \
91                      -Wl,--fix-cortex-a8 \
92                      -Wl,--no-warn-mismatch \
93                      -lm_hard
94else
95    LLVM_TRIPLE := armv5te-none-linux-androideabi
96
97    TARGET_CFLAGS += -target $(LLVM_TRIPLE) \
98                     -march=armv5te \
99                     -mtune=xscale \
100                     -msoft-float
101
102    TARGET_LDFLAGS += -target $(LLVM_TRIPLE)
103endif
104endif
105
106TARGET_CFLAGS.neon := -mfpu=neon
107
108TARGET_arm_release_CFLAGS :=  -O2 \
109                              -g \
110                              -DNDEBUG \
111                              -fomit-frame-pointer \
112                              -fstrict-aliasing
113
114TARGET_thumb_release_CFLAGS := -mthumb \
115                               -Os \
116                               -g \
117                               -DNDEBUG \
118                               -fomit-frame-pointer \
119                               -fno-strict-aliasing
120
121# When building for debug, compile everything as arm.
122TARGET_arm_debug_CFLAGS := $(TARGET_arm_release_CFLAGS) \
123                           -O0 \
124                           -UNDEBUG \
125                           -fno-omit-frame-pointer \
126                           -fno-strict-aliasing
127
128TARGET_thumb_debug_CFLAGS := $(TARGET_thumb_release_CFLAGS) \
129                             -O0 \
130                             -UNDEBUG \
131                             -marm \
132                             -fno-omit-frame-pointer
133
134# This function will be called to determine the target CFLAGS used to build
135# a C or Assembler source file, based on its tags.
136#
137TARGET-process-src-files-tags = \
138$(eval __arm_sources := $(call get-src-files-with-tag,arm)) \
139$(eval __thumb_sources := $(call get-src-files-without-tag,arm)) \
140$(eval __debug_sources := $(call get-src-files-with-tag,debug)) \
141$(eval __release_sources := $(call get-src-files-without-tag,debug)) \
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,$(__arm_sources),$(__release_sources)),\
147    $(TARGET_arm_release_CFLAGS)) \
148$(call set-src-files-target-cflags,\
149    $(call set_intersection,$(__arm_sources),$(__debug_sources)),\
150    $(TARGET_arm_debug_CFLAGS)) \
151$(call set-src-files-target-cflags,\
152    $(call set_intersection,$(__thumb_sources),$(__release_sources)),\
153    $(TARGET_thumb_release_CFLAGS)) \
154$(call set-src-files-target-cflags,\
155    $(call set_intersection,$(__thumb_sources),$(__debug_sources)),\
156    $(TARGET_thumb_debug_CFLAGS)) \
157$(call add-src-files-target-cflags,\
158    $(call get-src-files-with-tag,neon),\
159    $(TARGET_CFLAGS.neon)) \
160$(call set-src-files-text,$(__arm_sources),arm) \
161$(call set-src-files-text,$(__thumb_sources),thumb)
162