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 23# Check that we have a toolchain that supports the current ABI. 24# NOTE: If NDK_TOOLCHAIN is defined, we're going to use it. 25# 26ifndef NDK_TOOLCHAIN 27 TARGET_TOOLCHAIN_LIST := $(strip $(sort $(NDK_ABI.$(TARGET_ARCH_ABI).toolchains))) 28 ifndef TARGET_TOOLCHAIN_LIST 29 $(call __ndk_info,There is no toolchain that supports the $(TARGET_ARCH_ABI) ABI.) 30 $(call __ndk_info,Please modify the APP_ABI definition in $(NDK_APP_APPLICATION_MK) to use) 31 $(call __ndk_info,a set of the following values: $(NDK_ALL_ABIS)) 32 $(call __ndk_error,Aborting) 33 endif 34 # Select the last toolchain from the sorted list. 35 # For now, this is enough to select armeabi-4.4.0 by default for ARM 36 TARGET_TOOLCHAIN := $(lastword $(TARGET_TOOLCHAIN_LIST)) 37 $(call ndk_log,Using target toolchain '$(TARGET_TOOLCHAIN)' for '$(TARGET_ARCH_ABI)' ABI) 38else # NDK_TOOLCHAIN is not empty 39 TARGET_TOOLCHAIN_LIST := $(strip $(filter $(NDK_TOOLCHAIN),$(NDK_ABI.$(TARGET_ARCH_ABI).toolchains))) 40 ifndef TARGET_TOOLCHAIN_LIST 41 $(call __ndk_info,The selected toolchain ($(NDK_TOOLCHAIN)) does not support the $(TARGET_ARCH_ABI) ABI.) 42 $(call __ndk_info,Please modify the APP_ABI definition in $(NDK_APP_APPLICATION_MK) to use) 43 $(call __ndk_info,a set of the following values: $(NDK_TOOLCHAIN.$(NDK_TOOLCHAIN).abis)) 44 $(call __ndk_info,Or change your NDK_TOOLCHAIN definition.) 45 $(call __ndk_error,Aborting) 46 endif 47 TARGET_TOOLCHAIN := $(NDK_TOOLCHAIN) 48endif # NDK_TOOLCHAIN is not empty 49 50TARGET_ABI := $(TARGET_PLATFORM)-$(TARGET_ARCH_ABI) 51 52# setup sysroot-related variables. The SYSROOT point to a directory 53# that contains all public header files for a given platform, plus 54# some libraries and object files used for linking the generated 55# target files properly. 56# 57SYSROOT := $(NDK_PLATFORMS_ROOT)/$(TARGET_PLATFORM)/arch-$(TARGET_ARCH) 58 59TARGET_CRTBEGIN_STATIC_O := $(SYSROOT)/usr/lib/crtbegin_static.o 60TARGET_CRTBEGIN_DYNAMIC_O := $(SYSROOT)/usr/lib/crtbegin_dynamic.o 61TARGET_CRTEND_O := $(SYSROOT)/usr/lib/crtend_android.o 62 63# crtbegin_so.o and crtend_so.o are not available for all platforms, so 64# only define them if they are in the sysroot 65# 66TARGET_CRTBEGIN_SO_O := $(strip $(wildcard $(SYSROOT)/usr/lib/crtbegin_so.o)) 67TARGET_CRTEND_SO_O := $(strip $(wildcard $(SYSROOT)/usr/lib/crtend_so.o)) 68 69TARGET_PREBUILT_SHARED_LIBRARIES := 70 71# Define default values for TOOLCHAIN_NAME, this can be overriden in 72# the setup file. 73TOOLCHAIN_NAME := $(TARGET_TOOLCHAIN) 74 75# Define the root path of the toolchain in the NDK tree. 76TOOLCHAIN_ROOT := $(NDK_ROOT)/toolchains/$(TOOLCHAIN_NAME) 77 78# Define the root path where toolchain prebuilts are stored 79TOOLCHAIN_PREBUILT_ROOT := $(TOOLCHAIN_ROOT)/prebuilt/$(HOST_TAG) 80 81# Do the same for TOOLCHAIN_PREFIX. Note that we must chop the version 82# number from the toolchain name, e.g. arm-eabi-4.4.0 -> path/bin/arm-eabi- 83# to do that, we split at dashes, remove the last element, then merge the 84# result. Finally, add the complete path prefix. 85# 86TOOLCHAIN_PREFIX := $(call merge,-,$(call chop,$(call split,-,$(TOOLCHAIN_NAME))))- 87TOOLCHAIN_PREFIX := $(TOOLCHAIN_PREBUILT_ROOT)/bin/$(TOOLCHAIN_PREFIX) 88 89# Default build commands, can be overriden by the toolchain's setup script 90include $(BUILD_SYSTEM)/default-build-commands.mk 91 92# now call the toolchain-specific setup script 93include $(NDK_TOOLCHAIN.$(TARGET_TOOLCHAIN).setup) 94 95# We expect the gdbserver binary for this toolchain to be located at its root. 96TARGET_GDBSERVER := $(TOOLCHAIN_ROOT)/prebuilt/gdbserver 97 98# compute NDK_APP_DST_DIR as the destination directory for the generated files 99NDK_APP_DST_DIR := $(NDK_APP_PROJECT_PATH)/libs/$(TARGET_ARCH_ABI) 100 101clean-installed-binaries:: 102 103# Ensure that for debuggable applications, gdbserver will be copied to 104# the proper location 105ifeq ($(NDK_APP_DEBUGGABLE),true) 106 107NDK_APP_GDBSERVER := $(NDK_APP_DST_DIR)/gdbserver 108 109installed_modules: $(NDK_APP_GDBSERVER) 110 111$(NDK_APP_GDBSERVER): PRIVATE_NAME := $(TOOLCHAIN_NAME) 112$(NDK_APP_GDBSERVER): PRIVATE_SRC := $(TARGET_GDBSERVER) 113$(NDK_APP_GDBSERVER): PRIVATE_DST_DIR := $(NDK_APP_DST_DIR) 114$(NDK_APP_GDBSERVER): PRIVATE_DST := $(NDK_APP_GDBSERVER) 115 116$(NDK_APP_GDBSERVER): clean-installed-binaries 117 @ echo "Gdbserver : [$(PRIVATE_NAME)] $(call pretty-dir,$(PRIVATE_DST))" 118 $(hide) mkdir -p $(PRIVATE_DST_DIR) 119 $(hide) install -p $(PRIVATE_SRC) $(PRIVATE_DST) 120 121NDK_APP_GDBSETUP := $(NDK_APP_DST_DIR)/gdb.setup 122installed_modules: $(NDK_APP_GDBSETUP) 123 124$(NDK_APP_GDBSETUP): PRIVATE_DST := $(NDK_APP_GDBSETUP) 125$(NDK_APP_GDBSETUP): PRIVATE_DST_DIR := $(NDK_APP_DST_DIR) 126$(NDK_APP_GDBSETUP): PRIVATE_SOLIB_PATH := $(TARGET_OUT) 127$(NDK_APP_GDBSETUP): PRIVATE_SRC_DIRS := $(SYSROOT)/usr/include 128 129$(NDK_APP_GDBSETUP): 130 @ echo "Gdbsetup : $(call pretty-dir,$(PRIVATE_DST))" 131 $(hide) mkdir -p $(PRIVATE_DST_DIR) 132 $(hide) echo "set solib-search-path $(call host-path,$(PRIVATE_SOLIB_PATH))" > $(PRIVATE_DST) 133 $(hide) echo "directory $(call host-path,$(call remove-duplicates,$(PRIVATE_SRC_DIRS)))" >> $(PRIVATE_DST) 134 135# This prevents parallel execution to clear gdb.setup after it has been written to 136$(NDK_APP_GDBSETUP): clean-installed-binaries 137endif 138 139# free the dictionary of LOCAL_MODULE definitions 140$(call modules-clear) 141 142$(call ndk-stl-select,$(NDK_APP_STL)) 143 144# now parse the Android.mk for the application, this records all 145# module declarations, but does not populate the dependency graph yet. 146include $(NDK_APP_BUILD_SCRIPT) 147 148$(call ndk-stl-add-dependencies,$(NDK_APP_STL)) 149 150# recompute all dependencies between modules 151$(call modules-compute-dependencies) 152 153# for debugging purpose 154ifdef NDK_DEBUG_MODULES 155$(call modules-dump-database) 156endif 157 158# now, really build the modules, the second pass allows one to deal 159# with exported values 160$(foreach __pass2_module,$(__ndk_modules),\ 161 $(eval LOCAL_MODULE := $(__pass2_module))\ 162 $(eval include $(BUILD_SYSTEM)/build-binary.mk)\ 163) 164 165# Now compute the closure of all module dependencies. 166# 167# If APP_MODULES is not defined in the Application.mk, we 168# will build all modules that were listed from the top-level Android.mk 169# and the installable imported ones they depend on 170# 171ifeq ($(strip $(NDK_APP_MODULES)),) 172 WANTED_MODULES := $(call modules-get-all-installable,$(modules-get-top-list)) 173else 174 WANTED_MODULES := $(call module-get-all-dependencies,$(NDK_APP_MODULES)) 175endif 176 177WANTED_INSTALLED_MODULES += $(call map,module-get-installed,$(WANTED_MODULES)) 178