Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Newbie in Android NDK: definition in Android.mk

I am new in Android NDK. I know in every jni/ folder, there is Android.mk file, seems it always start with:

LOCAL_PATH := $(call my-dir)

It defines the LOCAL_PATH, but if translate it to a human-readable launguage, what is this path? Is the LOCAL_PATH points to the jni/ folder or is it the project root ?

For example, I imported an Android project which uses NDK, I checked its Android.mk file, it has something like following:

LOCAL_PATH := $(call my-dir)
...
MY_PLUGINS := XXX YYY ZZZ

MY_PATH := $(LOCAL_PATH)/other/something

Question 1, what does LOCAL_PATH := $(call my-dir) mean, what is the path it points to?

Question 2, Where can I find those MY_PLUGINS, I mean the XXX , YYY and ZZZ, at least I am not able to see it in the project I imported.

Question 3, Where can I find something defined by MYPATH ? I don't see it in project either.

P.S.: (I tried to find it under jni/other/something , but there isn't such file). By the way, what is the name of the script language used in Android.mk ?

like image 947
Leem.fin Avatar asked Nov 05 '13 12:11

Leem.fin


2 Answers

Your best resource here is probably the NDK documentation itself. It is (unfortunately) not hosted on the web, but it is distributed with the NDK. Check the android-ndk-rX/documentation.html file in the NDK you downloaded.

Question 1: from the Android.mk File part of the doc:

LOCAL_PATH := $(call my-dir)

An Android.mk file must begin with the definition of the LOCAL_PATH variable. It is used to locate source files in the development tree. In this example, the macro function 'my-dir', provided by the build system, is used to return the path of the current directory (i.e. the directory containing the Android.mk file itself).

Question 2 and 3: these variables are not "usual" variables in an Android.mk file. They are user-defined variables, and without more details on the project you're using, it's hard to tell much about it. For all I know, MY_PATH should indeed point to jni/other/something.

Concerning your P.S., I don't think the Android.mk file is written in any particular known language: it's a custom language that has some similarities with Makefile.

Hope this helps a little!

like image 196
mbrenon Avatar answered Oct 07 '22 22:10

mbrenon


Q - 1

Android.mk file must begin with LOCAL_PATH variable initialization.

LOCAL_PATH contains the "path to the Android.mk make file", in most case it would be present working directory.

$(call my-dir) is calling macro function "my-dir", defined in /build/core/definitions.mk, you can check the definition of the macro, It finds the directory for ndk-build script to start working.

Q - 2

Android.mk allows users to define local variables and "MY_PLUGINS" is a local variable containing list of plugins, "XXX YYY ZZZ" is list of the plugins he/she might be using within the Android.mk file.

Following are the restrictions on defining a local variable

  1. Names that begin with LOCAL_ (e.g. LOCAL_MODULE)
  2. Names that begin with PRIVATE_, NDK_ or APP_ (used internally)
  3. Lower-case names (used internally, e.g. my-dir)

It is advised to use MY_ prefix for local variable definition

Q - 3

Again MY_PATH is a local variable which contains absolute path to the "/something/other" folder, now this path could contain "XXX YYY ZZZ" plugins or some other useful stuff.

Hope this helps

like image 31
Viraj Tank Avatar answered Oct 07 '22 21:10

Viraj Tank