1# Copyright (C) 2013 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
15TOOLCHAIN_NAME   := clang-3.4
16TOOLCHAIN_PREFIX := $(TOOLCHAIN_PREBUILT_ROOT)/bin/
17ifneq ($(UNKNOWN_ABI_64),)
18LLVM_TRIPLE := le64-none-ndk
19else
20LLVM_TRIPLE := le32-none-ndk
21endif
22
23# For sources/cxx-stl/gnu-libstdc++/$(TOOLCHAIN_VERSION)/libs/*/libsupc++.a
24ifneq ($(UNKNOWN_ABI_64),)
25TOOLCHAIN_VERSION := 4.9
26else
27TOOLCHAIN_VERSION := 4.8
28endif
29
30TARGET_CC := $(TOOLCHAIN_PREFIX)clang$(HOST_EXEEXT)
31TARGET_CXX := $(TOOLCHAIN_PREFIX)clang++$(HOST_EXEEXT)
32TARGET_LD := $(TOOLCHAIN_PREFIX)clang++$(HOST_EXEEXT)
33TARGET_AR := $(TOOLCHAIN_PREFIX)llvm-ar$(HOST_EXEEXT)
34ifeq ($(APP_OPTIM),debug)
35  TARGET_STRIP := \# dont-strip-for-debugging-bitcode
36else
37  TARGET_STRIP := $(TOOLCHAIN_PREFIX)$(LLVM_TRIPLE)-strip$(HOST_EXEEXT)
38endif
39
40# Compiler runtime is determined in bc2native
41TARGET_LIBGCC :=
42
43# Override the ar flags, llvm-ar does not support D option
44TARGET_ARFLAGS := crs
45
46# Only use integrated binary if existed. Otherwise, use python version
47ifeq (,$(wildcard $(TOOLCHAIN_PREBUILT_ROOT)/bin/ndk-bc2native$(HOST_EXEEXT)))
48BC2NATIVE := $(HOST_PYTHON) $(TOOLCHAIN_PREBUILT_ROOT)/bin/ndk-bc2native.py
49else
50BC2NATIVE := $(TOOLCHAIN_PREBUILT_ROOT)/bin/ndk-bc2native$(HOST_EXEEXT)
51endif
52
53TARGET_CFLAGS := \
54    -target $(LLVM_TRIPLE) \
55    -emit-llvm \
56    -ffunction-sections \
57    -funwind-tables \
58    -fPIC \
59    -no-canonical-prefixes
60# -nostdlibinc
61
62#TARGET_CXXFLAGS := $(TARGET_CFLAGS) -fno-exceptions -fno-rtti
63
64# reset backend flags
65TARGET_NO_EXECUTE_CFLAGS :=
66
67# Add and LDFLAGS for the target here
68TARGET_LDFLAGS += \
69    -target $(LLVM_TRIPLE) \
70    -no-canonical-prefixes
71
72ifeq ($(APP_OPTIM),debug)
73  TARGET_LDFLAGS += -Wl,-O0 -Wl,--disable-opt
74else
75  TARGET_LDFLAGS += -Wl,-O2
76endif
77
78TARGET_C_INCLUDES := \
79    $(SYSROOT_INC)/usr/include
80
81TARGET_release_CFLAGS := -O2 \
82                         -g \
83                         -DNDEBUG \
84                         -fomit-frame-pointer \
85                         -fstrict-aliasing
86
87TARGET_debug_CFLAGS := $(TARGET_release_CFLAGS) \
88                       -O0 \
89                       -UNDEBUG \
90                       -fno-omit-frame-pointer \
91                       -fno-strict-aliasing
92
93# This function will be called to determine the target CFLAGS used to build
94# a C or Assembler source file, based on its tags.
95#
96TARGET-process-src-files-tags = \
97$(eval __debug_sources := $(call get-src-files-with-tag,debug)) \
98$(eval __release_sources := $(call get-src-files-without-tag,debug)) \
99$(call set-src-files-target-cflags, $(__debug_sources), $(TARGET_debug_CFLAGS)) \
100$(call set-src-files-target-cflags, $(__release_sources),$(TARGET_release_CFLAGS)) \
101$(call set-src-files-text,$(LOCAL_SRC_FILES),bc) \
102
103ifeq ($(strip $(filter-out $(NDK_KNOWN_ABIS),$(TARGET_ARCH_ABI))),)
104
105define cmd-build-shared-library
106$(PRIVATE_CXX) \
107    -Wl,-soname,$(notdir $(LOCAL_BUILT_MODULE)) \
108    -shared \
109    --sysroot=$(call host-path,$(PRIVATE_SYSROOT_LINK)) \
110    $(PRIVATE_LINKER_OBJECTS_AND_LIBRARIES) \
111    $(PRIVATE_LDFLAGS) \
112    $(PRIVATE_LDLIBS) \
113    -o $(call host-path,$(LOCAL_BUILT_MODULE)) && \
114    $(call host-mv, $(call host-path,$(LOCAL_BUILT_MODULE)), $(call host-path,$(LOCAL_BUILT_MODULE)).bc) && \
115    $(BC2NATIVE) \
116    --ndk-dir=$(NDK_ROOT) \
117    --abi=$(TARGET_ARCH_ABI) \
118    --platform=$(TARGET_PLATFORM) \
119    --file $(call host-path, $(LOCAL_BUILT_MODULE)).bc $(patsubst %.bc,%.so,$(call host-path,$(LOCAL_BUILT_MODULE)))
120endef
121
122define cmd-build-executable
123$(PRIVATE_CXX) \
124    -Wl,--gc-sections \
125    -Wl,-z,nocopyreloc \
126    --sysroot=$(call host-path,$(PRIVATE_SYSROOT_LINK)) \
127    $(PRIVATE_LINKER_OBJECTS_AND_LIBRARIES) \
128    $(PRIVATE_LDFLAGS) \
129    $(PRIVATE_LDLIBS) \
130    -o $(call host-path,$(LOCAL_BUILT_MODULE)) && \
131    $(call host-mv, $(call host-path,$(LOCAL_BUILT_MODULE)), $(call host-path,$(LOCAL_BUILT_MODULE)).bc) && \
132    $(BC2NATIVE) \
133    --ndk-dir=$(NDK_ROOT) \
134    --abi=$(TARGET_ARCH_ABI) \
135    --platform=$(TARGET_PLATFORM) \
136    --file $(call host-path,$(LOCAL_BUILT_MODULE)).bc $(call host-path,$(LOCAL_BUILT_MODULE))
137endef
138
139endif
140