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 15 TOOLCHAIN_NAME := clang-3.4 16 TOOLCHAIN_PREFIX := $(TOOLCHAIN_PREBUILT_ROOT)/bin/ 17 ifneq ($(UNKNOWN_ABI_64),) 18 LLVM_TRIPLE := le64-none-ndk 19 else 20 LLVM_TRIPLE := le32-none-ndk 21 endif 22 23 # For sources/cxx-stl/gnu-libstdc++/$(TOOLCHAIN_VERSION)/libs/*/libsupc++.a 24 ifneq ($(UNKNOWN_ABI_64),) 25 TOOLCHAIN_VERSION := 4.9 26 else 27 TOOLCHAIN_VERSION := 4.8 28 endif 29 30 TARGET_CC := $(TOOLCHAIN_PREFIX)clang$(HOST_EXEEXT) 31 TARGET_CXX := $(TOOLCHAIN_PREFIX)clang++$(HOST_EXEEXT) 32 TARGET_LD := $(TOOLCHAIN_PREFIX)clang++$(HOST_EXEEXT) 33 TARGET_AR := $(TOOLCHAIN_PREFIX)llvm-ar$(HOST_EXEEXT) 34 ifeq ($(APP_OPTIM),debug) 35 TARGET_STRIP := \# dont-strip-for-debugging-bitcode 36 else 37 TARGET_STRIP := $(TOOLCHAIN_PREFIX)$(LLVM_TRIPLE)-strip$(HOST_EXEEXT) 38 endif 39 40 # Compiler runtime is determined in bc2native 41 TARGET_LIBGCC := 42 43 # Override the ar flags, llvm-ar does not support D option 44 TARGET_ARFLAGS := crs 45 46 # Only use integrated binary if existed. Otherwise, use python version 47 ifeq (,$(wildcard $(TOOLCHAIN_PREBUILT_ROOT)/bin/ndk-bc2native$(HOST_EXEEXT))) 48 BC2NATIVE := $(HOST_PYTHON) $(TOOLCHAIN_PREBUILT_ROOT)/bin/ndk-bc2native.py 49 else 50 BC2NATIVE := $(TOOLCHAIN_PREBUILT_ROOT)/bin/ndk-bc2native$(HOST_EXEEXT) 51 endif 52 53 TARGET_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 65 TARGET_NO_EXECUTE_CFLAGS := 66 67 # Add and LDFLAGS for the target here 68 TARGET_LDFLAGS += \ 69 -target $(LLVM_TRIPLE) \ 70 -no-canonical-prefixes 71 72 ifeq ($(APP_OPTIM),debug) 73 TARGET_LDFLAGS += -Wl,-O0 -Wl,--disable-opt 74 else 75 TARGET_LDFLAGS += -Wl,-O2 76 endif 77 78 TARGET_C_INCLUDES := \ 79 $(SYSROOT_INC)/usr/include 80 81 TARGET_release_CFLAGS := -O2 \ 82 -g \ 83 -DNDEBUG \ 84 -fomit-frame-pointer \ 85 -fstrict-aliasing 86 87 TARGET_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 # 96 TARGET-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 103 ifeq ($(strip $(filter-out $(NDK_KNOWN_ABIS),$(TARGET_ARCH_ABI))),) 104 105 define 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))) 120 endef 121 122 define 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)) 137 endef 138 139 endif 140