Search code examples
java-native-interfaceandroid.mk

Need to understand Andorid.mk better


I have read all the Android.mk intro, and reviewed a number of posts on it here on this forum. And still am not sure how to apply it to what I am trying to do. I am just trying to have access to native library files some of which are a couple of levels below my JNI directory. What I did was to put a symlink in my JNI directory to my source, called tbd, and put the following lines in my Android.mk

LOCAL_PATH := $(call my-dir)
include $(call all-subdir-makefiles)
include $(CLEAR_VARS)
LOCAL_MODULE    := HelloJNI 
LOCAL_C_INCLUDES += $(LOCAL_PATH)/tbd
LOCAL_SRC_FILES := HelloJNI.c  manifest.c 
LOCAL_STATIC_LIBRARIES := \
libtbd_service \
libtbd_common \
libc

I don't know how to get visibility into some of the files in tbd directory. I am trying to call a function in a file in libc direcoty, which is a couple of levels below my jni folder, and I get the message "file not found". I saw a post, in which someone suggested the following:

FILE_LIST := $(wildcard $(LOCAL_PATH)/*.cpp)
FILE_LIST += $(wildcard $(LOCAL_PATH)/**/*.cpp)
FILE_LIST += $(wildcard $(LOCAL_PATH)/**/**/*.cpp)
LOCAL_SRC_FILES := $(FILE_LIST:$(LOCAL_PATH)/%=%)

Does this mean I have to do this for every directory in /tbd? There has to be a more efficient way to do this.

Someone else suggested...

LOCAL_SRC_FILES += $(patsubst $(LOCAL_PATH)/%, %, $(wildcard folder/**/*.cpp))

I can not even follow this:-( What does % do in this line? Would someone explain what this command is doing please?

@alijandro; thanks. So all I have to find out is how many levels of directory structure I have. Hey do you know about the static or shared libraries? Android.mk documents say "The BUILD_SHARED_LIBRARY is a variable provided by the build system that points to a GNU Makefile script that is in charge of collecting all the information you defined in LOCAL_XXX variables since the latest 'include $(CLEAR_VARS)' and determine what to build, and how to do it exactly. " So I don't know the details of how it would do all of this or what it means. Would it perhaps do a recursive search of the mentioned source files??


Solution

  • FILE_LIST := $(wildcard $(LOCAL_PATH)/*.cpp)
    FILE_LIST += $(wildcard $(LOCAL_PATH)/**/*.cpp)
    FILE_LIST += $(wildcard $(LOCAL_PATH)/**/**/*.cpp)
    LOCAL_SRC_FILES := $(FILE_LIST:$(LOCAL_PATH)/%=%)
    

    The statements above will get a list of .cpp files in a maximize of three subdirectory. It uses the makefile built-in function for file name operation wildcard.

    LOCAL_SRC_FILES += $(patsubst $(LOCAL_PATH)/%, %, $(wildcard folder/**/*.cpp))
    

    Similarly, the statement above uses the built-in function pattern substitute $(patsubst pattern,replacement,text), which means finding the pattern in text and replace them with replacement. The pattern % denotes any characters in makefile.

    You could refer here for more information about makefile.