Android: Add githash header to spare rebuilds after new commits

Before, android_version.h got changed at every new commit. Now, we
only change it with new minetest releases. Analogous to how cmake
does it,  we add an android_version_githash.h file that communicates
the git hash to C++ code.

Also, unify VERS_MAJOR, VERS_MINOR and VERS_PATCH variable
calculation inside the whole makefile.
This commit is contained in:
est31 2015-07-31 16:38:36 +02:00
parent 7919318be7
commit c39a85a88d
3 changed files with 38 additions and 24 deletions

1
.gitignore vendored
View File

@ -39,6 +39,7 @@ doc/doxygen_*
CMakeFiles/*
src/CMakeFiles/*
src/Makefile
src/android_config_githash.h
src/android_version.h
src/cmake_config.h
src/cmake_config_githash.h

View File

@ -15,6 +15,14 @@ ROOT = $(shell pwd)
GAMES_TO_COPY = minetest_game
VERSION_MAJOR := $(shell cat $(ROOT)/../../CMakeLists.txt | \
grep ^set\(VERSION_MAJOR\ | sed 's/)/ /' | cut -f2 -d' ')
VERSION_MINOR := $(shell cat $(ROOT)/../../CMakeLists.txt | \
grep ^set\(VERSION_MINOR\ | sed 's/)/ /' | cut -f2 -d' ')
VERSION_PATCH := $(shell cat $(ROOT)/../../CMakeLists.txt | \
grep ^set\(VERSION_PATCH\ | sed 's/)/ /' | cut -f2 -d' ')
################################################################################
# Android Version code
# Increase for each build!
@ -161,7 +169,8 @@ endif
$(OPENAL_TIMESTAMP) $(OGG_TIMESTAMP) \
$(IRRLICHT_TIMESTAMP) $(CURL_TIMESTAMP) \
$(OPENSSL_TIMESTAMP) curl_binary \
$(ROOT)/jni/src/android_version.h
$(ROOT)/jni/src/android_version.h \
$(ROOT)/jni/src/android_version_githash.h
debug : $(PATHCFGFILE)
export NDEBUG=; \
@ -773,7 +782,7 @@ clean_assets :
apk: $(PATHCFGFILE) assets $(ICONV_LIB) $(IRRLICHT_LIB) $(CURL_LIB) $(GMP_LIB) $(LEVELDB_TARGET) \
$(OPENAL_LIB) $(OGG_LIB) prep_srcdir $(ROOT)/jni/src/android_version.h \
sqlite3_download
$(ROOT)/jni/src/android_version_githash.h sqlite3_download
@export NDEBUG=$$NDEBUG; $(MAKE) manifest; \
export PATH=$$PATH:${SDKFOLDER}/platform-tools:${ANDROID_NDK}; \
export ANDROID_HOME=${SDKFOLDER}; \
@ -819,44 +828,47 @@ clean_all :
sleep 1; \
$(RM) -r gen libs obj deps bin Debug and_env
$(ROOT)/jni/src/android_version_githash.h : prep_srcdir
@export VERSION_FILE=${ROOT}/jni/src/android_version_githash.h; \
export VERSION_FILE_NEW=$${VERSION_FILE}.new; \
{ \
echo "#ifndef ANDROID_MT_VERSION_GITHASH_H"; \
echo "#define ANDROID_MT_VERSION_GITHASH_H"; \
export GITHASH=$$(git rev-parse --short=8 HEAD); \
export VERSION_STR="${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}"; \
echo "#define VERSION_GITHASH \"$$VERSION_STR-$$GITHASH-Android\""; \
echo "#endif"; \
} > "$${VERSION_FILE_NEW}"; \
if ! cmp -s $${VERSION_FILE} $${VERSION_FILE_NEW}; then \
echo "android_version_githash.h changed, updating..."; \
mv "$${VERSION_FILE_NEW}" "$${VERSION_FILE}"; \
else \
rm "$${VERSION_FILE_NEW}"; \
fi
$(ROOT)/jni/src/android_version.h : prep_srcdir
@export VERSION_FILE=${ROOT}/jni/src/android_version.h; \
export VERSION_FILE_NEW=$${VERSION_FILE}.new; \
{ \
echo "#ifndef ANDROID_MT_VERSION_H"; \
echo "#define ANDROID_MT_VERSION_H"; \
export CMAKE_FILE=${ROOT}/../../CMakeLists.txt; \
export VERSION_MAJOR=$$(cat $${CMAKE_FILE} | \
grep ^set\(VERSION_MAJOR\ | sed 's/)/ /' | cut -f2 -d' '); \
export VERSION_MINOR=$$(cat $${CMAKE_FILE} | \
grep ^set\(VERSION_MINOR\ | sed 's/)/ /' | cut -f2 -d' '); \
export VERSION_PATCH=$$(cat $${CMAKE_FILE} | \
grep ^set\(VERSION_PATCH\ | sed 's/)/ /' | cut -f2 -d' '); \
echo "#define VERSION_MAJOR $${VERSION_MAJOR}"; \
echo "#define VERSION_MINOR $${VERSION_MINOR}"; \
echo "#define VERSION_PATCH $${VERSION_PATCH}"; \
export GITHASH=$$(git rev-parse --short=8 HEAD); \
export VERSION_STR="$${VERSION_MAJOR}.$${VERSION_MINOR}.$${VERSION_PATCH}";\
echo "#define VERSION_GITHASH \"$$VERSION_STR-$$GITHASH-Android\""; \
echo "#define VERSION_MAJOR ${VERSION_MAJOR}"; \
echo "#define VERSION_MINOR ${VERSION_MINOR}"; \
echo "#define VERSION_PATCH ${VERSION_PATCH}"; \
echo "#define VERSION_STRING STR(VERSION_MAJOR)\".\"STR(VERSION_MINOR)\
\".\"STR(VERSION_PATCH)"; \
echo "#endif"; \
} > $${VERSION_FILE_NEW}; \
if ! cmp -s $${VERSION_FILE} $${VERSION_FILE_NEW}; then \
echo "android_version.h changed, updating..."; \
mv $${VERSION_FILE_NEW} $${VERSION_FILE}; \
mv "$${VERSION_FILE_NEW}" "$${VERSION_FILE}"; \
else \
rm $${VERSION_FILE_NEW}; \
rm "$${VERSION_FILE_NEW}"; \
fi
manifest :
@VERS_MAJOR=$$(cat ${ROOT}/../../CMakeLists.txt | \
grep ^set\(VERSION_MAJOR\ | sed 's/)/ /' | awk '{print $$2;}'); \
VERS_MINOR=$$(cat ${ROOT}/../../CMakeLists.txt | \
grep ^set\(VERSION_MINOR\ | sed 's/)/ /' | awk '{print $$2;}'); \
VERS_PATCH=$$(cat ${ROOT}/../../CMakeLists.txt | \
grep ^set\(VERSION_PATCH\ | sed 's/)/ /' | awk '{print $$2;}'); \
BASE_VERSION="$$VERS_MAJOR.$$VERS_MINOR.$$VERS_PATCH"; \
@BASE_VERSION="${VERS_MAJOR}.${VERS_MINOR}.${VERS_PATCH}"; \
if [ "${NDEBUG}x" != "x" ] ; then \
DBG=''; \
DBG_FLAG="android:debuggable=\"false\""; \

View File

@ -22,6 +22,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#if defined(__ANDROID__)
#include "android_version.h"
#include "android_version_githash.h"
#elif defined(USE_CMAKE_CONFIG_H)
#include "cmake_config_githash.h"
#endif