diff mbox

[MPFR] Allow building for Android

Message ID 20121010084715.GX4846@xvii.vinc17.org
State New
Headers show

Commit Message

Vincent Lefevre Oct. 10, 2012, 8:47 a.m. UTC
On 2012-10-10 02:05:34 +0200, Bernhard Rosenkränzer wrote:
> mpfr 3.1.1 doesn't compile for Android hosts because it assumes it can
> determine the best decimal point and thousands separator from
> localeconv() if locale.h exists.
> This assumption is not true for Bionic (Android's libc) as it has a
> stripped down locale.h.

I've patched the MPFR trunk by doing a configure test. It is also more
flexible, as the user can also explicitly disable/enable decimal point
and thousands separator support via CFLAGS (useful for tests). I've
attached the patch. Please tell me whether this is OK.

Then I'll apply it to the 3.1 branch.

Note: I think that there should also be a mpfr_buildopt_lconvdpts_p
function in src/buildopt.c (trunk only, for the future MPFR 3.2).
A configure switch to explicitly disable/enable decimal point and
thousands separator support could also be added, though I wonder
whether this would be useful.
diff mbox

Patch

Index: src/mpfr-impl.h
===================================================================
--- src/mpfr-impl.h	(revision 8422)
+++ src/mpfr-impl.h	(revision 8423)
@@ -1170,8 +1170,18 @@ 
    (r) = _size * GMP_NUMB_BITS - _cnt;       \
   } while (0)
 
-/* Needs <locale.h> */
-#ifdef HAVE_LOCALE_H
+/* MPFR_LCONV_DPTS can also be forced to 0 or 1 by the user. */
+#ifndef MPFR_LCONV_DPTS
+# if defined(HAVE_LOCALE_H) && \
+     defined(HAVE_STRUCT_LCONV_DECIMAL_POINT) && \
+     defined(HAVE_STRUCT_LCONV_THOUSANDS_SEP)
+#  define MPFR_LCONV_DPTS 1
+# else
+#  define MPFR_LCONV_DPTS 0
+# endif
+#endif
+
+#if MPFR_LCONV_DPTS
 #include <locale.h>
 /* Warning! In case of signed char, the value of MPFR_DECIMAL_POINT may
    be negative (the ISO C99 does not seem to forbid negative values). */
Index: tests/tsprintf.c
===================================================================
--- tests/tsprintf.c	(revision 8422)
+++ tests/tsprintf.c	(revision 8423)
@@ -832,6 +832,8 @@ 
   return 0;
 }
 
+#if MPFR_LCONV_DPTS
+
 /* Check with locale "da_DK". On most platforms, decimal point is ','
    and thousands separator is '.'; the test is not performed if this
    is not the case or if the locale doesn't exist. */
@@ -878,6 +880,8 @@ 
   return 0;
 }
 
+#endif  /* MPFR_LCONV_DPTS */
+
 /* check concordance between mpfr_asprintf result with a regular mpfr float
    and with a regular double float */
 static int
@@ -1201,8 +1205,10 @@ 
   check_emax ();
 
 #if defined(HAVE_LOCALE_H) && defined(HAVE_SETLOCALE)
+#if MPFR_LCONV_DPTS
   locale_da_DK ();
-
+  /* Avoid a warning by doing the setlocale outside of this #if */
+#endif
   setlocale (LC_ALL, locale);
 #endif
 
Index: acinclude.m4
===================================================================
--- acinclude.m4	(revision 8422)
+++ acinclude.m4	(revision 8423)
@@ -59,6 +59,10 @@ 
 dnl sys/fpu.h - MIPS specific
 AC_CHECK_HEADERS([sys/time.h sys/fpu.h])
 
+dnl Android has a <locale.h>, but not the following members.
+AC_CHECK_MEMBERS([struct lconv.decimal_point, struct lconv.thousands_sep],,,
+  [#include <locale.h>])
+
 dnl Check how to get `alloca'
 AC_FUNC_ALLOCA