Home | History | Annotate | Download | only in core
      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)
     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 #
     26 ifndef 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)
     38 else # 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)
     48 endif # NDK_TOOLCHAIN is not empty
     49 
     50 TARGET_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 #
     57 SYSROOT := $(NDK_PLATFORMS_ROOT)/$(TARGET_PLATFORM)/arch-$(TARGET_ARCH)
     58 
     59 TARGET_CRTBEGIN_STATIC_O  := $(SYSROOT)/usr/lib/crtbegin_static.o
     60 TARGET_CRTBEGIN_DYNAMIC_O := $(SYSROOT)/usr/lib/crtbegin_dynamic.o
     61 TARGET_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 #
     66 TARGET_CRTBEGIN_SO_O := $(strip $(wildcard $(SYSROOT)/usr/lib/crtbegin_so.o))
     67 TARGET_CRTEND_SO_O   := $(strip $(wildcard $(SYSROOT)/usr/lib/crtend_so.o))
     68 
     69 TARGET_PREBUILT_SHARED_LIBRARIES := libc libstdc++ libm
     70 TARGET_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.
     74 TOOLCHAIN_NAME   := $(TARGET_TOOLCHAIN)
     75 
     76 # Define the root path of the toolchain in the NDK tree.
     77 TOOLCHAIN_ROOT   := $(NDK_ROOT)/toolchains/$(TOOLCHAIN_NAME)
     78 
     79 # Define the root path where toolchain prebuilts are stored
     80 TOOLCHAIN_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 #
     87 TOOLCHAIN_PREFIX := $(call merge,-,$(call chop,$(call split,-,$(TOOLCHAIN_NAME))))-
     88 TOOLCHAIN_PREFIX := $(TOOLCHAIN_PREBUILT_ROOT)/bin/$(TOOLCHAIN_PREFIX)
     89 
     90 # Default build commands, can be overriden by the toolchain's setup script
     91 include $(BUILD_SYSTEM)/default-build-commands.mk
     92 
     93 # now call the toolchain-specific setup script
     94 include $(NDK_TOOLCHAIN.$(TARGET_TOOLCHAIN).setup)
     95 
     96 # We expect the gdbserver binary for this toolchain to be located at its root.
     97 TARGET_GDBSERVER := $(TOOLCHAIN_ROOT)/prebuilt/gdbserver
     98 
     99 # compute NDK_APP_DST_DIR as the destination directory for the generated files
    100 NDK_APP_DST_DIR := $(NDK_APP_PROJECT_PATH)/libs/$(TARGET_ARCH_ABI)
    101 
    102 clean-installed-binaries::
    103 
    104 # Ensure that for debuggable applications, gdbserver will be copied to
    105 # the proper location
    106 ifeq ($(NDK_APP_DEBUGGABLE),true)
    107 
    108 NDK_APP_GDBSERVER := $(NDK_APP_DST_DIR)/gdbserver
    109 
    110 installed_modules: $(NDK_APP_GDBSERVER)
    111 
    112 $(NDK_APP_GDBSERVER): PRIVATE_NAME    := $(TOOLCHAIN_NAME)
    113 $(NDK_APP_GDBSERVER): PRIVATE_SRC     := $(TARGET_GDBSERVER)
    114 $(NDK_APP_GDBSERVER): PRIVATE_DST_DIR := $(NDK_APP_DST_DIR)
    115 $(NDK_APP_GDBSERVER): PRIVATE_DST     := $(NDK_APP_GDBSERVER)
    116 
    117 $(NDK_APP_GDBSERVER): clean-installed-binaries
    118 	@ echo "Gdbserver      : [$(PRIVATE_NAME)] $(call pretty-dir,$(PRIVATE_DST))"
    119 	$(hide) mkdir -p $(PRIVATE_DST_DIR)
    120 	$(hide) install -p $(PRIVATE_SRC) $(PRIVATE_DST)
    121 
    122 NDK_APP_GDBSETUP := $(NDK_APP_DST_DIR)/gdb.setup
    123 installed_modules: $(NDK_APP_GDBSETUP)
    124 
    125 $(NDK_APP_GDBSETUP): PRIVATE_DST := $(NDK_APP_GDBSETUP)
    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) echo "set solib-search-path $(call host-path,$(PRIVATE_SOLIB_PATH))" > $(PRIVATE_DST)
    132 	$(hide) echo "directory $(call host-path,$(call uniq,$(PRIVATE_SRC_DIRS)))" >> $(PRIVATE_DST)
    133 
    134 # This prevents parallel execution to clear gdb.setup after it has been written to
    135 $(NDK_APP_GDBSETUP): clean-installed-binaries
    136 endif
    137 
    138 # free the dictionary of LOCAL_MODULE definitions
    139 $(call modules-clear)
    140 
    141 # now parse the Android.mk for the application, this records all
    142 # module declarations, but does not populate the dependency graph yet.
    143 include $(NDK_APP_BUILD_SCRIPT)
    144 
    145 # special case of C++ runtime support: If any module has C++ sources,
    146 # we need to parse the Android.mk for our selected C++ runtime and
    147 # add it as an automatic dependency to the corresponding modules.
    148 #
    149 include $(NDK_ROOT)/sources/cxx-stl/system/setup.mk
    150 $(call modules-add-c++-dependencies,$(NDK_APP_CXX_STATIC_LIBRARIES),$(NDK_APP_CXX_SHARED_LIBRARIES))
    151 
    152 # recompute all dependencies between modules
    153 $(call modules-compute-dependencies)
    154 
    155 # for debugging purpose
    156 ifdef NDK_DEBUG_MODULES
    157 $(call modules-dump-database)
    158 endif
    159 
    160 # now, really build the modules, the second pass allows one to deal
    161 # with exported values
    162 $(foreach __pass2_module,$(__ndk_modules),\
    163     $(eval LOCAL_MODULE := $(__pass2_module))\
    164     $(eval include $(BUILD_SYSTEM)/build-binary.mk)\
    165 )
    166 
    167 # Now compute the closure of all module dependencies.
    168 #
    169 # If APP_MODULES is not defined in the Application.mk, we
    170 # will build all modules that were listed from the top-level Android.mk
    171 #
    172 ifeq ($(strip $(NDK_APP_MODULES)),)
    173     WANTED_MODULES := $(call modules-get-top-list)
    174 else
    175     WANTED_MODULES := $(call module-get-all-dependencies,$(NDK_APP_MODULES))
    176 endif
    177 
    178 WANTED_INSTALLED_MODULES += $(call map,module-get-installed,$(WANTED_MODULES))
    179