Android NDK: how to include Android.mk into another Android.mk (hierarchical project structure)?

Viewed 59627

Looks like it's possible, but my script produces odd results:

LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)

include $(LOCAL_PATH)/libos/Android.mk
include $(LOCAL_PATH)/libbase/Android.mk
include $(LOCAL_PATH)/utils/Android.mk

LOCAL_MODULE := native
include $(BUILD_SHARED_LIBRARY)

Only the first include is being parsed fine, other Android.mk files are being seacrhed at odd paths. Suggestions?

Update: I have broken my building environment... It was OK in the office, but at home LOCAL_PATH:= $(call my-dir) defines LOCAL_PATH to NDK dir instead of project dir. This is my batch for building:

set BASHPATH=K:\cygwin\bin\bash
set PROJECTDIR=/cygdrive/h/Alex/Alex/Work/Android/remote-android
set NDKDIR=/cygdrive/h/Alex/Programming_Docs/Android/android-ndk-r6/ndk-build
set APP_BUILD_SCRIPT=/cygdrive/h/Alex/Alex/Work/Android/project/jni/Android.mk
set DEV_ROOT=h:/Alex/Alex/Work/Android/project

%BASHPATH% --login -c "cd %PROJECTDIR% && %NDKDIR%"

Update: I absolutely don't understand how does this thing compose paths. I'm getting errors with paths like "/cygdrive/d/project/jni//cygdrive/d/Soft/project/jni/libos/src/libos.cpp'. This is after I decided to specify all files in the root Android.mk instead of including submodules.

Update 2: No luck, this doesn't work either:

LOCAL_PATH:= $(call my-dir)
# Include makefiles here.
include $(LOCAL_PATH)/libos/Android.mk
include $(LOCAL_PATH)/libbase/Android.mk
include $(LOCAL_PATH)/utils/Android.mk

# Clear variables here.
 include $(CLEAR_VARS)
6 Answers

My approah is like this:

LOCAL_PATH:= $(call my-dir)

# Clear variables here.
include $(CLEAR_VARS)

# Current module settings.
LOCAL_MODULE := native
# setup some source files
LOCAL_SRC_FILES := file1.c file2.c
# setup some includes
LOCAL_C_INCLUDES := $(LOCAL_PATH)/libos/include
# setup the included libs for the main module
LOCAL_STATIC_LIBRARIES := libos libbase utils # note that order matters here

include $(BUILD_SHARED_LIBRARY)

# Include makefiles here. Its important that these 
# includes are done after the main module, explanation below.

# create a temp variable with the current path, because it 
# changes after each include
ZPATH := $(LOCAL_PATH)

include $(ZPATH)/libos/Android.mk
include $(ZPATH)/libbase/Android.mk
include $(ZPATH)/utils/Android.mk

Note, that includes are done after the setup of current module variables. This is needed because each include modifies the LOCAL_PATH variable (actually it modifes what $(call my-dir) returns) and thats why includes must be done last.

This will automatically compile all included modules (or clean then if called with clean) and then link with all the included libraries.

This setup was tested in a real project and works correctly.

answer taken from here: https://docs.google.com/document/d/1jDmWgVgorTY_njX68juH5vt0KY_FXWgxkxmi2v_W_a4/edit

Related