setup-toolchain.mk revision 05be040fdd9fa9d23259d6b6a4aaf4f2aca9c9f2
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 := libc libstdc++ libm
70TARGET_PREBUILT_SHARED_LIBRARIES := $(TARGET_PREBUILT_SHARED_LIBRARIES:%=$(SYSROOT)/usr/lib/%.so)
71
72# Define default values for TOOLCHAIN_NAME, this can be overriden in
73# the setup file.
74TOOLCHAIN_NAME   := $(TARGET_TOOLCHAIN)
75
76# Define the root path of the toolchain in the NDK tree.
77TOOLCHAIN_ROOT   := $(NDK_ROOT)/toolchains/$(TOOLCHAIN_NAME)
78
79# Define the root path where toolchain prebuilts are stored
80TOOLCHAIN_PREBUILT_ROOT := $(TOOLCHAIN_ROOT)/prebuilt/$(HOST_TAG)
81
82# Do the same for TOOLCHAIN_PREFIX. Note that we must chop the version
83# number from the toolchain name, e.g. arm-eabi-4.4.0 -> path/bin/arm-eabi-
84# to do that, we split at dashes, remove the last element, then merge the
85# result. Finally, add the complete path prefix.
86#
87TOOLCHAIN_PREFIX := $(call merge,-,$(call chop,$(call split,-,$(TOOLCHAIN_NAME))))-
88TOOLCHAIN_PREFIX := $(TOOLCHAIN_PREBUILT_ROOT)/bin/$(TOOLCHAIN_PREFIX)
89
90# Default build commands, can be overriden by the toolchain's setup script
91include $(BUILD_SYSTEM)/default-build-commands.mk
92
93# now call the toolchain-specific setup script
94include $(NDK_TOOLCHAIN.$(TARGET_TOOLCHAIN).setup)
95
96# We expect the gdbserver binary for this toolchain to be located at its root.
97TARGET_GDBSERVER := $(TOOLCHAIN_ROOT)/prebuilt/gdbserver
98
99# compute NDK_APP_DST_DIR as the destination directory for the generated files
100NDK_APP_DST_DIR := $(NDK_APP_PROJECT_PATH)/libs/$(TARGET_ARCH_ABI)
101
102clean-installed-binaries::
103
104# Ensure that for debuggable applications, gdbserver will be copied to
105# the proper location
106ifeq ($(NDK_APP_DEBUGGABLE),true)
107
108ifneq ($(TARGET_ARCH),llvm)
109NDK_APP_GDBSERVER := $(NDK_APP_DST_DIR)/gdbserver
110
111installed_modules: $(NDK_APP_GDBSERVER)
112
113$(NDK_APP_GDBSERVER): PRIVATE_NAME    := $(TOOLCHAIN_NAME)
114$(NDK_APP_GDBSERVER): PRIVATE_SRC     := $(TARGET_GDBSERVER)
115$(NDK_APP_GDBSERVER): PRIVATE_DST_DIR := $(NDK_APP_DST_DIR)
116$(NDK_APP_GDBSERVER): PRIVATE_DST     := $(NDK_APP_GDBSERVER)
117
118$(NDK_APP_GDBSERVER): clean-installed-binaries
119	@ echo "Gdbserver      : [$(PRIVATE_NAME)] $(call pretty-dir,$(PRIVATE_DST))"
120	$(hide) mkdir -p $(PRIVATE_DST_DIR)
121	$(hide) install -p $(PRIVATE_SRC) $(PRIVATE_DST)
122
123NDK_APP_GDBSETUP := $(NDK_APP_DST_DIR)/gdb.setup
124installed_modules: $(NDK_APP_GDBSETUP)
125
126$(NDK_APP_GDBSETUP): PRIVATE_DST := $(NDK_APP_GDBSETUP)
127$(NDK_APP_GDBSETUP): PRIVATE_SOLIB_PATH := $(TARGET_OUT)
128$(NDK_APP_GDBSETUP): PRIVATE_SRC_DIRS := $(SYSROOT)/usr/include
129
130$(NDK_APP_GDBSETUP):
131	@ echo "Gdbsetup       : $(call pretty-dir,$(PRIVATE_DST))"
132	$(hide) echo "set solib-search-path $(call host-path,$(PRIVATE_SOLIB_PATH))" > $(PRIVATE_DST)
133	$(hide) echo "directory $(call host-path,$(call uniq,$(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
138endif
139
140# free the dictionary of LOCAL_MODULE definitions
141$(call modules-clear)
142
143$(call ndk-stl-select,$(NDK_APP_STL))
144
145# now parse the Android.mk for the application, this records all
146# module declarations, but does not populate the dependency graph yet.
147include $(NDK_APP_BUILD_SCRIPT)
148
149$(call ndk-stl-add-dependencies,$(NDK_APP_STL))
150
151# recompute all dependencies between modules
152$(call modules-compute-dependencies)
153
154# for debugging purpose
155ifdef NDK_DEBUG_MODULES
156$(call modules-dump-database)
157endif
158
159# now, really build the modules, the second pass allows one to deal
160# with exported values
161$(foreach __pass2_module,$(__ndk_modules),\
162    $(eval LOCAL_MODULE := $(__pass2_module))\
163    $(eval include $(BUILD_SYSTEM)/build-binary.mk)\
164)
165
166# Now compute the closure of all module dependencies.
167#
168# If APP_MODULES is not defined in the Application.mk, we
169# will build all modules that were listed from the top-level Android.mk
170#
171ifeq ($(strip $(NDK_APP_MODULES)),)
172    WANTED_MODULES := $(call 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