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 script is used to record an application definition in the 17# NDK build system, before performing any build whatsoever. 18# 19# It is included repeatedly from build/core/main.mk and expects a 20# variable named '_application_mk' which points to a given Application.mk 21# file that will be included here. The latter must define a few variables 22# to describe the application to the build system, and the rest of the 23# code here will perform book-keeping and basic checks 24# 25 26$(call assert-defined, _application_mk _app) 27$(call ndk_log,Parsing $(_application_mk)) 28 29$(call clear-vars, $(NDK_APP_VARS)) 30 31# Check that NDK_DEBUG is properly defined. If it is 32# the only valid states are: undefined, 0, 1, false and true 33# 34# We set APP_DEBUG to <undefined>, 'true' or 'false'. 35# 36APP_DEBUG := $(strip $(NDK_DEBUG)) 37ifeq ($(APP_DEBUG),0) 38 APP_DEBUG:= false 39endif 40ifeq ($(APP_DEBUG),1) 41 APP_DEBUG := true 42endif 43ifdef APP_DEBUG 44 ifneq (,$(filter-out true false,$(APP_DEBUG))) 45 $(call __ndk_warning,NDK_DEBUG is defined to the unsupported value '$(NDK_DEBUG)', will be ignored!) 46 endif 47endif 48 49include $(_application_mk) 50 51$(call check-required-vars,$(NDK_APP_VARS_REQUIRED),$(_application_mk)) 52 53_map := NDK_APP.$(_app) 54 55# strip the 'lib' prefix in front of APP_MODULES modules 56APP_MODULES := $(call strip-lib-prefix,$(APP_MODULES)) 57 58APP_PROJECT_PATH := $(strip $(APP_PROJECT_PATH)) 59ifndef APP_PROJECT_PATH 60 APP_PROJECT_PATH := $(NDK_PROJECT_PATH) 61endif 62 63ifeq (null,$(APP_PROJECT_PATH)) 64 65ifndef APP_PLATFORM 66 APP_PLATFORM := android-3 67 $(call ndk_log, Defaulted to APP_PLATFORM=$(APP_PLATFORM)) 68endif 69 70else 71 72# check whether APP_PLATFORM is defined. If not, look for project.properties in 73# the $(APP_PROJECT_PATH) and extract the value with awk's help. If nothing is here, 74# revert to the default value (i.e. "android-3"). 75# 76APP_PLATFORM := $(strip $(APP_PLATFORM)) 77ifndef APP_PLATFORM 78 _local_props := $(strip $(wildcard $(APP_PROJECT_PATH)/project.properties)) 79 ifndef _local_props 80 # NOTE: project.properties was called default.properties before 81 _local_props := $(strip $(wildcard $(APP_PROJECT_PATH)/default.properties)) 82 endif 83 ifdef _local_props 84 APP_PLATFORM := $(strip $(shell $(HOST_AWK) -f $(BUILD_AWK)/extract-platform.awk $(call host-path,$(_local_props)))) 85 $(call ndk_log, Found APP_PLATFORM=$(APP_PLATFORM) in $(_local_props)) 86 else 87 APP_PLATFORM := android-3 88 $(call ndk_log, Defaulted to APP_PLATFORM=$(APP_PLATFORM)) 89 endif 90endif 91 92ifeq ($(APP_PLATFORM),android-L) 93$(call __ndk_warning,WARNING: android-L is renamed as android-21) 94override APP_PLATFORM := android-21 95endif 96 97endif # APP_PROJECT_PATH == null 98 99# SPECIAL CASES: 100# 1) android-6 and android-7 are the same thing as android-5 101# 2) android-10 and android-11 are the same thing as android-9 102# 3) android-20 is the same thing as android-19 103# 4) android-21 and up are the same thing as android-21 104# ADDITIONAL CASES for remote server where total number of files is limited 105# 5) android-13 is the same thing as android-12 106# 6) android-15 is the same thing as android-14 107# 7) android-17 is the same thing as android-16 108APP_PLATFORM_LEVEL := $(strip $(subst android-,,$(APP_PLATFORM))) 109ifneq (,$(filter 6 7,$(APP_PLATFORM_LEVEL))) 110 override APP_PLATFORM := android-5 111endif 112ifneq (,$(filter 10 11,$(APP_PLATFORM_LEVEL))) 113 override APP_PLATFORM := android-9 114endif 115ifneq (,$(filter 20,$(APP_PLATFORM_LEVEL))) 116 override APP_PLATFORM := android-19 117endif 118ifneq (,$(call gt,$(APP_PLATFORM_LEVEL),21)) 119 override APP_PLATFORM := android-21 120endif 121 122ifneq ($(strip $(subst android-,,$(APP_PLATFORM))),$(APP_PLATFORM_LEVEL)) 123 $(call ndk_log, Adjusting APP_PLATFORM android-$(APP_PLATFORM_LEVEL) to $(APP_PLATFORM)) 124endif 125 126# If APP_PIE isn't defined, set it to true for android-$(NDK_FIRST_PIE_PLATFORM_LEVEL) and above 127# 128APP_PIE := $(strip $(APP_PIE)) 129$(call ndk_log, APP_PIE is $(APP_PIE)) 130ifndef APP_PIE 131 ifneq (,$(call gte,$(APP_PLATFORM_LEVEL),$(NDK_FIRST_PIE_PLATFORM_LEVEL))) 132 APP_PIE := true 133 $(call ndk_log, Enabling -fPIE) 134 else 135 APP_PIE := false 136 endif 137endif 138 139# Check that the value of APP_PLATFORM corresponds to a known platform 140# If not, we're going to use the max supported platform value. 141# 142_bad_platform := $(strip $(filter-out $(NDK_ALL_PLATFORMS),$(APP_PLATFORM))) 143ifdef _bad_platform 144 $(call ndk_log,Application $(_app) targets unknown platform '$(_bad_platform)') 145 override APP_PLATFORM := android-$(NDK_MAX_PLATFORM_LEVEL) 146 $(call ndk_log,Switching to $(APP_PLATFORM)) 147endif 148 149ifneq (null,$(APP_PROJECT_PATH)) 150 151# Check platform level (after adjustment) against android:minSdkVersion in AndroidManifest.xml 152# 153APP_MANIFEST := $(strip $(wildcard $(APP_PROJECT_PATH)/AndroidManifest.xml)) 154APP_PLATFORM_LEVEL := $(strip $(subst android-,,$(APP_PLATFORM))) 155ifdef APP_MANIFEST 156 APP_MIN_PLATFORM_LEVEL := $(strip $(shell $(HOST_AWK) -f $(BUILD_AWK)/extract-minsdkversion.awk $(call host-path,$(APP_MANIFEST)))) 157 ifdef APP_MIN_PLATFORM_LEVEL 158 ifneq (,$(call gt,$(APP_PLATFORM_LEVEL),$(APP_MIN_PLATFORM_LEVEL))) 159 $(call __ndk_info,WARNING: APP_PLATFORM $(APP_PLATFORM) is larger than android:minSdkVersion $(APP_MIN_PLATFORM_LEVEL) in $(APP_MANIFEST)) 160 endif 161 endif 162endif 163 164endif # APP_PROJECT_PATH == null 165 166# Check that the value of APP_ABI corresponds to known ABIs 167# 'all' is a special case that means 'all supported ABIs' 168# 169# It will be handled in setup-app.mk. We can't hope to change 170# the value of APP_ABI is the user enforces it on the command-line 171# with a call like: ndk-build APP_ABI=all 172# 173# Because GNU Make makes the APP_ABI variable read-only (any assignments 174# to it will be ignored) 175# 176APP_ABI := $(subst $(comma),$(space),$(strip $(APP_ABI))) 177ifndef APP_ABI 178 # Default ABI is 'armeabi' 179 APP_ABI := armeabi 180endif 181ifneq ($(APP_ABI),all) 182 _bad_abis := $(strip $(filter-out $(NDK_ALL_ABIS),$(APP_ABIS))) 183 ifdef _bad_abis 184 $(call __ndk_info,Application $(_app) targets unknown ABI '$(_bad_abis)') 185 $(call __ndk_info,Please fix the APP_ABI definition in $(_application_mk)) 186 $(call __ndk_info,to use a set of the following values: $(NDK_ALL_ABIS)) 187 $(call __ndk_error,Aborting) 188 endif 189endif 190 191# If APP_BUILD_SCRIPT is defined, check that the file exists. 192# If undefined, look in $(APP_PROJECT_PATH)/jni/Android.mk 193# 194APP_BUILD_SCRIPT := $(strip $(APP_BUILD_SCRIPT)) 195ifdef APP_BUILD_SCRIPT 196 _build_script := $(strip $(wildcard $(APP_BUILD_SCRIPT))) 197 ifndef _build_script 198 $(call __ndk_info,Your APP_BUILD_SCRIPT points to an unknown file: $(APP_BUILD_SCRIPT)) 199 $(call __ndk_error,Aborting...) 200 endif 201 APP_BUILD_SCRIPT := $(_build_script) 202 $(call ndk_log, Using build script $(APP_BUILD_SCRIPT)) 203else 204 ifeq (null,$(APP_PROJECT_PATH)) 205 $(call __ndk_info,NDK_PROJECT_PATH==null. Please explicitly set APP_BUILD_SCRIPT.) 206 $(call __ndk_error,Aborting.) 207 endif 208 209 _build_script := $(strip $(wildcard $(APP_PROJECT_PATH)/jni/Android.mk)) 210 ifndef _build_script 211 $(call __ndk_info,There is no Android.mk under $(APP_PROJECT_PATH)/jni) 212 $(call __ndk_info,If this is intentional, please define APP_BUILD_SCRIPT to point) 213 $(call __ndk_info,to a valid NDK build script.) 214 $(call __ndk_error,Aborting...) 215 endif 216 APP_BUILD_SCRIPT := $(_build_script) 217 $(call ndk_log, Defaulted to APP_BUILD_SCRIPT=$(APP_BUILD_SCRIPT)) 218endif 219 220# Determine whether the application should be debuggable. 221# - If APP_DEBUG is set to 'true', then it always should. 222# - If APP_DEBUG is set to 'false', then it never should 223# - Otherwise, extract the android:debuggable attribute from the manifest. 224# 225ifdef APP_DEBUG 226 APP_DEBUGGABLE := $(APP_DEBUG) 227 ifeq ($(NDK_LOG),1) 228 ifeq ($(APP_DEBUG),true) 229 $(call ndk_log,Application '$(_app)' forced debuggable through NDK_DEBUG) 230 else 231 $(call ndk_log,Application '$(_app)' forced *not* debuggable through NDK_DEBUG) 232 endif 233 endif 234else 235 # NOTE: To make unit-testing simpler, handle the case where there is no manifest. 236 APP_DEBUGGABLE := false 237 ifdef APP_MANIFEST 238 APP_DEBUGGABLE := $(shell $(HOST_AWK) -f $(BUILD_AWK)/extract-debuggable.awk $(call host-path,$(APP_MANIFEST))) 239 endif 240 ifeq ($(NDK_LOG),1) 241 ifeq ($(APP_DEBUGGABLE),true) 242 $(call ndk_log,Application '$(_app)' *is* debuggable) 243 else 244 $(call ndk_log,Application '$(_app)' is not debuggable) 245 endif 246 endif 247endif 248 249# LOCAL_BUILD_MODE will be either release or debug 250# 251# If APP_OPTIM is defined in the Application.mk, just use this. 252# 253# Otherwise, set to 'debug' if android:debuggable is set to TRUE, 254# and to 'release' if not. 255# 256ifneq ($(APP_OPTIM),) 257 # check that APP_OPTIM, if defined, is either 'release' or 'debug' 258 $(if $(filter-out release debug,$(APP_OPTIM)),\ 259 $(call __ndk_info, The APP_OPTIM defined in $(_application_mk) must only be 'release' or 'debug')\ 260 $(call __ndk_error,Aborting)\ 261 ) 262 $(call ndk_log,Selecting optimization mode through Application.mk: $(APP_OPTIM)) 263else 264 ifeq ($(APP_DEBUGGABLE),true) 265 $(call ndk_log,Selecting debug optimization mode (app is debuggable)) 266 APP_OPTIM := debug 267 else 268 $(call ndk_log,Selecting release optimization mode (app is not debuggable)) 269 APP_OPTIM := release 270 endif 271endif 272 273APP_CFLAGS := $(strip $(APP_CFLAGS)) 274APP_CONLYFLAGS := $(strip $(APP_CONLYFLAGS)) 275APP_CPPFLAGS := $(strip $(APP_CPPFLAGS)) 276APP_CXXFLAGS := $(strip $(APP_CXXFLAGS)) 277APP_RENDERSCRIPT_FLAGS := $(strip $(APP_RENDERSCRIPT_FLAGS)) 278APP_ASMFLAGS := $(strip $(APP_ASMFLAGS)) 279APP_LDFLAGS := $(strip $(APP_LDFLAGS)) 280 281# Check that APP_STL is defined. If not, use the default value (system) 282# otherwise, check that the name is correct. 283APP_STL := $(strip $(APP_STL)) 284ifndef APP_STL 285 APP_STL := system 286else 287 $(call ndk-stl-check,$(APP_STL)) 288endif 289 290$(if $(call get,$(_map),defined),\ 291 $(call __ndk_info,Weird, the application $(_app) is already defined by $(call get,$(_map),defined))\ 292 $(call __ndk_error,Aborting)\ 293) 294 295$(call set,$(_map),defined,$(_application_mk)) 296 297# Record all app-specific variable definitions 298$(foreach __name,$(NDK_APP_VARS),\ 299 $(call set,$(_map),$(__name),$($(__name)))\ 300) 301 302# Record the Application.mk for debugging 303$(call set,$(_map),Application.mk,$(_application_mk)) 304 305NDK_ALL_APPS += $(_app) 306