4

I have an Android JNI project I'd like to compile with ndk-build. The project contains of multiple third-party sub projects.

+- jni
   +- Android.mk
   +- my-proj.mk
   +- other-proj.mk
   +- my-proj
      +- a.cpp
      +- b.cpp
   +- other-proj  (third-party)
      +- c.cpp
      +- d.cpp

The idea now is to include/import the makefiles of all sub projects in Android.mk, like this:

LOCAL_PATH := $(call my-dir)

include $(LOCAL_PATH)/my-proj.mk
include $(LOCAL_PATH)/other-proj.mk

other-proj is built as static library. my-proj.mk depends on other-proj and is built as shared library.

Building this project works. However, modifying either my-proj.mk or other-proj.mk doesn't trigger a rebuild of the respective project. Is there a way to do this?

I though I could list the makefiles as dependencies of Android.mk but I couldn't figure out a way. (Listing them under LOCAL_SRC_FILES doesn't work.)

I also read about $(call import-module,foo/bar) which seems to do exactly what I want. However, in this case I had to place the makefiles in a directory adjacent to the project directories (e.g. jni/makefiles/other-proj/Android.mk) but I couldn't figure out how to specify the LOCAL_SRC_FILES. They don't seem to like to be specified with an absolute path or with a .. inside the path. (I can't place the makefiles directly in the sub project directories as they're third-party projects.)

mtvec
  • 17,846
  • 5
  • 52
  • 83
Sebastian Krysmanski
  • 8,114
  • 10
  • 49
  • 91
  • possible duplicate of [Depend on the make file itself](http://stackoverflow.com/questions/4150830/depend-on-the-make-file-itself) – mtvec Apr 28 '12 at 13:18
  • No, it's not a duplicate. The Android makefiles behave slightly different than regular makefiles. For example, editing an Android makefile will rebuild all source files. – Sebastian Krysmanski May 02 '12 at 07:22

2 Answers2

2

I figured out a way to do it, although not with simple includes but rather with $(call import-module,foo/bar).

First change, you need to decide on one of the sub projects being the main project. Let's take my-proj for that. Then the directory structure changes like this:

+- jni
   +- Android.mk
   +- my-proj
      +- a.cpp
      +- b.cpp
   +- other-proj  (third-party)
      +- Android.mk
      +- c.cpp
      +- d.cpp

Basically I renamed my-proj.mk to /Android.mk and other-proj.mk to other-proj/Android.mk.

The main Android.mk then changes to something like this:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
...
LOCAL_STATIC_LIBRARIES := other-proj
include $(BUILD_SHARED_LIBRARY)

$(call import-add-path,$(LOCAL_PATH))
$(call import-module,other-proj)

The other-proj is included in the last line.

Note that the line before the last line sets the module path. Setting the module path from within the makefile via

NDK_MODULE_PATH := $(LOCAL_PATH)

does not work. (If NDK_MODULE_PATH is to be used, it needs to be defined as an environment variable outside of the makefile).

Sebastian Krysmanski
  • 8,114
  • 10
  • 49
  • 91
1

It might not be the most elegant way, but sometimes I modify one of the sources by putting in an extra space or a new line. That seems to wake the compiler up.

AnthonyS
  • 103
  • 10