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# GDK 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 gdk_log,Parsing $(_application_mk))
28
29$(call clear-vars, $(GDK_APP_VARS))
30
31# Check that GDK_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 $(GDK_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 __gdk_warning,GDK_DEBUG is defined to the unsupported value '$(GDK_DEBUG)', will be ignored!)
46  endif
47endif
48
49include $(_application_mk)
50
51$(call check-required-vars,$(GDK_APP_VARS_REQUIRED),$(_application_mk))
52
53_map := GDK_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 := $(GDK_PROJECT_PATH)
61endif
62
63# check whether APP_PLATFORM is defined. If not, look for default.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# NOTE: APP_PLATFORM is an experimental feature for now.
68#
69APP_PLATFORM := android-portable
70
71# If APP_BUILD_SCRIPT is defined, check that the file exists.
72# If undefined, look in $(APP_PROJECT_PATH)/jni/Android.mk
73#
74APP_BUILD_SCRIPT := $(strip $(APP_BUILD_SCRIPT))
75ifdef APP_BUILD_SCRIPT
76    _build_script := $(strip $(wildcard $(APP_BUILD_SCRIPT)))
77    ifndef _build_script
78        $(call __gdk_info,Your APP_BUILD_SCRIPT points to an unknown file: $(APP_BUILD_SCRIPT))
79        $(call __gdk_error,Aborting...)
80    endif
81    APP_BUILD_SCRIPT := $(_build_script)
82    $(call gdk_log,  Using build script $(APP_BUILD_SCRIPT))
83else
84    _build_script := $(strip $(wildcard $(APP_PROJECT_PATH)/jni/Android-portable.mk))
85    ifndef _build_script
86        $(call __gdk_info,There is no Android-portable.mk under $(APP_PROJECT_PATH)/jni)
87        $(call __gdk_info,If this is intentional, please define APP_BUILD_SCRIPT to point)
88        $(call __gdk_info,to a valid GDK build script.)
89        $(call __gdk_error,Aborting...)
90    endif
91    APP_BUILD_SCRIPT := $(_build_script)
92    $(call gdk_log,  Defaulted to APP_BUILD_SCRIPT=$(APP_BUILD_SCRIPT))
93endif
94
95# Determine whether the application should be debuggable.
96# - If APP_DEBUG is set to 'true', then it always should.
97# - If APP_DEBUG is set to 'false', then it never should
98# - Otherwise, extract the android:debuggable attribute from the manifest.
99#
100ifdef APP_DEBUG
101  APP_DEBUGGABLE := $(APP_DEBUG)
102  ifdef GDK_LOG
103    ifeq ($(APP_DEBUG),true)
104      $(call gdk_log,Application '$(_app)' forced debuggable through GDK_DEBUG)
105    else
106      $(call gdk_log,Application '$(_app)' forced *not* debuggable through GDK_DEBUG)
107    endif
108  endif
109else
110  # NOTE: To make unit-testing simpler, handle the case where there is no manifest.
111  APP_DEBUGGABLE := false
112  APP_MANIFEST := $(strip $(wildcard $(APP_PROJECT_PATH)/AndroidManifest.xml))
113  ifdef APP_MANIFEST
114    APP_DEBUGGABLE := $(shell $(HOST_AWK) -f $(BUILD_AWK)/extract-debuggable.awk $(APP_MANIFEST))
115  endif
116  ifdef GDK_LOG
117    ifeq ($(APP_DEBUGGABLE),true)
118      $(call gdk_log,Application '$(_app)' *is* debuggable)
119    else
120      $(call gdk_log,Application '$(_app)' is not debuggable)
121    endif
122  endif
123endif
124
125# LOCAL_BUILD_MODE will be either release or debug
126#
127# If APP_OPTIM is defined in the Application.mk, just use this.
128#
129# Otherwise, set to 'debug' if android:debuggable is set to TRUE,
130# and to 'release' if not.
131#
132ifneq ($(APP_OPTIM),)
133    # check that APP_OPTIM, if defined, is either 'release' or 'debug'
134    $(if $(filter-out release debug,$(APP_OPTIM)),\
135        $(call __gdk_info, The APP_OPTIM defined in $(_application_mk) must only be 'release' or 'debug')\
136        $(call __gdk_error,Aborting)\
137    )
138    $(call gdk_log,Selecting optimization mode through Application.mk: $(APP_OPTIM))
139else
140    ifeq ($(APP_DEBUGGABLE),true)
141        $(call gdk_log,Selecting debug optimization mode (app is debuggable))
142        APP_OPTIM := debug
143    else
144        $(call gdk_log,Selecting release optimization mode (app is not debuggable))
145        APP_OPTIM := release
146    endif
147endif
148
149# set release/debug build flags. We always use the -g flag because
150# we generate symbol versions of the binaries that are later stripped
151# when they are copied to the final project's libs/<abi> directory.
152#
153ifeq ($(APP_OPTIM),debug)
154  APP_CFLAGS := -O0 -g $(APP_CFLAGS)
155else
156  APP_CFLAGS := -O2 -DNDEBUG -g $(APP_CFLAGS)
157endif
158
159$(if $(call get,$(_map),defined),\
160  $(call __gdk_info,Weird, the application $(_app) is already defined by $(call get,$(_map),defined))\
161  $(call __gdk_error,Aborting)\
162)
163
164$(call set,$(_map),defined,$(_application_mk))
165
166# Record all app-specific variable definitions
167$(foreach __name,$(GDK_APP_VARS),\
168  $(call set,$(_map),$(__name),$($(__name)))\
169)
170
171GDK_ALL_APPS += $(_app)
172