4

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

Walidix
  • 1,247
  • 5
  • 17
  • 27

1 Answers1

4

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 $< $@
richq
  • 55,548
  • 20
  • 150
  • 144
  • 1
    In case the generated sources depend on each other (#includes), is it possible to force generating all sources before actual compilation starts? – Punit Soni Nov 23 '16 at 03:53
  • 1
    Won’t this put the generated file in the source directory? Is there a way to get it to generate the file into the build directory? – Neil Roberts Nov 15 '18 at 11:39