From 82b2fc2c8325830667ed780ae5402674c7b9bbf5 Mon Sep 17 00:00:00 2001 From: Krzysztof Adamski Date: Sun, 1 Sep 2013 18:45:36 +0200 Subject: [PATCH 1/4] Create ANDROID build option CMake seems not to support Android as a target and this option lets us test this in CMakeLists.txt. --- CMakeLists.txt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1c70ec2d6..a9b87b8a8 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) From b1447edebc15de58f46e5863e59acb7b4988f304 Mon Sep 17 00:00:00 2001 From: Krzysztof Adamski Date: Sun, 1 Sep 2013 18:47:56 +0200 Subject: [PATCH 2/4] Use git__insertsort_r on Android too. --- src/util.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util.c b/src/util.c index ad7603829..d0c326ae5 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) From 3b75b684a1ac32cbf726cc3d647453a769b8dfe4 Mon Sep 17 00:00:00 2001 From: Krzysztof Adamski Date: Sun, 1 Sep 2013 18:53:07 +0200 Subject: [PATCH 3/4] Define S_IREAD i S_IWRITE for Android. --- tests-clar/odb/loose.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests-clar/odb/loose.c b/tests-clar/odb/loose.c index 9539bb24c..eb6b788b7 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; From 01cd5ae3772a32b29c6bd1cdc1cdc50d98961c1c Mon Sep 17 00:00:00 2001 From: Krzysztof Adamski Date: Sun, 1 Sep 2013 19:43:35 +0200 Subject: [PATCH 4/4] Add instructions about buiding for Android to README.md --- README.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/README.md b/README.md index 44fd059c1..9222f3dcf 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 ==================================