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