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 # 36 APP_DEBUG := $(strip $(NDK_DEBUG)) 37 ifeq ($(APP_DEBUG),0) 38 APP_DEBUG:= false 39 endif 40 ifeq ($(APP_DEBUG),1) 41 APP_DEBUG := true 42 endif 43 ifdef 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 47 endif 48 49 include $(_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 56 APP_MODULES := $(call strip-lib-prefix,$(APP_MODULES)) 57 58 APP_PROJECT_PATH := $(strip $(APP_PROJECT_PATH)) 59 ifndef APP_PROJECT_PATH 60 APP_PROJECT_PATH := $(NDK_PROJECT_PATH) 61 endif 62 63 # check whether APP_PLATFORM is defined. If not, look for project.properties in 64 # the $(APP_PROJECT_PATH) and extract the value with awk's help. If nothing is here, 65 # revert to the default value (i.e. "android-3"). 66 # 67 APP_PLATFORM := $(strip $(APP_PLATFORM)) 68 ifndef APP_PLATFORM 69 _local_props := $(strip $(wildcard $(APP_PROJECT_PATH)/project.properties)) 70 ifndef _local_props 71 # NOTE: project.properties was called default.properties before 72 _local_props := $(strip $(wildcard $(APP_PROJECT_PATH)/default.properties)) 73 endif 74 ifdef _local_props 75 APP_PLATFORM := $(strip $(shell $(HOST_AWK) -f $(BUILD_AWK)/extract-platform.awk $(call host-path,$(_local_props)))) 76 $(call ndk_log, Found APP_PLATFORM=$(APP_PLATFORM) in $(_local_props)) 77 else 78 APP_PLATFORM := android-3 79 $(call ndk_log, Defaulted to APP_PLATFORM=$(APP_PLATFORM)) 80 endif 81 endif 82 83 # SPECIAL CASES: 84 # 1) android-6 and android-7 are the same thing as android-5 85 # 2) android-10 .. 13 is the same thing as android-9 86 # 87 APP_PLATFORM_LEVEL := $(strip $(subst android-,,$(APP_PLATFORM))) 88 ifneq (,$(filter 6 7,$(APP_PLATFORM_LEVEL))) 89 APP_PLATFORM := android-5 90 $(call ndk_log, Adjusting APP_PLATFORM android-$(APP_PLATFORM_LEVEL) to $(APP_PLATFORM)) 91 endif 92 ifneq (,$(filter 10 11 12 13,$(APP_PLATFORM_LEVEL))) 93 APP_PLATFORM := android-9 94 $(call ndk_log, Adjusting APP_PLATFORM android-$(APP_PLATFORM_LEVEL) to $(APP_PLATFORM)) 95 endif 96 97 # If APP_PIE isn't defined, set it to true for android-16 and above 98 # 99 APP_PIE := $(strip $(APP_PIE)) 100 $(call ndk_log, APP_PIE is $(APP_PIE)) 101 ifndef APP_PIE 102 ifneq (,$(call gte,$(APP_PLATFORM_LEVEL),16)) 103 APP_PLATFORM := android-14 104 $(call ndk_log, Adjusting APP_PLATFORM android-$(APP_PLATFORM_LEVEL) to $(APP_PLATFORM) and enabling -fPIE) 105 APP_PIE := true 106 else 107 APP_PIE := false 108 endif 109 endif 110 111 # Check that the value of APP_PLATFORM corresponds to a known platform 112 # If not, we're going to use the max supported platform value. 113 # 114 _bad_platform := $(strip $(filter-out $(NDK_ALL_PLATFORMS),$(APP_PLATFORM))) 115 ifdef _bad_platform 116 $(call ndk_log,Application $(_app) targets unknown platform '$(_bad_platform)') 117 APP_PLATFORM := android-$(NDK_MAX_PLATFORM_LEVEL) 118 $(call ndk_log,Switching to $(APP_PLATFORM)) 119 endif 120 121 # Check platform level (after adjustment) against android:minSdkVersion in AndroidManifest.xml 122 # 123 APP_MANIFEST := $(strip $(wildcard $(APP_PROJECT_PATH)/AndroidManifest.xml)) 124 APP_PLATFORM_LEVEL := $(strip $(subst android-,,$(APP_PLATFORM))) 125 ifdef APP_MANIFEST 126 APP_MIN_PLATFORM_LEVEL := $(shell $(HOST_AWK) -f $(BUILD_AWK)/extract-minsdkversion.awk $(call host-path,$(APP_MANIFEST))) 127 ifneq (,$(call gt,$(APP_PLATFORM_LEVEL),$(APP_MIN_PLATFORM_LEVEL))) 128 $(call __ndk_warning,WARNING: APP_PLATFORM $(APP_PLATFORM) is larger than android:minSdkVersion $(APP_MIN_PLATFORM_LEVEL) in $(APP_MANIFEST)) 129 endif 130 endif 131 132 # Check that the value of APP_ABI corresponds to known ABIs 133 # 'all' is a special case that means 'all supported ABIs' 134 # 135 # It will be handled in setup-app.mk. We can't hope to change 136 # the value of APP_ABI is the user enforces it on the command-line 137 # with a call like: ndk-build APP_ABI=all 138 # 139 # Because GNU Make makes the APP_ABI variable read-only (any assignments 140 # to it will be ignored) 141 # 142 APP_ABI := $(strip $(APP_ABI)) 143 ifndef APP_ABI 144 # Default ABI is 'armeabi' 145 APP_ABI := armeabi 146 endif 147 ifneq ($(APP_ABI),all) 148 _bad_abis := $(strip $(filter-out $(NDK_ALL_ABIS),$(APP_ABIS))) 149 ifdef _bad_abis 150 $(call __ndk_info,Application $(_app) targets unknown ABI '$(_bad_abis)') 151 $(call __ndk_info,Please fix the APP_ABI definition in $(_application_mk)) 152 $(call __ndk_info,to use a set of the following values: $(NDK_ALL_ABIS)) 153 $(call __ndk_error,Aborting) 154 endif 155 endif 156 157 # If APP_BUILD_SCRIPT is defined, check that the file exists. 158 # If undefined, look in $(APP_PROJECT_PATH)/jni/Android.mk 159 # 160 APP_BUILD_SCRIPT := $(strip $(APP_BUILD_SCRIPT)) 161 ifdef APP_BUILD_SCRIPT 162 _build_script := $(strip $(wildcard $(APP_BUILD_SCRIPT))) 163 ifndef _build_script 164 $(call __ndk_info,Your APP_BUILD_SCRIPT points to an unknown file: $(APP_BUILD_SCRIPT)) 165 $(call __ndk_error,Aborting...) 166 endif 167 APP_BUILD_SCRIPT := $(_build_script) 168 $(call ndk_log, Using build script $(APP_BUILD_SCRIPT)) 169 else 170 _build_script := $(strip $(wildcard $(APP_PROJECT_PATH)/jni/Android.mk)) 171 ifndef _build_script 172 $(call __ndk_info,There is no Android.mk under $(APP_PROJECT_PATH)/jni) 173 $(call __ndk_info,If this is intentional, please define APP_BUILD_SCRIPT to point) 174 $(call __ndk_info,to a valid NDK build script.) 175 $(call __ndk_error,Aborting...) 176 endif 177 APP_BUILD_SCRIPT := $(_build_script) 178 $(call ndk_log, Defaulted to APP_BUILD_SCRIPT=$(APP_BUILD_SCRIPT)) 179 endif 180 181 # Determine whether the application should be debuggable. 182 # - If APP_DEBUG is set to 'true', then it always should. 183 # - If APP_DEBUG is set to 'false', then it never should 184 # - Otherwise, extract the android:debuggable attribute from the manifest. 185 # 186 ifdef APP_DEBUG 187 APP_DEBUGGABLE := $(APP_DEBUG) 188 ifeq ($(NDK_LOG),1) 189 ifeq ($(APP_DEBUG),true) 190 $(call ndk_log,Application '$(_app)' forced debuggable through NDK_DEBUG) 191 else 192 $(call ndk_log,Application '$(_app)' forced *not* debuggable through NDK_DEBUG) 193 endif 194 endif 195 else 196 # NOTE: To make unit-testing simpler, handle the case where there is no manifest. 197 APP_DEBUGGABLE := false 198 ifdef APP_MANIFEST 199 APP_DEBUGGABLE := $(shell $(HOST_AWK) -f $(BUILD_AWK)/extract-debuggable.awk $(call host-path,$(APP_MANIFEST))) 200 endif 201 ifeq ($(NDK_LOG),1) 202 ifeq ($(APP_DEBUGGABLE),true) 203 $(call ndk_log,Application '$(_app)' *is* debuggable) 204 else 205 $(call ndk_log,Application '$(_app)' is not debuggable) 206 endif 207 endif 208 endif 209 210 # LOCAL_BUILD_MODE will be either release or debug 211 # 212 # If APP_OPTIM is defined in the Application.mk, just use this. 213 # 214 # Otherwise, set to 'debug' if android:debuggable is set to TRUE, 215 # and to 'release' if not. 216 # 217 ifneq ($(APP_OPTIM),) 218 # check that APP_OPTIM, if defined, is either 'release' or 'debug' 219 $(if $(filter-out release debug,$(APP_OPTIM)),\ 220 $(call __ndk_info, The APP_OPTIM defined in $(_application_mk) must only be 'release' or 'debug')\ 221 $(call __ndk_error,Aborting)\ 222 ) 223 $(call ndk_log,Selecting optimization mode through Application.mk: $(APP_OPTIM)) 224 else 225 ifeq ($(APP_DEBUGGABLE),true) 226 $(call ndk_log,Selecting debug optimization mode (app is debuggable)) 227 APP_OPTIM := debug 228 else 229 $(call ndk_log,Selecting release optimization mode (app is not debuggable)) 230 APP_OPTIM := release 231 endif 232 endif 233 234 APP_CFLAGS := $(strip $(APP_CFLAGS)) 235 APP_LDFLAGS := $(strip $(APP_LDFLAGS)) 236 237 # Check that APP_STL is defined. If not, use the default value (system) 238 # otherwise, check that the name is correct. 239 APP_STL := $(strip $(APP_STL)) 240 ifndef APP_STL 241 APP_STL := system 242 else 243 $(call ndk-stl-check,$(APP_STL)) 244 endif 245 246 $(if $(call get,$(_map),defined),\ 247 $(call __ndk_info,Weird, the application $(_app) is already defined by $(call get,$(_map),defined))\ 248 $(call __ndk_error,Aborting)\ 249 ) 250 251 $(call set,$(_map),defined,$(_application_mk)) 252 253 # Record all app-specific variable definitions 254 $(foreach __name,$(NDK_APP_VARS),\ 255 $(call set,$(_map),$(__name),$($(__name)))\ 256 ) 257 258 # Record the Application.mk for debugging 259 $(call set,$(_map),Application.mk,$(_application_mk)) 260 261 NDK_ALL_APPS += $(_app) 262