Subject: Patch for Android NDK build

Patch for Android NDK build

From: <wayne_at_tinmith.net>
Date: Thu, 12 Apr 2012 14:59:42 -0700

Hi everyone,

I have noticed a problem with building c-ares on the Android NDK. The
problem is that c-ares currently only checks for #ifdef ANDROID but it
really also needs to check for __ANDROID__ as well.

I noticed recently that a patch was submitted by Cedric Deltheil to the
CURL sources on 20 Dec 2011, which is designed to correctly test for
building with the Android NDK. I have included a copy of his comments and
patches for everyone to review at the bottom of this email.

I think a similar patch should also be applied to c-ares as well:

diff --git a/ares_init.c b/ares_init.c
index ea2a978..3d29cfe 100644
--- a/ares_init.c
+++ b/ares_init.c
@@ -60,7 +60,7 @@
 #include <ctype.h>
 #include <time.h>

-#ifdef ANDROID
+#if defined(ANDROID) || defined(__ANDROID__)
 #include <sys/system_properties.h>
 #endif

@@ -971,7 +971,7 @@ DhcpNameServer
   }
   status = ARES_EOF;

-#elif defined(ANDROID)
+#elif defined(ANDROID) || defined(__ANDROID__)
   char value[PROP_VALUE_MAX]="";
   __system_property_get("net.dns1", value);
   status = config_nameserver(&servers, &nservers, value);

thanks,
Wayne

------------- attached original patch from curl below --------------

Author: CeĢdric Deltheil <cedric_at_moodstocks.com> 2011-12-20 03:23:11
Committer: Daniel Stenberg <daniel_at_haxx.se> 2011-12-20 11:18:14
Parent: 8d0a504f0d34c2471393ef23fb2345c73c5d4746 (CURLOPT_DNS_SERVERS: set
name servers if possible)
Child: c834213ad52c52431e9ca597862dc81839cabe84 (FTP: perform active
connections non-blocking)
Branches: master, remotes/origin/master
Follows: curl-7_23_1
Precedes: curl-7_24_0

    curl.h: add __ANDROID__ macro check

    When working with the Android Standalone Toolchain the compiler defines
    this macro:

      /path/to/arm-linux-androideabi-gcc -E -dM - < /dev/null \
      | grep -i android
      #define __ANDROID__ 1

    We really need to check both ANDROID and __ANDROID__ since I've observed
    that:

    * if you use Android.mk file(s) and the 'ndk-build' script (aka vanilla
    way), ANDROID is predefined (see -DANDROID extra C flag),

    * if you use the Android Standalone Toolchain, then __ANDROID__ is
    predefined as stated by the compiler

----------------------------- include/curl/curl.h
-----------------------------
index 8f82348..1e908a3 100644
@@ -69,7 +69,7 @@
    require it! */
 #if defined(_AIX) || defined(__NOVELL_LIBC__) || defined(__NetBSD__) || \
     defined(__minix) || defined(__SYMBIAN32__) || defined(__INTEGRITY) || \
- defined(ANDROID) || \
+ defined(ANDROID) || defined(__ANDROID__) || \
    (defined(__FreeBSD_version) && (__FreeBSD_version < 800000))
 #include <sys/select.h>
 #endif
Received on 2012-04-15