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# ==================================================================== 17# 18# Define the main configuration variables, and read the host-specific 19# configuration file that is normally generated by build/host-setup.sh 20# 21# ==================================================================== 22 23# The location of the build system files 24BUILD_SYSTEM := $(strip $(dir $(lastword $(MAKEFILE_LIST)))) 25BUILD_SYSTEM := $(BUILD_SYSTEM:%/=%) 26 27# Include common definitions 28include build/core/definitions.mk 29 30# Where all generated files will be stored during a build 31NDK_OUT := out 32 33# Read the host-specific configuration file in $(NDK_OUT) 34# 35HOST_CONFIG_MAKE := $(NDK_OUT)/host/config.mk 36 37ifeq ($(strip $(wildcard $(HOST_CONFIG_MAKE))),) 38 $(call __ndk_info,\ 39 The configuration file '$(HOST_CONFIG_MAKE)' doesnt' exist.) 40 $(call __ndk_info,\ 41 Please run 'build/host-setup.sh' to generate it.) 42 $(call __ndk_error, Aborting) 43endif 44 45include $(HOST_CONFIG_MAKE) 46HOST_PREBUILT_TAG := $(HOST_TAG) 47 48# Location where all prebuilt binaries for a given host architectures 49# will be stored. 50HOST_PREBUILT := build/prebuilt/$(HOST_TAG) 51 52# Where all app-specific generated files will be stored 53NDK_APP_OUT := $(NDK_OUT)/apps 54 55# Where all host-specific generated files will be stored 56NDK_HOST_OUT := $(NDK_OUT)/host/$(HOST_TAG) 57 58# ==================================================================== 59# 60# Read all toolchain-specific configuration files. 61# 62# Each toolchain must have a corresponding config.mk file located 63# in build/toolchains/<name>/ that will be included here. 64# 65# Each one of these files should define the following variables: 66# TOOLCHAIN_NAME toolchain name (e.g. arm-eabi-4.2.1) 67# TOOLCHAIN_ABIS list of target ABIs supported by the toolchain. 68# 69# Then, it should include $(ADD_TOOLCHAIN) which will perform 70# book-keeping for the build system. 71# 72# ==================================================================== 73 74# the build script to include in each toolchain config.mk 75ADD_TOOLCHAIN := $(BUILD_SYSTEM)/add-toolchain.mk 76 77# the list of all toolchains in this NDK 78NDK_ALL_TOOLCHAINS := 79NDK_ALL_ABIS := 80 81TOOLCHAIN_CONFIGS := $(wildcard build/toolchains/*/config.mk) 82$(foreach _config_mk,$(TOOLCHAIN_CONFIGS),\ 83 $(eval include $(BUILD_SYSTEM)/add-toolchain.mk)\ 84) 85 86#$(info ALL_TOOLCHAINS=$(ALL_TOOLCHAINS)) 87NDK_TARGET_TOOLCHAIN := $(firstword $(NDK_ALL_TOOLCHAINS)) 88$(call ndk_log, Default toolchain is $(NDK_TARGET_TOOLCHAIN)) 89 90NDK_ALL_TOOLCHAINS := $(call uniq,$(NDK_ALL_TOOLCHAINS)) 91NDK_ALL_ABIS := $(call uniq,$(NDK_ALL_ABIS)) 92 93$(call ndk_log, This NDK supports the following toolchains and target ABIs:) 94$(foreach tc,$(NDK_ALL_TOOLCHAINS),\ 95 $(call ndk_log, $(space)$(space)$(tc): $(NDK_TOOLCHAIN.$(tc).abis))\ 96) 97 98# ==================================================================== 99# 100# Read all platform-specific configuration files. 101# 102# Each platform must be located in build/platforms/android-<apilevel> 103# where <apilevel> corresponds to an API level number, with: 104# 3 -> Android 1.5 105# 4 -> next platform release 106# 107# ==================================================================== 108 109NDK_PLATFORMS_ROOT := $(BUILD_SYSTEM)/../platforms 110NDK_ALL_PLATFORMS := $(strip $(notdir $(wildcard $(NDK_PLATFORMS_ROOT)/android-*))) 111$(call ndk_log,Found supported platforms: $(NDK_ALL_PLATFORMS)) 112 113$(foreach _platform,$(NDK_ALL_PLATFORMS),\ 114 $(eval include $(BUILD_SYSTEM)/add-platform.mk)\ 115) 116 117# we're going to find the maximum platform number of the form android-<number> 118# ignore others, which could correspond to special and experimental cases 119NDK_ALL_PLATFORM_LEVELS := $(filter android-%,$(NDK_ALL_PLATFORMS)) 120NDK_ALL_PLATFORM_LEVELS := $(patsubst android-%,%,$(NDK_ALL_PLATFORM_LEVELS)) 121$(call ndk_log,Found stable platform levels: $(NDK_ALL_PLATFORM_LEVELS)) 122 123NDK_MAX_PLATFORM_LEVEL := 3 124$(foreach level,$(NDK_ALL_PLATFORM_LEVELS),\ 125 $(eval NDK_MAX_PLATFORM_LEVEL := $$(call max,$$(NDK_MAX_PLATFORM_LEVEL),$$(level)))\ 126) 127$(call ndk_log,Found max platform level: $(NDK_MAX_PLATFORM_LEVEL)) 128 129# ==================================================================== 130# 131# Read all application configuration files 132# 133# Each 'application' must have a corresponding Application.mk file 134# located in apps/<name> where <name> is a liberal name that doesn't 135# contain any space in it, used to uniquely identify the 136# 137# See docs/ANDROID-MK.TXT for their specification. 138# 139# ==================================================================== 140 141NDK_ALL_APPS := 142 143NDK_APPLICATIONS := $(wildcard apps/*/Application.mk) 144$(foreach _application_mk, $(NDK_APPLICATIONS),\ 145 $(eval include $(BUILD_SYSTEM)/add-application.mk)\ 146) 147 148# clean up environment, just to be safe 149$(call clear-vars, $(NDK_APP_VARS)) 150 151ifeq ($(strip $(NDK_ALL_APPS)),) 152 $(call __ndk_info,\ 153 The NDK could not find a proper application description under apps/*/Application.mk) 154 $(call __ndk_info,\ 155 Please follow the instructions in docs/NDK-APPS.TXT to write one.) 156 $(call __ndk_error, Aborting) 157endif 158 159ifeq ($(strip $(APP)),) 160 $(call __ndk_info,\ 161 The APP variable is undefined or empty.) 162 $(call __ndk_info,\ 163 Please define it to one of: $(NDK_ALL_APPS)) 164 $(call __ndk_info,\ 165 You can also add new applications by writing an Application.mk file.) 166 $(call __ndk_info,\ 167 See docs/APPLICATION-MK.TXT for details.) 168 $(call __ndk_error, Aborting) 169endif 170 171# now check that APP doesn't contain an unknown app name 172# if it does, we ignore them if there is at least one known 173# app name in the list. Otherwise, abort with an error message 174# 175_unknown_apps := $(filter-out $(NDK_ALL_APPS),$(APP)) 176_known_apps := $(filter $(NDK_ALL_APPS),$(APP)) 177 178NDK_APPS := $(APP) 179 180$(if $(_unknown_apps),\ 181 $(if $(_known_apps),\ 182 $(call __ndk_info,WARNING:\ 183 Removing unknown names from APP variable: $(_unknown_apps))\ 184 $(eval NDK_APPS := $(_known_apps))\ 185 ,\ 186 $(call __ndk_info,\ 187 The APP variable contains unknown app names: $(_unknown_apps))\ 188 $(call __ndk_info,\ 189 Please use one of: $(NDK_ALL_APPS))\ 190 $(call __ndk_error, Aborting)\ 191 )\ 192) 193 194$(call __ndk_info,Building for application '$(NDK_APPS)') 195 196# ==================================================================== 197# 198# Prepare the build for parsing Android.mk files 199# 200# ==================================================================== 201 202# These phony targets are used to control various stages of the build 203.PHONY: all \ 204 host_libraries host_executables \ 205 installed_modules \ 206 executables libraries static_libraries shared_libraries \ 207 clean clean-config clean-objs-dir \ 208 clean-executables clean-libraries \ 209 clean-installed-modules 210 211# These macros are used in Android.mk to include the corresponding 212# build script that will parse the LOCAL_XXX variable definitions. 213# 214CLEAR_VARS := $(BUILD_SYSTEM)/clear-vars.mk 215BUILD_HOST_EXECUTABLE := $(BUILD_SYSTEM)/build-host-executable.mk 216BUILD_HOST_STATIC_LIBRARY := $(BUILD_SYSTEM)/build-host-static-library.mk 217BUILD_STATIC_LIBRARY := $(BUILD_SYSTEM)/build-static-library.mk 218BUILD_SHARED_LIBRARY := $(BUILD_SYSTEM)/build-shared-library.mk 219BUILD_EXECUTABLE := $(BUILD_SYSTEM)/build-executable.mk 220 221ANDROID_MK_INCLUDED := \ 222 $(CLEAR_VARS) \ 223 $(BUILD_HOST_EXECUTABLE) \ 224 $(BUILD_HOST_STATIC_LIBRARY) \ 225 $(BUILD_STATIC_LIBRARY) \ 226 $(BUILD_SHARED_LIBRARY) \ 227 $(BUILD_EXECUTABLE) \ 228 229 230# this is the list of directories containing dependency information 231# generated during the build. It will be updated by build scripts 232# when module definitions are parsed. 233# 234ALL_DEPENDENCY_DIRS := 235 236# this is the list of all generated files that we would need to clean 237ALL_HOST_EXECUTABLES := 238ALL_HOST_STATIC_LIBRARIES := 239ALL_STATIC_LIBRARIES := 240ALL_SHARED_LIBRARIES := 241ALL_EXECUTABLES := 242ALL_INSTALLED_MODULES := 243 244# the first rule 245all: installed_modules host_libraries host_executables 246 247 248$(foreach _app,$(NDK_APPS),\ 249 $(eval include $(BUILD_SYSTEM)/setup-app.mk)\ 250) 251 252# ==================================================================== 253# 254# Now finish the build preparation with a few rules that depend on 255# what has been effectively parsed and recorded previously 256# 257# ==================================================================== 258 259clean: clean-intermediates clean-installed-modules 260 261distclean: clean clean-config 262 263installed_modules: libraries $(ALL_INSTALLED_MODULES) 264host_libraries: $(HOST_STATIC_LIBRARIES) 265host_executables: $(HOST_EXECUTABLES) 266 267static_libraries: $(STATIC_LIBRARIES) 268shared_libraries: $(SHARED_LIBRARIES) 269executables: $(EXECUTABLES) 270 271libraries: static_libraries shared_libraries 272 273clean-host-intermediates: 274 $(hide) rm -rf $(HOST_EXECUTABLES) $(HOST_STATIC_LIBRARIES) 275 276clean-intermediates: clean-host-intermediates 277 $(hide) rm -rf $(EXECUTABLES) $(STATIC_LIBRARIES) $(SHARED_LIBRARIES) 278 279clean-installed-modules: 280 $(hide) rm -rf $(ALL_INSTALLED_MODULES) 281 282clean-config: 283 $(hide) rm -f $(CONFIG_MAKE) $(CONFIG_H) 284 285# include dependency information 286ALL_DEPENDENCY_DIRS := $(sort $(ALL_DEPENDENCY_DIRS)) 287-include $(wildcard $(ALL_DEPENDENCY_DIRS:%=%/*.d)) 288