integer-gmp: improve cross-compiling support GmpDerivedConstants.h
[packages/integer-gmp.git] / configure.ac
1 AC_INIT([Haskell integer (GMP)], [0.1], [libraries@haskell.org], [integer])
2
3 AC_CANONICAL_TARGET
4
5 AC_ARG_WITH([cc],
6             [C compiler],
7             [CC=$withval])
8 AC_PROG_CC()
9
10
11 dnl--------------------------------------------------------------------
12 dnl * Deal with arguments telling us gmp is somewhere odd
13 dnl--------------------------------------------------------------------
14
15 AC_ARG_WITH([gmp-includes],
16   [AC_HELP_STRING([--with-gmp-includes],
17     [directory containing gmp.h])],
18     [GMP_INCLUDE_DIRS=$withval; CPPFLAGS="-I$withval"],
19     [GMP_INCLUDE_DIRS=])
20
21 AC_ARG_WITH([gmp-libraries],
22   [AC_HELP_STRING([--with-gmp-libraries],
23     [directory containing gmp library])],
24     [GMP_LIB_DIRS=$withval; LDFLAGS="-L$withval"],
25     [GMP_LIB_DIRS=])
26
27 AC_ARG_WITH([gmp-framework-preferred],
28   [AC_HELP_STRING([--with-gmp-framework-preferred],
29     [on OSX, prefer the GMP framework to the gmp lib])],
30     [GMP_PREFER_FRAMEWORK=YES],
31     [GMP_PREFER_FRAMEWORK=NO])
32
33 dnl--------------------------------------------------------------------
34 dnl * Detect gmp
35 dnl--------------------------------------------------------------------
36
37 HaveLibGmp=NO
38 GMP_LIBS=
39 HaveFrameworkGMP=NO
40 GMP_FRAMEWORK=
41
42 if test "$GMP_PREFER_FRAMEWORK" = "YES"
43 then
44     LOOK_FOR_GMP_FRAMEWORK
45     LOOK_FOR_GMP_LIB
46 else
47     LOOK_FOR_GMP_LIB
48     LOOK_FOR_GMP_FRAMEWORK
49 fi
50 if test "$HaveFrameworkGMP" = "YES" || test "$HaveLibGmp" = "YES"
51 then
52     AC_CHECK_HEADER([gmp.h], , [AC_MSG_ERROR([Cannot find gmp.h])])
53 fi
54
55 dnl--------------------------------------------------------------------
56 dnl * Make sure we got some form of gmp
57 dnl--------------------------------------------------------------------
58
59 AC_SUBST(GMP_INCLUDE_DIRS)
60 AC_SUBST(GMP_LIBS)
61 AC_SUBST(GMP_LIB_DIRS)
62 AC_SUBST(GMP_FRAMEWORK)
63 AC_SUBST(HaveLibGmp)
64 AC_SUBST(HaveFrameworkGMP)
65
66 dnl GMP_INT_TO_CONST(int_expr, var_name)
67 AC_DEFUN([GMP_INT_TO_VAR],
68 [
69     AC_MSG_CHECKING([for $1 size])
70     AC_COMPUTE_INT([$2], [$1],[[#include <stdio.h>
71 #include <stddef.h>
72 #include "gmp.h"
73
74 #define FIELD_OFFSET(s_type, field) offsetof(s_type, field)
75 #define FIELD_SIZE_BITS(s_type, field) (unsigned long)sizeof (__typeof__(((((s_type*)0)->field)))) * 8
76 ]], AC_MSG_ERROR([Failed to compute size of $1]))
77     AC_MSG_RESULT($$2)
78     AC_SUBST($2)
79 ])
80
81 GMP_INT_TO_VAR([[sizeof (MP_INT)]], [SIZEOF_MP_INT])
82 GMP_INT_TO_VAR([[FIELD_OFFSET(MP_INT,_mp_alloc)]],    [OFFSET_MP_INT__mp_alloc])
83 GMP_INT_TO_VAR([[FIELD_SIZE_BITS(MP_INT,_mp_alloc)]], [REP_MP_INT__mp_alloc])
84 GMP_INT_TO_VAR([[FIELD_OFFSET(MP_INT,_mp_size)]],     [OFFSET_MP_INT__mp_size])
85 GMP_INT_TO_VAR([[FIELD_SIZE_BITS(MP_INT,_mp_size)]],  [REP_MP_INT__mp_size])
86 GMP_INT_TO_VAR([[FIELD_OFFSET(MP_INT,_mp_d)]],        [OFFSET_MP_INT__mp_d])
87 GMP_INT_TO_VAR([[FIELD_SIZE_BITS(MP_INT,_mp_d)]],     [REP_MP_INT__mp_d])
88
89 AC_CONFIG_FILES([integer-gmp.buildinfo gmp/config.mk cbits/GmpDerivedConstants.h])
90
91 dnl--------------------------------------------------------------------
92 dnl * Generate the header cbits/GmpDerivedConstants.h
93 dnl--------------------------------------------------------------------
94
95 AC_OUTPUT