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