1# Copyright (C) 2009 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 16# this file is included repeatedly from build/core/setup-abi.mk and is used 17# to setup the target toolchain for a given platform/abi combination. 18# 19 20$(call assert-defined,TARGET_PLATFORM TARGET_ARCH TARGET_ARCH_ABI) 21$(call assert-defined,NDK_APPS NDK_APP_STL) 22 23LLVM_VERSION_LIST := 2.6 2.7 2.8 2.9 3.0 3.1 3.2 24 25# Check that we have a toolchain that supports the current ABI. 26# NOTE: If NDK_TOOLCHAIN is defined, we're going to use it. 27# 28ifndef NDK_TOOLCHAIN 29 TARGET_TOOLCHAIN_LIST := $(strip $(sort $(NDK_ABI.$(TARGET_ARCH_ABI).toolchains))) 30 31 # Filter out the Clang toolchain, so that we can keep GCC as the default 32 # toolchain. 33 $(foreach _ver,$(LLVM_VERSION_LIST), \ 34 $(eval TARGET_TOOLCHAIN_LIST := \ 35 $(filter-out %-clang$(_ver),$(TARGET_TOOLCHAIN_LIST)))) 36 # Filter out 4.7 which is considered experimental at this moment 37 TARGET_TOOLCHAIN_LIST := $(filter-out %4.7,$(TARGET_TOOLCHAIN_LIST)) 38 39 ifndef TARGET_TOOLCHAIN_LIST 40 $(call __ndk_info,There is no toolchain that supports the $(TARGET_ARCH_ABI) ABI.) 41 $(call __ndk_info,Please modify the APP_ABI definition in $(NDK_APP_APPLICATION_MK) to use) 42 $(call __ndk_info,a set of the following values: $(NDK_ALL_ABIS)) 43 $(call __ndk_error,Aborting) 44 endif 45 # Select the last toolchain from the sorted list. 46 # For now, this is enough to select armeabi-4.6 by default for ARM 47 TARGET_TOOLCHAIN := $(lastword $(TARGET_TOOLCHAIN_LIST)) 48 49 # If NDK_TOOLCHAIN_VERSION is defined, we replace the toolchain version 50 # suffix with it. 51 # 52 ifdef NDK_TOOLCHAIN_VERSION 53 # Replace "clang" with the most recent verion 54 ifeq ($(NDK_TOOLCHAIN_VERSION),clang) 55 override NDK_TOOLCHAIN_VERSION := clang$(lastword $(LLVM_VERSION_LIST)) 56 endif 57 # We assume the toolchain name uses dashes (-) as separators and doesn't 58 # contain any space. The following is a bit subtle, but essentially 59 # does the following: 60 # 61 # 1/ Use 'subst' to convert dashes into spaces, this generates a list 62 # 2/ Use 'chop' to remove the last element of the list 63 # 3/ Use 'subst' again to convert the spaces back into dashes 64 # 65 # So it TARGET_TOOLCHAIN is 'foo-bar-zoo-xxx', then 66 # TARGET_TOOLCHAIN_BASE will be 'foo-bar-zoo' 67 # 68 TARGET_TOOLCHAIN_BASE := $(subst $(space),-,$(call chop,$(subst -,$(space),$(TARGET_TOOLCHAIN)))) 69 # if TARGET_TOOLCHAIN_BASE is llvm, remove clang from NDK_TOOLCHAIN_VERSION 70 VERSION := $(NDK_TOOLCHAIN_VERSION) 71 ifeq ($(TARGET_TOOLCHAIN_BASE),llvm) 72 VERSION := $(subst clang,,$(NDK_TOOLCHAIN_VERSION)) 73 endif 74 TARGET_TOOLCHAIN := $(TARGET_TOOLCHAIN_BASE)-$(VERSION) 75 $(call ndk_log,Using target toolchain '$(TARGET_TOOLCHAIN)' for '$(TARGET_ARCH_ABI)' ABI (through NDK_TOOLCHAIN_VERSION)) 76 else 77 $(call ndk_log,Using target toolchain '$(TARGET_TOOLCHAIN)' for '$(TARGET_ARCH_ABI)' ABI) 78 endif 79else # NDK_TOOLCHAIN is not empty 80 TARGET_TOOLCHAIN_LIST := $(strip $(filter $(NDK_TOOLCHAIN),$(NDK_ABI.$(TARGET_ARCH_ABI).toolchains))) 81 ifndef TARGET_TOOLCHAIN_LIST 82 $(call __ndk_info,The selected toolchain ($(NDK_TOOLCHAIN)) does not support the $(TARGET_ARCH_ABI) ABI.) 83 $(call __ndk_info,Please modify the APP_ABI definition in $(NDK_APP_APPLICATION_MK) to use) 84 $(call __ndk_info,a set of the following values: $(NDK_TOOLCHAIN.$(NDK_TOOLCHAIN).abis)) 85 $(call __ndk_info,Or change your NDK_TOOLCHAIN definition.) 86 $(call __ndk_error,Aborting) 87 endif 88 TARGET_TOOLCHAIN := $(NDK_TOOLCHAIN) 89endif # NDK_TOOLCHAIN is not empty 90 91TARGET_ABI := $(TARGET_PLATFORM)-$(TARGET_ARCH_ABI) 92 93# setup sysroot variable. 94# SYSROOT_INC points to a directory that contains all public header 95# files for a given platform, and 96# SYSROOT_LIB points to libraries and object files used for linking 97# the generated target files properly. 98# 99SYSROOT_INC := $(NDK_PLATFORMS_ROOT)/$(TARGET_PLATFORM)/arch-$(TARGET_ARCH) 100SYSROOT_LINK := $(SYSROOT_INC) 101 102TARGET_PREBUILT_SHARED_LIBRARIES := 103 104# Define default values for TOOLCHAIN_NAME, this can be overriden in 105# the setup file. 106TOOLCHAIN_NAME := $(TARGET_TOOLCHAIN) 107TOOLCHAIN_VERSION := $(call last,$(subst -,$(space),$(TARGET_TOOLCHAIN))) 108 109# Define the root path of the toolchain in the NDK tree. 110TOOLCHAIN_ROOT := $(NDK_ROOT)/toolchains/$(TOOLCHAIN_NAME) 111 112# Define the root path where toolchain prebuilts are stored 113TOOLCHAIN_PREBUILT_ROOT := $(call host-prebuilt-tag,$(TOOLCHAIN_ROOT)) 114 115# Do the same for TOOLCHAIN_PREFIX. Note that we must chop the version 116# number from the toolchain name, e.g. arm-eabi-4.4.0 -> path/bin/arm-eabi- 117# to do that, we split at dashes, remove the last element, then merge the 118# result. Finally, add the complete path prefix. 119# 120TOOLCHAIN_PREFIX := $(call merge,-,$(call chop,$(call split,-,$(TOOLCHAIN_NAME))))- 121TOOLCHAIN_PREFIX := $(TOOLCHAIN_PREBUILT_ROOT)/bin/$(TOOLCHAIN_PREFIX) 122 123# We expect the gdbserver binary for this toolchain to be located at its root. 124TARGET_GDBSERVER := $(NDK_ROOT)/prebuilt/android-$(TARGET_ARCH)/gdbserver/gdbserver 125 126# compute NDK_APP_DST_DIR as the destination directory for the generated files 127NDK_APP_DST_DIR := $(NDK_APP_PROJECT_PATH)/libs/$(TARGET_ARCH_ABI) 128 129# Default build commands, can be overriden by the toolchain's setup script 130include $(BUILD_SYSTEM)/default-build-commands.mk 131 132# now call the toolchain-specific setup script 133include $(NDK_TOOLCHAIN.$(TARGET_TOOLCHAIN).setup) 134 135clean-installed-binaries:: 136 137# Ensure that for debuggable applications, gdbserver will be copied to 138# the proper location 139 140NDK_APP_GDBSERVER := $(NDK_APP_DST_DIR)/gdbserver 141NDK_APP_GDBSETUP := $(NDK_APP_DST_DIR)/gdb.setup 142 143ifeq ($(NDK_APP_DEBUGGABLE),true) 144ifeq ($(TARGET_SONAME_EXTENSION),.so) 145 146installed_modules: $(NDK_APP_GDBSERVER) 147 148$(NDK_APP_GDBSERVER): PRIVATE_NAME := $(TOOLCHAIN_NAME) 149$(NDK_APP_GDBSERVER): PRIVATE_SRC := $(TARGET_GDBSERVER) 150$(NDK_APP_GDBSERVER): PRIVATE_DST := $(NDK_APP_GDBSERVER) 151 152$(call generate-file-dir,$(NDK_APP_GDBSERVER)) 153 154$(NDK_APP_GDBSERVER): clean-installed-binaries 155 @ $(HOST_ECHO) "Gdbserver : [$(PRIVATE_NAME)] $(call pretty-dir,$(PRIVATE_DST))" 156 $(hide) $(call host-install,$(PRIVATE_SRC),$(PRIVATE_DST)) 157 158installed_modules: $(NDK_APP_GDBSETUP) 159 160$(NDK_APP_GDBSETUP): PRIVATE_DST := $(NDK_APP_GDBSETUP) 161$(NDK_APP_GDBSETUP): PRIVATE_SOLIB_PATH := $(TARGET_OUT) 162$(NDK_APP_GDBSETUP): PRIVATE_SRC_DIRS := $(SYSROOT_INC)/usr/include 163 164$(NDK_APP_GDBSETUP): 165 @ $(HOST_ECHO) "Gdbsetup : $(call pretty-dir,$(PRIVATE_DST))" 166 $(hide) $(HOST_ECHO) "set solib-search-path $(call host-path,$(PRIVATE_SOLIB_PATH))" > $(PRIVATE_DST) 167 $(hide) $(HOST_ECHO) "directory $(call host-path,$(call remove-duplicates,$(PRIVATE_SRC_DIRS)))" >> $(PRIVATE_DST) 168 169$(call generate-file-dir,$(NDK_APP_GDBSETUP)) 170 171# This prevents parallel execution to clear gdb.setup after it has been written to 172$(NDK_APP_GDBSETUP): clean-installed-binaries 173endif 174endif 175 176# free the dictionary of LOCAL_MODULE definitions 177$(call modules-clear) 178 179$(call ndk-stl-select,$(NDK_APP_STL)) 180 181# now parse the Android.mk for the application, this records all 182# module declarations, but does not populate the dependency graph yet. 183include $(NDK_APP_BUILD_SCRIPT) 184 185$(call ndk-stl-add-dependencies,$(NDK_APP_STL)) 186 187# recompute all dependencies between modules 188$(call modules-compute-dependencies) 189 190# for debugging purpose 191ifdef NDK_DEBUG_MODULES 192$(call modules-dump-database) 193endif 194 195# now, really build the modules, the second pass allows one to deal 196# with exported values 197$(foreach __pass2_module,$(__ndk_modules),\ 198 $(eval LOCAL_MODULE := $(__pass2_module))\ 199 $(eval include $(BUILD_SYSTEM)/build-binary.mk)\ 200) 201 202# Now compute the closure of all module dependencies. 203# 204# If APP_MODULES is not defined in the Application.mk, we 205# will build all modules that were listed from the top-level Android.mk 206# and the installable imported ones they depend on 207# 208ifeq ($(strip $(NDK_APP_MODULES)),) 209 WANTED_MODULES := $(call modules-get-all-installable,$(modules-get-top-list)) 210else 211 WANTED_MODULES := $(call module-get-all-dependencies,$(NDK_APP_MODULES)) 212endif 213 214WANTED_INSTALLED_MODULES += $(call map,module-get-installed,$(WANTED_MODULES)) 215