Home | History | Annotate | Download | only in core
      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 #
     23 NDK_ROOT := $(dir $(lastword $(MAKEFILE_LIST)))
     24 NDK_ROOT := $(strip $(NDK_ROOT:%build/core/=%))
     25 NDK_ROOT := $(subst \,/,$(NDK_ROOT))
     26 NDK_ROOT := $(NDK_ROOT:%/=%)
     27 ifeq ($(NDK_ROOT),)
     28     # for the case when we're invoked from the NDK install path
     29     NDK_ROOT := .
     30 endif
     31 ifdef NDK_LOG
     32     $(info Android NDK: NDK installation path auto-detected: '$(NDK_ROOT)')
     33 endif
     34 ifneq ($(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.)
     38 endif
     39 
     40 include $(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 # ====================================================================
     56 
     57 find-project-dir = $(strip $(call find-project-dir-inner,$(abspath $1),$2))
     58 
     59 find-project-dir-inner = \
     60     $(eval __found_project_path := )\
     61     $(eval __find_project_path := $1)\
     62     $(eval __find_project_file := $2)\
     63     $(call find-project-dir-inner-2)\
     64     $(__found_project_path)
     65 
     66 find-project-dir-inner-2 = \
     67     $(call ndk_log,Looking for $(__find_project_file) in $(__find_project_path))\
     68     $(eval __find_project_manifest := $(strip $(wildcard $(__find_project_path)/$(__find_project_file))))\
     69     $(if $(__find_project_manifest),\
     70         $(call ndk_log,    Found it !)\
     71         $(eval __found_project_path := $(__find_project_path))\
     72         ,\
     73         $(eval __find_project_parent := $(patsubst %/,%,$(dir $(__find_project_path))))\
     74         $(if $(__find_project_parent),\
     75             $(eval __find_project_path := $(__find_project_parent))\
     76             $(call find-project-dir-inner-2)\
     77         )\
     78     )
     79 
     80 NDK_PROJECT_PATH := $(strip $(NDK_PROJECT_PATH))
     81 ifndef NDK_PROJECT_PATH
     82     ifneq (,$(strip $(wildcard AndroidManifest.xml)))
     83         NDK_PROJECT_PATH := .
     84     else
     85         ifneq (,$(strip $(wildcard jni/Android.mk)))
     86             NDK_PROJECT_PATH := .
     87         endif
     88     endif
     89 endif
     90 ifndef NDK_PROJECT_PATH
     91     NDK_PROJECT_PATH := $(call find-project-dir,.,jni/Android.mk)
     92 endif
     93 ifndef NDK_PROJECT_PATH
     94     NDK_PROJECT_PATH := $(call find-project-dir,$(strip $(shell pwd)),AndroidManifest.xml)
     95 endif
     96 ifndef NDK_PROJECT_PATH
     97     NDK_PROJECT_PATH := $(call find-project-dir,$(strip $(shell pwd)),jni/Android.mk)
     98 endif
     99 ifndef NDK_PROJECT_PATH
    100     $(call __ndk_info,Could not find application project directory !)
    101     $(call __ndk_info,Please define the NDK_PROJECT_PATH variable to point to it.)
    102     $(call __ndk_error,Aborting)
    103 endif
    104 
    105 # Check that there are no spaces in the project path, or bad things will happen
    106 ifneq ($(words $(NDK_PROJECT_PATH)),1)
    107     $(call __ndk_info,Your Android application project path contains spaces: '$(NDK_PROJECT_PATH)')
    108     $(call __ndk_info,The Android NDK build cannot work here. Please move your project to a different location.)
    109     $(call __ndk_error,Aborting.)
    110 endif
    111 
    112 NDK_APPLICATION_MK := $(strip $(wildcard $(NDK_PROJECT_PATH)/jni/Application.mk))
    113 ifndef NDK_APPLICATION_MK
    114     NDK_APPLICATION_MK := $(NDK_ROOT)/build/core/default-application.mk
    115 endif
    116 
    117 $(call ndk_log,Found project path: $(NDK_PROJECT_PATH))
    118 
    119 # Place all generated files here
    120 NDK_APP_OUT := $(NDK_PROJECT_PATH)/obj
    121 
    122 # Fake an application named 'local'
    123 _app            := local
    124 _application_mk := $(NDK_APPLICATION_MK)
    125 NDK_APPS        := $(_app)
    126 
    127 include $(BUILD_SYSTEM)/add-application.mk
    128 
    129 # If a goal is DUMP_xxx then we dump a variable xxx instead
    130 # of building anything
    131 #
    132 DUMP_VAR     := $(patsubst DUMP_%,%,$(filter DUMP_%,$(MAKECMDGOALS)))
    133 MAKECMDGOALS := $(filter-out DUMP_$(DUMP_VAR),$(MAKECMDGOALS))
    134 
    135 include $(BUILD_SYSTEM)/setup-imports.mk
    136 
    137 ifneq (,$(DUMP_VAR))
    138 
    139 # We only support a single DUMP_XXX goal at a time for now.
    140 ifneq ($(words $(DUMP_VAR)),1)
    141     $(call __ndk_error,!!TOO-MANY-DUMP-VARIABLES!!)
    142 endif
    143 
    144 $(foreach _app,$(NDK_APPS),\
    145   $(eval include $(BUILD_SYSTEM)/setup-app.mk)\
    146 )
    147 
    148 DUMP_$(DUMP_VAR):
    149 	@echo $($(DUMP_VAR))
    150 else
    151     # Build it
    152     include $(BUILD_SYSTEM)/build-all.mk
    153 endif
    154