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# Note that we first look at the current directory to avoid using 48# absolute NDK_PROJECT_PATH values. This reduces the length of all 49# source, object and binary paths that are passed to build commands. 50# 51# It turns out that some people use ndk-build to generate static 52# libraries without a full Android project tree. 53# 54# ==================================================================== 55 56find-project-dir = $(strip $(call find-project-dir-inner,$1,$2)) 57 58find-project-dir-inner = \ 59 $(eval __found_project_path := )\ 60 $(eval __find_project_path := $1)\ 61 $(eval __find_project_file := $2)\ 62 $(call find-project-dir-inner-2)\ 63 $(__found_project_path) 64 65find-project-dir-inner-2 = \ 66 $(call ndk_log,Looking for $(__find_project_file) in $(__find_project_path))\ 67 $(eval __find_project_manifest := $(strip $(wildcard $(__find_project_path)/$(__find_project_file))))\ 68 $(if $(__find_project_manifest),\ 69 $(call ndk_log, Found it !)\ 70 $(eval __found_project_path := $(__find_project_path))\ 71 ,\ 72 $(eval __find_project_parent := $(patsubst %/,%,$(dir $(__find_project_path))))\ 73 $(if $(__find_project_parent),\ 74 $(eval __find_project_path := $(__find_project_parent))\ 75 $(call find-project-dir-inner-2)\ 76 )\ 77 ) 78 79NDK_PROJECT_PATH := $(strip $(NDK_PROJECT_PATH)) 80ifndef NDK_PROJECT_PATH 81 ifneq (,$(strip $(wildcard AndroidManifest.xml))) 82 NDK_PROJECT_PATH := . 83 else 84 ifneq (,$(strip $(wildcard jni/Android.mk))) 85 NDK_PROJECT_PATH := . 86 endif 87 endif 88endif 89ifndef NDK_PROJECT_PATH 90 NDK_PROJECT_PATH := $(call find-project-dir,.,jni/Android.mk) 91endif 92ifndef NDK_PROJECT_PATH 93 NDK_PROJECT_PATH := $(call find-project-dir,$(strip $(shell pwd)),AndroidManifest.xml) 94endif 95ifndef NDK_PROJECT_PATH 96 NDK_PROJECT_PATH := $(call find-project-dir,$(strip $(shell pwd)),jni/Android.mk) 97endif 98ifndef NDK_PROJECT_PATH 99 $(call __ndk_info,Could not find application project directory !) 100 $(call __ndk_info,Please define the NDK_PROJECT_PATH variable to point to it.) 101 $(call __ndk_error,Aborting) 102endif 103 104# Check that there are no spaces in the project path, or bad things will happen 105ifneq ($(words $(NDK_PROJECT_PATH)),1) 106 $(call __ndk_info,Your Android application project path contains spaces: '$(NDK_PROJECT_PATH)') 107 $(call __ndk_info,The Android NDK build cannot work here. Please move your project to a different location.) 108 $(call __ndk_error,Aborting.) 109endif 110 111NDK_APPLICATION_MK := $(strip $(wildcard $(NDK_PROJECT_PATH)/jni/Application.mk)) 112ifndef NDK_APPLICATION_MK 113 NDK_APPLICATION_MK := $(NDK_ROOT)/build/core/default-application.mk 114endif 115 116$(call ndk_log,Found project path: $(NDK_PROJECT_PATH)) 117 118# Place all generated files here 119NDK_APP_OUT := $(NDK_PROJECT_PATH)/obj 120 121# Fake an application named 'local' 122_app := local 123_application_mk := $(NDK_APPLICATION_MK) 124NDK_APPS := $(_app) 125 126include $(BUILD_SYSTEM)/add-application.mk 127 128# If a goal is DUMP_xxx then we dump a variable xxx instead 129# of building anything 130# 131DUMP_VAR := $(patsubst DUMP_%,%,$(filter DUMP_%,$(MAKECMDGOALS))) 132MAKECMDGOALS := $(filter-out DUMP_$(DUMP_VAR),$(MAKECMDGOALS)) 133 134include $(BUILD_SYSTEM)/setup-imports.mk 135 136ifneq (,$(DUMP_VAR)) 137 138# We only support a single DUMP_XXX goal at a time for now. 139ifneq ($(words $(DUMP_VAR)),1) 140 $(call __ndk_error,!!TOO-MANY-DUMP-VARIABLES!!) 141endif 142 143$(foreach _app,$(NDK_APPS),\ 144 $(eval include $(BUILD_SYSTEM)/setup-app.mk)\ 145) 146 147DUMP_$(DUMP_VAR): 148 @echo $($(DUMP_VAR)) 149else 150 # Build it 151 include $(BUILD_SYSTEM)/build-all.mk 152endif 153