14c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih# Copyright (C) 2009 The Android Open Source Project
24c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih#
34c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih# Licensed under the Apache License, Version 2.0 (the "License");
44c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih# you may not use this file except in compliance with the License.
54c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih# You may obtain a copy of the License at
64c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih#
74c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih#      http://www.apache.org/licenses/LICENSE-2.0
84c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih#
94c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih# Unless required by applicable law or agreed to in writing, software
104c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih# distributed under the License is distributed on an "AS IS" BASIS,
114c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
124c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih# See the License for the specific language governing permissions and
134c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih# limitations under the License.
144c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih#
154c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih
164c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih# this file is used to prepare the NDK to build with the arm clang-3.4
174c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih# toolchain any number of source files
184c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih#
194c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih# its purpose is to define (or re-define) templates used to build
204c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih# various sources into target object files, libraries or executables.
214c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih#
224c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih# Note that this file may end up being parsed several times in future
234c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih# revisions of the NDK.
244c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih#
254c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih
264c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih#
274c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih# Override the toolchain prefix
284c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih#
294c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih
304c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-ChihLLVM_VERSION := 3.4
314c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-ChihLLVM_NAME := llvm-$(LLVM_VERSION)
324c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-ChihLLVM_TOOLCHAIN_ROOT := $(NDK_ROOT)/toolchains/$(LLVM_NAME)
334c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-ChihLLVM_TOOLCHAIN_PREBUILT_ROOT := $(call host-prebuilt-tag,$(LLVM_TOOLCHAIN_ROOT))
344c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-ChihLLVM_TOOLCHAIN_PREFIX := $(LLVM_TOOLCHAIN_PREBUILT_ROOT)/bin/
354c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih
364c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-ChihTOOLCHAIN_VERSION := 4.8
374c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-ChihTOOLCHAIN_NAME := arm-linux-androideabi-$(TOOLCHAIN_VERSION)
384c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-ChihTOOLCHAIN_ROOT := $(NDK_ROOT)/toolchains/$(TOOLCHAIN_NAME)
394c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-ChihTOOLCHAIN_PREBUILT_ROOT := $(call host-prebuilt-tag,$(TOOLCHAIN_ROOT))
404c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-ChihTOOLCHAIN_PREFIX := $(TOOLCHAIN_PREBUILT_ROOT)/bin/arm-linux-androideabi-
414c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih
424c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-ChihTARGET_CC := $(LLVM_TOOLCHAIN_PREFIX)clang$(HOST_EXEEXT)
434c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-ChihTARGET_CXX := $(LLVM_TOOLCHAIN_PREFIX)clang++$(HOST_EXEEXT)
444c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih
454c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih#
464c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih# CFLAGS and LDFLAGS
474c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih#
484c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih
494c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-ChihTARGET_CFLAGS := \
504c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih    -gcc-toolchain $(call host-path,$(TOOLCHAIN_PREBUILT_ROOT)) \
514c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih    -fpic \
524c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih    -ffunction-sections \
534c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih    -funwind-tables \
544c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih    -fstack-protector \
554c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih    -no-canonical-prefixes
564c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih
574c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-ChihTARGET_LDFLAGS += \
584c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih    -gcc-toolchain $(call host-path,$(TOOLCHAIN_PREBUILT_ROOT)) \
594c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih    -no-canonical-prefixes
604c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih
614c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-ChihTARGET_C_INCLUDES := \
624c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih    $(SYSROOT_INC)/usr/include
634c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih
644c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chihifneq ($(filter %armeabi-v7a,$(TARGET_ARCH_ABI)),)
654c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih    LLVM_TRIPLE := armv7-none-linux-androideabi
664c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih
674c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih    TARGET_CFLAGS += -target $(LLVM_TRIPLE) \
684c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih                     -march=armv7-a \
694c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih                     -mfloat-abi=softfp \
704c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih                     -mfpu=vfpv3-d16
714c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih
724c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih    TARGET_LDFLAGS += -target $(LLVM_TRIPLE) \
734c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih                      -Wl,--fix-cortex-a8
744c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chihelse
75748416e5a7654ce6cfce9f680cf4e7a9728bd6beAndrew Hsiehifneq ($(filter %armeabi-v7a-hard,$(TARGET_ARCH_ABI)),)
76748416e5a7654ce6cfce9f680cf4e7a9728bd6beAndrew Hsieh    LLVM_TRIPLE := armv7-none-linux-androideabi
77748416e5a7654ce6cfce9f680cf4e7a9728bd6beAndrew Hsieh
78748416e5a7654ce6cfce9f680cf4e7a9728bd6beAndrew Hsieh    TARGET_CFLAGS += -target $(LLVM_TRIPLE) \
79748416e5a7654ce6cfce9f680cf4e7a9728bd6beAndrew Hsieh                     -march=armv7-a \
80748416e5a7654ce6cfce9f680cf4e7a9728bd6beAndrew Hsieh                     -mfpu=vfpv3-d16 \
81748416e5a7654ce6cfce9f680cf4e7a9728bd6beAndrew Hsieh                     -mhard-float \
82748416e5a7654ce6cfce9f680cf4e7a9728bd6beAndrew Hsieh                     -D_NDK_MATH_NO_SOFTFP=1
83748416e5a7654ce6cfce9f680cf4e7a9728bd6beAndrew Hsieh
84748416e5a7654ce6cfce9f680cf4e7a9728bd6beAndrew Hsieh    TARGET_LDFLAGS += -target $(LLVM_TRIPLE) \
85748416e5a7654ce6cfce9f680cf4e7a9728bd6beAndrew Hsieh                      -Wl,--fix-cortex-a8 \
86748416e5a7654ce6cfce9f680cf4e7a9728bd6beAndrew Hsieh                      -Wl,--no-warn-mismatch \
87748416e5a7654ce6cfce9f680cf4e7a9728bd6beAndrew Hsieh                      -lm_hard
88748416e5a7654ce6cfce9f680cf4e7a9728bd6beAndrew Hsiehelse
894c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih    LLVM_TRIPLE := armv5te-none-linux-androideabi
904c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih
914c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih    TARGET_CFLAGS += -target $(LLVM_TRIPLE) \
924c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih                     -march=armv5te \
934c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih                     -mtune=xscale \
944c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih                     -msoft-float
954c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih
964c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih    TARGET_LDFLAGS += -target $(LLVM_TRIPLE)
974c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chihendif
98748416e5a7654ce6cfce9f680cf4e7a9728bd6beAndrew Hsiehendif
994c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih
1004c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-ChihTARGET_CFLAGS.neon := -mfpu=neon
1014c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih
1024c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-ChihTARGET_arm_release_CFLAGS :=  -O2 \
1034c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih                              -g \
1044c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih                              -DNDEBUG \
1054c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih                              -fomit-frame-pointer \
1064c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih                              -fstrict-aliasing
1074c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih
1084c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-ChihTARGET_thumb_release_CFLAGS := -mthumb \
1094c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih                               -Os \
1104c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih                               -g \
1114c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih                               -DNDEBUG \
1124c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih                               -fomit-frame-pointer \
1134c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih                               -fno-strict-aliasing
1144c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih
1154c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih# When building for debug, compile everything as arm.
1164c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-ChihTARGET_arm_debug_CFLAGS := $(TARGET_arm_release_CFLAGS) \
1174c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih                           -O0 \
1184c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih                           -UNDEBUG \
1194c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih                           -fno-omit-frame-pointer \
1204c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih                           -fno-strict-aliasing
1214c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih
1224c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-ChihTARGET_thumb_debug_CFLAGS := $(TARGET_thumb_release_CFLAGS) \
1234c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih                             -O0 \
1244c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih                             -UNDEBUG \
1254c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih                             -marm \
1264c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih                             -fno-omit-frame-pointer
1274c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih
1284c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih# This function will be called to determine the target CFLAGS used to build
1294c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih# a C or Assembler source file, based on its tags.
1304c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih#
1314c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-ChihTARGET-process-src-files-tags = \
1324c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih$(eval __arm_sources := $(call get-src-files-with-tag,arm)) \
1334c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih$(eval __thumb_sources := $(call get-src-files-without-tag,arm)) \
1344c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih$(eval __debug_sources := $(call get-src-files-with-tag,debug)) \
1354c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih$(eval __release_sources := $(call get-src-files-without-tag,debug)) \
1364c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih$(call set-src-files-target-cflags, \
1374c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih    $(call set_intersection,$(__arm_sources),$(__debug_sources)), \
1384c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih    $(TARGET_arm_debug_CFLAGS)) \
1394c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih$(call set-src-files-target-cflags,\
1404c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih    $(call set_intersection,$(__arm_sources),$(__release_sources)),\
1414c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih    $(TARGET_arm_release_CFLAGS)) \
1424c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih$(call set-src-files-target-cflags,\
1434c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih    $(call set_intersection,$(__arm_sources),$(__debug_sources)),\
1444c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih    $(TARGET_arm_debug_CFLAGS)) \
1454c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih$(call set-src-files-target-cflags,\
1464c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih    $(call set_intersection,$(__thumb_sources),$(__release_sources)),\
1474c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih    $(TARGET_thumb_release_CFLAGS)) \
1484c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih$(call set-src-files-target-cflags,\
1494c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih    $(call set_intersection,$(__thumb_sources),$(__debug_sources)),\
1504c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih    $(TARGET_thumb_debug_CFLAGS)) \
1514c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih$(call add-src-files-target-cflags,\
1524c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih    $(call get-src-files-with-tag,neon),\
1534c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih    $(TARGET_CFLAGS.neon)) \
1544c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih$(call set-src-files-text,$(__arm_sources),arm) \
1554c1d6fa3fcd4bd014cbaf1ecee21c0f0cb559c32Lai Wei-Chih$(call set-src-files-text,$(__thumb_sources),thumb)
156