• 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 toolchain any
17# 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_TOOLCHAIN_PREBUILT_ROOT := $(call get-toolchain-root,llvm)
31LLVM_TOOLCHAIN_PREFIX := $(LLVM_TOOLCHAIN_PREBUILT_ROOT)/bin/
32
33TOOLCHAIN_NAME := arm-linux-androideabi
34BINUTILS_ROOT := $(call get-binutils-root,$(NDK_ROOT),$(TOOLCHAIN_NAME))
35TOOLCHAIN_ROOT := $(call get-toolchain-root,$(TOOLCHAIN_NAME)-4.9)
36TOOLCHAIN_PREFIX := $(TOOLCHAIN_ROOT)/bin/$(TOOLCHAIN_NAME)-
37
38TARGET_CC := $(LLVM_TOOLCHAIN_PREFIX)clang$(HOST_EXEEXT)
39TARGET_CXX := $(LLVM_TOOLCHAIN_PREFIX)clang++$(HOST_EXEEXT)
40
41#
42# CFLAGS and LDFLAGS
43#
44
45TARGET_CFLAGS := \
46    -gcc-toolchain $(call host-path,$(TOOLCHAIN_ROOT)) \
47    -fpic \
48    -ffunction-sections \
49    -funwind-tables \
50    -fstack-protector-strong \
51    -Wno-invalid-command-line-argument \
52    -Wno-unused-command-line-argument \
53    -no-canonical-prefixes
54
55# Disable integrated-as for better compatibility
56TARGET_CFLAGS += \
57    -fno-integrated-as
58
59TARGET_LDFLAGS += \
60    -gcc-toolchain $(call host-path,$(TOOLCHAIN_ROOT)) \
61    -no-canonical-prefixes
62
63ifneq ($(filter %armeabi-v7a,$(TARGET_ARCH_ABI)),)
64    LLVM_TRIPLE := armv7-none-linux-androideabi
65
66    TARGET_CFLAGS += -target $(LLVM_TRIPLE) \
67                     -march=armv7-a \
68                     -mfloat-abi=softfp \
69                     -mfpu=vfpv3-d16
70
71    TARGET_LDFLAGS += -target $(LLVM_TRIPLE) \
72                      -Wl,--fix-cortex-a8
73
74    GCCLIB_SUBDIR := armv7-a
75else
76ifneq ($(filter %armeabi-v7a-hard,$(TARGET_ARCH_ABI)),)
77    LLVM_TRIPLE := armv7-none-linux-androideabi
78
79    TARGET_CFLAGS += -target $(LLVM_TRIPLE) \
80                     -march=armv7-a \
81                     -mfpu=vfpv3-d16 \
82                     -mhard-float \
83                     -D_NDK_MATH_NO_SOFTFP=1
84
85    TARGET_LDFLAGS += -target $(LLVM_TRIPLE) \
86                      -Wl,--fix-cortex-a8 \
87                      -Wl,--no-warn-mismatch \
88                      -lm_hard
89
90    GCCLIB_SUBDIR := armv7-a
91else
92    LLVM_TRIPLE := armv5te-none-linux-androideabi
93
94    TARGET_CFLAGS += -target $(LLVM_TRIPLE) \
95                     -march=armv5te \
96                     -mtune=xscale \
97                     -msoft-float
98
99    TARGET_LDFLAGS += -target $(LLVM_TRIPLE)
100
101    GCCLIB_SUBDIR :=
102endif
103endif
104
105GCCLIB_ROOT := $(call get-gcclibs-path,$(NDK_ROOT),$(TOOLCHAIN_NAME))
106
107TARGET_CFLAGS.neon := -mfpu=neon
108
109TARGET_arm_release_CFLAGS :=  -O2 \
110                              -g \
111                              -DNDEBUG \
112                              -fomit-frame-pointer \
113                              -fstrict-aliasing
114
115TARGET_thumb_release_CFLAGS := -mthumb \
116                               -Os \
117                               -g \
118                               -DNDEBUG \
119                               -fomit-frame-pointer \
120                               -fno-strict-aliasing
121
122# When building for debug, compile everything as arm.
123TARGET_arm_debug_CFLAGS := $(TARGET_arm_release_CFLAGS) \
124                           -O0 \
125                           -UNDEBUG \
126                           -fno-omit-frame-pointer \
127                           -fno-strict-aliasing
128
129TARGET_thumb_debug_CFLAGS := $(TARGET_thumb_release_CFLAGS) \
130                             -O0 \
131                             -UNDEBUG \
132                             -marm \
133                             -fno-omit-frame-pointer
134
135# This function will be called to determine the target CFLAGS used to build
136# a C or Assembler source file, based on its tags.
137#
138TARGET-process-src-files-tags = \
139$(eval __arm_sources := $(call get-src-files-with-tag,arm)) \
140$(eval __thumb_sources := $(call get-src-files-without-tag,arm)) \
141$(eval __debug_sources := $(call get-src-files-with-tag,debug)) \
142$(eval __release_sources := $(call get-src-files-without-tag,debug)) \
143$(call set-src-files-target-cflags, \
144    $(call set_intersection,$(__arm_sources),$(__debug_sources)), \
145    $(TARGET_arm_debug_CFLAGS)) \
146$(call set-src-files-target-cflags,\
147    $(call set_intersection,$(__arm_sources),$(__release_sources)),\
148    $(TARGET_arm_release_CFLAGS)) \
149$(call set-src-files-target-cflags,\
150    $(call set_intersection,$(__arm_sources),$(__debug_sources)),\
151    $(TARGET_arm_debug_CFLAGS)) \
152$(call set-src-files-target-cflags,\
153    $(call set_intersection,$(__thumb_sources),$(__release_sources)),\
154    $(TARGET_thumb_release_CFLAGS)) \
155$(call set-src-files-target-cflags,\
156    $(call set_intersection,$(__thumb_sources),$(__debug_sources)),\
157    $(TARGET_thumb_debug_CFLAGS)) \
158$(call add-src-files-target-cflags,\
159    $(call get-src-files-with-tag,neon),\
160    $(TARGET_CFLAGS.neon)) \
161$(call set-src-files-text,$(__arm_sources),arm) \
162$(call set-src-files-text,$(__thumb_sources),thumb)
163