Peter M
Peter M

Reputation: 1988

Add pre-build step to android ndk-build module for header dependency?

Basically, what I'd like to do in an Android.mk file is:

LOCAL_MODULE := foo
$(LOCAL_MODULE): pre-build
pre-build:
    @echo HI
.PHONY: pre-build
# ...
include $(BUILD_SHARED_LIBRARY)

The ndk-build system does work for ndk-build foo, and the pre-build step works, but if you use this library in an application, it won't do the pre-build step.

In particular, I'm trying to generate a header file (with version/date stamps etc) that is placed in the path that is used in LOCAL_EXPORT_C_INCLUDES such that modules that consume the library can enjoy the header file.

Upvotes: 4

Views: 3718

Answers (2)

Georgie
Georgie

Reputation: 2475

Here's a way I found to do a pre-build step when building a dynamic library for one or more architectures (ABIs). This may not work in all situations.

Create an Application.mk file (if you don't have one already) with the following:

all: pre_build
pre_build:
    echo "This is the pre-build"

Note that using 'all' as above ends up doing a pre-build in Application.mk, and a post-build in Android.mk.

Upvotes: 1

Peter M
Peter M

Reputation: 1988

Here's what I've done, as a bit of a hack.

It seems you can add a post-build step, fairly easily, but not a pre-build step.

After you include the build process, you can add a dependency to $(LOCAL_BUILT_MODULE) which will effectively be a post-build process that is always executed.

include $(BUILD_SHARED_LIBRARY)
$(LOCAL_BUILT_MODULE): post_build

post_build:
    $echo Hi, I'm post-build.

If you need to be fancy and use, for example, things on your $(LOCAL_PATH), then

include $(BUILD_SHARED_LIBRARY)
$(LOCAL_BUILT_MODULE): post_build

define gen_post_build
post_build:
    $(hide) python $(1)/MyScript.py 
endef

$(eval $(call gen_post_build,$(LOCAL_PATH)))

Upvotes: 2

Related Questions