How to pass macro definition which generating from ShellScripts to source code in Android.mk

424 views Asked by At

Using Android NDK,I want to get git version in my c++ source code. so i implement my function like this:

const char *GetGitVersion()
{
#ifdef GIT_VERSION
   return GIT_VERSION;
#else
   return NULL;
#endif
}

in Android.mk:

LOCAL_CPPFLAGS += -D'GIT_VERSION="$(shell $(LOCAL_PATH)/get_version.sh)"'

in get_version.sh:

GIT_VERSION=`git --no-pager log --abbrev=7 -n 1 --pretty=format:"%h %ci" HEAD | \
                  awk '{gsub("-", "");print $2"-"$1}'`
echo Git-$GIT_VERSION

My problem is :

When i first build my program,it works.But when i have submited my changes and the git version has changed, the Compiler has not build my source code. Function GetGitVersion return previous version. Why? is there any other method to implement my requirement?

Sorry,my English is poor!

1

There are 1 answers

1
ph0b On

you need to recompile your lib so the function implementation can be updated.

However, if there are no changes in the source file where GetGitVersion() is defined, it may not be recompiled.

To force a recompilation of your sourcefile, you can use touch source.c (linux/unix) or copy /b source.c +,, (windows) to update your file last modification time.