Merge pull request #1823 from kadamski/building4android Small changes enabling compiling libgit2 for Android.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 317ed1b..78c25b1 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -29,6 +29,8 @@ OPTION( PROFILE "Generate profiling information" OFF )
OPTION( ENABLE_TRACE "Enables tracing support" OFF )
OPTION( LIBGIT2_FILENAME "Name of the produced binary" OFF )
+OPTION( ANDROID "Build for android NDK" OFF )
+
IF(MSVC)
# This option is only available when building with MSVC. By default, libgit2
# is build using the cdecl calling convention, which is useful if you're
@@ -127,7 +129,7 @@ IF (ENABLE_TRACE STREQUAL "ON")
ENDIF()
# Include POSIX regex when it is required
-IF(WIN32 OR AMIGA)
+IF(WIN32 OR AMIGA OR ANDROID)
INCLUDE_DIRECTORIES(deps/regex)
SET(SRC_REGEX deps/regex/regex.c)
ENDIF()
@@ -409,7 +411,7 @@ ENDIF ()
IF (BUILD_EXAMPLES)
FILE(GLOB_RECURSE EXAMPLE_SRC examples/network/*.c examples/network/*.h)
ADD_EXECUTABLE(cgit2 ${EXAMPLE_SRC})
- IF(WIN32)
+ IF(WIN32 OR ANDROID)
TARGET_LINK_LIBRARIES(cgit2 git2)
ELSE()
TARGET_LINK_LIBRARIES(cgit2 git2 pthread)
diff --git a/README.md b/README.md
index 44fd059..9222f3d 100644
--- a/README.md
+++ b/README.md
@@ -108,6 +108,28 @@ See [the wiki]
(https://github.com/libgit2/libgit2/wiki/Building-libgit2-on-Windows)
for more detailed instructions.
+Android
+-------
+
+Extract toolchain from NDK using, `make-standalone-toolchain.sh` script.
+Optionaly, crosscompile and install OpenSSL inside of it. Then create CMake
+toolchain file that configures paths to your crosscompiler (substitude `{PATH}`
+with full path to the toolchain):
+
+ SET(CMAKE_SYSTEM_NAME Linux)
+ SET(CMAKE_SYSTEM_VERSION Android)
+
+ SET(CMAKE_C_COMPILER {PATH}/bin/arm-linux-androideabi-gcc)
+ SET(CMAKE_CXX_COMPILER {PATH}/bin/arm-linux-androideabi-g++)
+ SET(CMAKE_FIND_ROOT_PATH {PATH}/sysroot/)
+
+ SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
+ SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
+ SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
+
+Add `-DCMAKE_TOOLCHAIN_FILE={pathToToolchainFile} -DANDROID=1` to cmake command
+when configuring.
+
Language Bindings
==================================
diff --git a/src/util.c b/src/util.c
index ad76038..d0c326a 100644
--- a/src/util.c
+++ b/src/util.c
@@ -711,7 +711,7 @@ void git__qsort_r(
void *els, size_t nel, size_t elsize, git__sort_r_cmp cmp, void *payload)
{
#if defined(__MINGW32__) || defined(__OpenBSD__) || defined(AMIGA) || \
- defined(__gnu_hurd__) || \
+ defined(__gnu_hurd__) || defined(__ANDROID_API__) || \
(__GLIBC__ == 2 && __GLIBC_MINOR__ < 8)
git__insertsort_r(els, nel, elsize, NULL, cmp, payload);
#elif defined(GIT_WIN32)
diff --git a/tests-clar/odb/loose.c b/tests-clar/odb/loose.c
index 9539bb2..eb6b788 100644
--- a/tests-clar/odb/loose.c
+++ b/tests-clar/odb/loose.c
@@ -3,6 +3,11 @@
#include "posix.h"
#include "loose_data.h"
+#ifdef __ANDROID_API__
+# define S_IREAD S_IRUSR
+# define S_IWRITE S_IWUSR
+#endif
+
static void write_object_files(object_data *d)
{
int fd;