Walidix
Walidix

Reputation: 1277

How to deal with source code file auto-generated in the build process

I'm trying to build a third party library which uses auto-generated source code files. In normal case, this kind of files is generated by gnu build tools. My question is How can I tell the Android NDK build tools to generate and build this kind of files.

Thanks in advance

Upvotes: 4

Views: 2511

Answers (1)

richq
richq

Reputation: 56438

The ndk-build tool is a thin wrapper script that calls GNU Make with some command line arguments. You can add any build rules to your Android.mk file that you like written in make, including generating source files.

If you have the generated file name in the LOCAL_SRC_FILES variable together with the rule to generate this file, make will figure it out. This is a minimal example Android.mk that copies "generated.in" to "generated.c" and then compiles it:

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := ndkexample
LOCAL_SRC_FILES := generated.c
$(LOCAL_PATH)/generated.c : $(LOCAL_PATH)/generated.in
    echo "Generate file"
    cp $< $@

Upvotes: 4

Related Questions