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