Home | History | Annotate | Download | only in llvm-3.3
      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.3
     16 TOOLCHAIN_PREFIX := $(TOOLCHAIN_PREBUILT_ROOT)/bin/
     17 LLVM_TRIPLE := le32-none-ndk
     18 
     19 # For sources/cxx-stl/gnu-libstdc++/$(TOOLCHAIN_VERSION)/libs/*/libsupc++.a
     20 TOOLCHAIN_VERSION := 4.8
     21 
     22 TARGET_CC := $(TOOLCHAIN_PREFIX)clang$(HOST_EXEEXT)
     23 TARGET_CXX := $(TOOLCHAIN_PREFIX)clang++$(HOST_EXEEXT)
     24 TARGET_LD := $(TOOLCHAIN_PREFIX)clang++$(HOST_EXEEXT)
     25 TARGET_AR := $(TOOLCHAIN_PREFIX)llvm-ar$(HOST_EXEEXT)
     26 ifeq ($(APP_OPTIM),debug)
     27   TARGET_STRIP := \# dont-strip-for-debugging-bitcode
     28 else
     29   TARGET_STRIP := $(TOOLCHAIN_PREFIX)$(LLVM_TRIPLE)-strip$(HOST_EXEEXT)
     30 endif
     31 
     32 # Compiler runtime is determined in bc2native
     33 TARGET_LIBGCC :=
     34 
     35 # Override the ar flags, llvm-ar does not support D option
     36 TARGET_ARFLAGS := crs
     37 
     38 # Only use integrated binary if existed. Otherwise, use python version
     39 ifeq (,$(wildcard $(TOOLCHAIN_PREBUILT_ROOT)/bin/ndk-bc2native$(HOST_EXEEXT)))
     40 BC2NATIVE := $(HOST_PYTHON) $(TOOLCHAIN_PREBUILT_ROOT)/bin/ndk-bc2native.py
     41 else
     42 BC2NATIVE := $(TOOLCHAIN_PREBUILT_ROOT)/bin/ndk-bc2native$(HOST_EXEEXT)
     43 endif
     44 
     45 TARGET_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
     57 TARGET_NO_EXECUTE_CFLAGS :=
     58 
     59 # Add and LDFLAGS for the target here
     60 TARGET_LDFLAGS += \
     61     -target $(LLVM_TRIPLE) \
     62     -emit-llvm \
     63     -no-canonical-prefixes
     64 
     65 ifeq ($(APP_OPTIM),debug)
     66   TARGET_LDFLAGS += -Wl,-O0 -Wl,--disable-opt
     67 else
     68   TARGET_LDFLAGS += -Wl,-O2
     69 endif
     70 
     71 TARGET_C_INCLUDES := \
     72     $(SYSROOT_INC)/usr/include
     73 
     74 TARGET_release_CFLAGS := -O2 \
     75                          -g \
     76                          -DNDEBUG \
     77                          -fomit-frame-pointer \
     78                          -fstrict-aliasing
     79 
     80 TARGET_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 #
     89 TARGET-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 
     96 ifeq ($(strip $(filter-out $(NDK_KNOWN_ABIS),$(TARGET_ARCH_ABI))),)
     97 
     98 define 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)))
    113 endef
    114 
    115 define 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))
    130 endef
    131 
    132 endif
    133