• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 := $(subst \,/,$(NDK_ROOT))
26NDK_ROOT := $(NDK_ROOT:%/=%)
27ifeq ($(NDK_ROOT),)
28    # for the case when we're invoked from the NDK install path
29    NDK_ROOT := .
30endif
31ifeq ($(NDK_LOG),1)
32    $(info Android NDK: NDK installation path auto-detected: '$(NDK_ROOT)')
33endif
34ifneq ($(words $(NDK_ROOT)),1)
35    $(info Android NDK: You NDK installation path contains spaces.)
36    $(info Android NDK: Please re-install to a different location to fix the issue !)
37    $(error Aborting.)
38endif
39
40include $(NDK_ROOT)/build/core/init.mk
41
42# ====================================================================
43#
44# If NDK_PROJECT_PATH is not defined, find the application's project
45# path by looking at the manifest file in the current directory or
46# any of its parents. If none is found, try again with 'jni/Android.mk'
47#
48# Note that we first look at the current directory to avoid using
49# absolute NDK_PROJECT_PATH values. This reduces the length of all
50# source, object and binary paths that are passed to build commands.
51#
52# It turns out that some people use ndk-build to generate static
53# libraries without a full Android project tree.
54#
55# If NDK_PROJECT_PATH=null, ndk-build make no attempt to look for it, but does
56# need the following variables depending on NDK_PROJECT_PATH to be explicitly
57# specified (from the default, if any):
58#
59#   NDK_OUT
60#   NDK_LIBS_OUT
61#   APP_BUILD_SCRIPT
62#   NDK_DEBUG (optional, default to 0)
63#   Other APP_* used to be in Application.mk
64#
65# This behavior may be useful in an integrated build system.
66#
67# ====================================================================
68
69ifeq ($(HOST_OS),windows)
70# On Windows, defining host-dir-parent is a bit more tricky because the
71# GNU Make $(dir ...) function doesn't return an empty string when it
72# reaches the top of the directory tree, and we want to enforce this to
73# avoid infinite loops.
74#
75#   $(dir C:)     -> C:       (empty expected)
76#   $(dir C:/)    -> C:/      (empty expected)
77#   $(dir C:\)    -> C:\      (empty expected)
78#   $(dir C:/foo) -> C:/      (correct)
79#   $(dir C:\foo) -> C:\      (correct)
80#
81host-dir-parent = $(strip \
82    $(eval __host_dir_node := $(patsubst %/,%,$(subst \,/,$1)))\
83    $(eval __host_dir_parent := $(dir $(__host_dir_node)))\
84    $(filter-out $1,$(__host_dir_parent))\
85    )
86else
87host-dir-parent = $(patsubst %/,%,$(dir $1))
88endif
89
90find-project-dir = $(strip $(call find-project-dir-inner,$(abspath $1),$2))
91
92find-project-dir-inner = \
93    $(eval __found_project_path := )\
94    $(eval __find_project_path := $1)\
95    $(eval __find_project_file := $2)\
96    $(call find-project-dir-inner-2)\
97    $(__found_project_path)
98
99find-project-dir-inner-2 = \
100    $(call ndk_log,Looking for $(__find_project_file) in $(__find_project_path))\
101    $(eval __find_project_manifest := $(strip $(wildcard $(__find_project_path)/$(__find_project_file))))\
102    $(if $(__find_project_manifest),\
103        $(call ndk_log,    Found it !)\
104        $(eval __found_project_path := $(__find_project_path))\
105        ,\
106        $(eval __find_project_parent := $(call host-dir-parent,$(__find_project_path)))\
107        $(if $(__find_project_parent),\
108            $(eval __find_project_path := $(__find_project_parent))\
109            $(call find-project-dir-inner-2)\
110        )\
111    )
112
113NDK_PROJECT_PATH := $(strip $(NDK_PROJECT_PATH))
114
115ifeq (null,$(NDK_PROJECT_PATH))
116
117$(call ndk_log,Make no attempt to look for NDK_PROJECT_PATH.)
118
119else
120
121# To keep paths as short as possible during the build, we first look if the
122# current directory is the top of our project path. If this is the case, we
123# will define NDK_PROJECT_PATH to simply '.'
124#
125# Otherwise, we will use find-project-dir which will first get the absolute
126# path of the current directory the climb back the hierarchy until we find
127# something. The result will always be a much longer definition for
128# NDK_PROJECT_PATH
129#
130ifndef NDK_PROJECT_PATH
131    ifneq (,$(strip $(wildcard AndroidManifest.xml)))
132        NDK_PROJECT_PATH := .
133    else
134        ifneq (,$(strip $(wildcard jni/Android.mk)))
135            NDK_PROJECT_PATH := .
136        endif
137    endif
138endif
139ifndef NDK_PROJECT_PATH
140    NDK_PROJECT_PATH := $(call find-project-dir,.,jni/Android.mk)
141endif
142ifndef NDK_PROJECT_PATH
143    NDK_PROJECT_PATH := $(call find-project-dir,.,AndroidManifest.xml)
144endif
145ifndef NDK_PROJECT_PATH
146    $(call __ndk_info,Could not find application project directory !)
147    $(call __ndk_info,Please define the NDK_PROJECT_PATH variable to point to it.)
148    $(call __ndk_error,Aborting)
149endif
150
151# Check that there are no spaces in the project path, or bad things will happen
152ifneq ($(words $(NDK_PROJECT_PATH)),1)
153    $(call __ndk_info,Your Android application project path contains spaces: '$(NDK_PROJECT_PATH)')
154    $(call __ndk_info,The Android NDK build cannot work here. Please move your project to a different location.)
155    $(call __ndk_error,Aborting.)
156endif
157
158$(call ndk_log,Found project path: $(NDK_PROJECT_PATH))
159
160NDK_APPLICATION_MK := $(strip $(wildcard $(NDK_PROJECT_PATH)/jni/Application.mk))
161
162endif # NDK_PROJECT_PATH == null
163
164ifndef NDK_APPLICATION_MK
165    NDK_APPLICATION_MK := $(NDK_ROOT)/build/core/default-application.mk
166endif
167
168
169# Place all generated intermediate files here
170NDK_APP_OUT := $(strip $(NDK_OUT))
171ifndef NDK_APP_OUT
172  ifeq (null,$(NDK_PROJECT_PATH))
173    $(call __ndk_info,NDK_PROJECT_PATH==null.  Please explicitly set NDK_OUT to directory for all generated intermediate files.)
174    $(call __ndk_error,Aborting.)
175  endif
176  NDK_APP_OUT := $(NDK_PROJECT_PATH)/obj
177endif
178$(call ndk_log,Ouput path for intermediate files: $(NDK_APP_OUT))
179
180# Place all generated library files here.  This is rarely changed since aapt expects the default libs/
181NDK_APP_LIBS_OUT := $(strip $(NDK_LIBS_OUT))
182ifndef NDK_APP_LIBS_OUT
183  ifeq (null,$(NDK_PROJECT_PATH))
184    $(call __ndk_info,NDK_PROJECT_PATH==null.  Please explicitly set NDK_LIBS_OUT to directory for generated library files.)
185    $(call __ndk_error,Aborting.)
186  endif
187  NDK_APP_LIBS_OUT := $(NDK_PROJECT_PATH)/libs
188endif
189$(call ndk_log,Ouput path for generated library files: $(NDK_APP_LIBS_OUT))
190
191# Fake an application named 'local'
192_app            := local
193_application_mk := $(NDK_APPLICATION_MK)
194NDK_APPS        := $(_app)
195
196include $(BUILD_SYSTEM)/add-application.mk
197
198# For cygwin, put generated dependency conversion script here
199# Do not define this variable for other host platforms
200#
201ifeq ($(HOST_OS),cygwin)
202NDK_DEPENDENCIES_CONVERTER := $(NDK_APP_OUT)/convert-dependencies.sh
203endif
204
205# If a goal is DUMP_xxx then we dump a variable xxx instead
206# of building anything
207#
208DUMP_VAR     := $(patsubst DUMP_%,%,$(filter DUMP_%,$(MAKECMDGOALS)))
209MAKECMDGOALS := $(filter-out DUMP_$(DUMP_VAR),$(MAKECMDGOALS))
210
211include $(BUILD_SYSTEM)/setup-imports.mk
212
213ifneq (,$(DUMP_VAR))
214
215# We only support a single DUMP_XXX goal at a time for now.
216ifneq ($(words $(DUMP_VAR)),1)
217    $(call __ndk_error,!!TOO-MANY-DUMP-VARIABLES!!)
218endif
219
220$(foreach _app,$(NDK_APPS),\
221  $(eval include $(BUILD_SYSTEM)/setup-app.mk)\
222)
223
224DUMP_$(DUMP_VAR):
225	@echo $($(DUMP_VAR))
226else
227    # Build it
228    include $(BUILD_SYSTEM)/build-all.mk
229endif
230