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 := $(NDK_ROOT:%/=%)
     26 ifeq ($(NDK_ROOT),)
     27     # for the case when we're invoked from the NDK install path
     28     NDK_ROOT := .
     29 endif
     30 ifdef NDK_LOG
     31     $(info Android NDK: NDK installation path auto-detected: '$(NDK_ROOT)')
     32 endif
     33 ifneq ($(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.)
     37 endif
     38 
     39 include $(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 
     52 find-project-dir = $(strip $(call find-project-dir-inner,$1,$2))
     53 
     54 find-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 
     61 find-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 
     75 NDK_PROJECT_PATH := $(strip $(NDK_PROJECT_PATH))
     76 ifndef NDK_PROJECT_PATH
     77     NDK_PROJECT_PATH := $(call find-project-dir,$(strip $(shell pwd)),AndroidManifest.xml)
     78 endif
     79 ifndef NDK_PROJECT_PATH
     80     NDK_PROJECT_PATH := $(call find-project-dir,$(strip $(shell pwd)),jni/Android.mk)
     81 endif
     82 ifndef 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)
     86 endif
     87 
     88 # Check that there are no spaces in the project path, or bad things will happen
     89 ifneq ($(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.)
     93 endif
     94 
     95 NDK_APPLICATION_MK := $(strip $(wildcard $(NDK_PROJECT_PATH)/jni/Application.mk))
     96 ifndef NDK_APPLICATION_MK
     97     NDK_APPLICATION_MK := $(NDK_ROOT)/build/core/default-application.mk
     98 endif
     99 
    100 $(call ndk_log,Found project path: $(NDK_PROJECT_PATH))
    101 
    102 # Place all generated files here
    103 NDK_APP_OUT := $(NDK_PROJECT_PATH)/obj
    104 
    105 # Fake an application named 'local'
    106 _app            := local
    107 _application_mk := $(NDK_APPLICATION_MK)
    108 NDK_APPS        := $(_app)
    109 
    110 include $(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 #
    115 DUMP_VAR     := $(patsubst DUMP_%,%,$(filter DUMP_%,$(MAKECMDGOALS)))
    116 MAKECMDGOALS := $(filter-out DUMP_$(DUMP_VAR),$(MAKECMDGOALS))
    117 
    118 ifneq (,$(DUMP_VAR))
    119 
    120 # We only support a single DUMP_XXX goal at a time for now.
    121 ifneq ($(words $(DUMP_VAR)),1)
    122     $(call __ndk_error,!!TOO-MANY-DUMP-VARIABLES!!)
    123 endif
    124 
    125 $(foreach _app,$(NDK_APPS),\
    126   $(eval include $(BUILD_SYSTEM)/setup-app.mk)\
    127 )
    128 
    129 DUMP_$(DUMP_VAR):
    130 	@echo $($(DUMP_VAR))
    131 else
    132     # Build it
    133     include $(BUILD_SYSTEM)/build-all.mk
    134 endif
    135