build-local.mk revision 05be040fdd9fa9d23259d6b6a4aaf4f2aca9c9f2
1# Copyright (C) 2010 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 designed to be called from the 'ndk-build' script
17# or similar wrapper tool.
18#
19
20# Detect the NDK installation path by processing this Makefile's location.
21# This assumes we are located under $NDK_ROOT/build/core/main.mk
22#
23NDK_ROOT := $(dir $(lastword $(MAKEFILE_LIST)))
24NDK_ROOT := $(strip $(NDK_ROOT:%build/core/=%))
25NDK_ROOT := $(NDK_ROOT:%/=%)
26ifeq ($(NDK_ROOT),)
27    # for the case when we're invoked from the NDK install path
28    NDK_ROOT := .
29endif
30ifdef NDK_LOG
31    $(info Android NDK: NDK installation path auto-detected: '$(NDK_ROOT)')
32endif
33ifneq ($(words $(NDK_ROOT)),1)
34    $(info Android NDK: You NDK installation path contains spaces.)
35    $(info Android NDK: Please re-install to a different location to fix the issue !)
36    $(error Aborting.)
37endif
38
39include $(NDK_ROOT)/build/core/init.mk
40
41# ====================================================================
42#
43# If NDK_PROJECT_PATH is not defined, find the application's project
44# path by looking at the manifest file in the current directory or
45# any of its parents. If none is found, try again with 'jni/Android.mk'
46#
47# It turns out that some people use ndk-build to generate static
48# libraries without a full Android project tree.
49#
50# ====================================================================
51
52find-project-dir = $(strip $(call find-project-dir-inner,$1,$2))
53
54find-project-dir-inner = \
55    $(eval __found_project_path := )\
56    $(eval __find_project_path := $1)\
57    $(eval __find_project_file := $2)\
58    $(call find-project-dir-inner-2)\
59    $(__found_project_path)
60
61find-project-dir-inner-2 = \
62    $(call ndk_log,Looking for $(__find_project_file) in $(__find_project_path))\
63    $(eval __find_project_manifest := $(strip $(wildcard $(__find_project_path)/$(__find_project_file))))\
64    $(if $(__find_project_manifest),\
65        $(call ndk_log,    Found it !)\
66        $(eval __found_project_path := $(__find_project_path))\
67        ,\
68        $(eval __find_project_parent := $(patsubst %/,%,$(dir $(__find_project_path))))\
69        $(if $(__find_project_parent),\
70            $(eval __find_project_path := $(__find_project_parent))\
71            $(call find-project-dir-inner-2)\
72        )\
73    )
74
75NDK_PROJECT_PATH := $(strip $(NDK_PROJECT_PATH))
76ifndef NDK_PROJECT_PATH
77    NDK_PROJECT_PATH := $(call find-project-dir,$(strip $(shell pwd)),AndroidManifest.xml)
78endif
79ifndef NDK_PROJECT_PATH
80    NDK_PROJECT_PATH := $(call find-project-dir,$(strip $(shell pwd)),jni/Android.mk)
81endif
82ifndef NDK_PROJECT_PATH
83    $(call __ndk_info,Could not find application project directory !)
84    $(call __ndk_info,Please define the NDK_PROJECT_PATH variable to point to it.)
85    $(call __ndk_error,Aborting)
86endif
87
88# Check that there are no spaces in the project path, or bad things will happen
89ifneq ($(words $(NDK_PROJECT_PATH)),1)
90    $(call __ndk_info,Your Android application project path contains spaces: '$(NDK_PROJECT_PATH)')
91    $(call __ndk_info,The Android NDK build cannot work here. Please move your project to a different location.)
92    $(call __ndk_error,Aborting.)
93endif
94
95NDK_APPLICATION_MK := $(strip $(wildcard $(NDK_PROJECT_PATH)/jni/Application.mk))
96ifndef NDK_APPLICATION_MK
97    NDK_APPLICATION_MK := $(NDK_ROOT)/build/core/default-application.mk
98endif
99
100$(call ndk_log,Found project path: $(NDK_PROJECT_PATH))
101
102# Place all generated files here
103NDK_APP_OUT := $(NDK_PROJECT_PATH)/obj
104
105# Fake an application named 'local'
106_app            := local
107_application_mk := $(NDK_APPLICATION_MK)
108NDK_APPS        := $(_app)
109
110include $(BUILD_SYSTEM)/add-application.mk
111
112# If a goal is DUMP_xxx then we dump a variable xxx instead
113# of building anything
114#
115DUMP_VAR     := $(patsubst DUMP_%,%,$(filter DUMP_%,$(MAKECMDGOALS)))
116MAKECMDGOALS := $(filter-out DUMP_$(DUMP_VAR),$(MAKECMDGOALS))
117
118include $(BUILD_SYSTEM)/setup-imports.mk
119
120ifneq (,$(DUMP_VAR))
121
122# We only support a single DUMP_XXX goal at a time for now.
123ifneq ($(words $(DUMP_VAR)),1)
124    $(call __ndk_error,!!TOO-MANY-DUMP-VARIABLES!!)
125endif
126
127$(foreach _app,$(NDK_APPS),\
128  $(eval include $(BUILD_SYSTEM)/setup-app.mk)\
129)
130
131DUMP_$(DUMP_VAR):
132	@echo $($(DUMP_VAR))
133else
134    # Build it
135    include $(BUILD_SYSTEM)/build-all.mk
136endif
137