-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure.ac
233 lines (219 loc) · 8.3 KB
/
configure.ac
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
AC_PREREQ([2.72])
AC_INIT([flint],
[0.0.1],
[https://github.com/jaganmn/flint/issues],
[],
[https://github.com/jaganmn/flint])
AC_CONFIG_SRCDIR([man/flint-class.Rd])
AC_CONFIG_HEADERS([src/config.h])
save_IFS="${IFS}"; IFS=.
set x ${PACKAGE_VERSION}
shift; v1=$1; v2=$2; shift; shift; v3=$*
set --
IFS="${save_IFS}"
AC_DEFINE_UNQUOTED([PACKAGE_VERSION_MAJOR], [${v1}],
[Define to the first field of the version string.])
AC_DEFINE_UNQUOTED([PACKAGE_VERSION_MINOR], [${v2}],
[Define to the second field of the version string.])
AC_DEFINE_UNQUOTED([PACKAGE_VERSION_PATCHLEVEL], [${v3}],
[Define to the third field of the version string.])
AC_ARG_VAR([R_HOME],
[R installation directory])
AC_ARG_VAR([PKG_CONFIG],
[path to pkg-config utility])
AC_ARG_VAR([PKG_CONFIG_PATH],
[path to be prepended to pkg-config's default search path])
AC_ARG_VAR([PKG_CONFIG_LIBDIR],
[path overriding pkg-config's default search path])
AC_ARG_VAR([R_FLINT_CPPFLAGS],
[preprocessor options for the C compiler, overriding pkg-config])
AC_ARG_VAR([R_FLINT_CFLAGS],
[debugging and optimization options for the C compiler, overriding pkg-config])
AC_ARG_VAR([R_FLINT_LDFLAGS],
[options (except -lx) for the linker, overriding pkg-config])
AC_ARG_VAR([R_FLINT_LIBS],
[options (only -lx) and libraries for the linker, overriding pkg-config [default=-lflint -lmpfr -lgmp]])
AC_MSG_CHECKING([for R])
if test "x${R_HOME=`R RHOME`}" != "x" &&
test -x "${R_HOME}/bin/R" &&
"${R_HOME}/bin/R" --version >/dev/null 2>&1; then
AC_MSG_RESULT([${R_HOME}/bin/R])
else
AC_MSG_RESULT([no])
AC_MSG_ERROR([install R before configuring R packages])
fi
AC_PROG_CC([])
AC_PROG_SED([])
CC=`"${R_HOME}/bin/R" CMD config CC`
CPPFLAGS=`"${R_HOME}/bin/R" CMD config CPPFLAGS`
CFLAGS=`"${R_HOME}/bin/R" CMD config CFLAGS`
LDFLAGS=`"${R_HOME}/bin/R" CMD config LDFLAGS`
LIBS=
if test "x${R_FLINT_CPPFLAGS+x}" = "x" &&
test "x${R_FLINT_CFLAGS+x}" = "x" &&
test "x${R_FLINT_LDFLAGS+x}" = "x" &&
test "x${R_FLINT_LIBS+x}" = "x"; then
dnl All R_FLINT_* are unset.
AC_PATH_PROGS([PKG_CONFIG], [pkg-config pkgconf], [])
if test "x${PKG_CONFIG}" != "x" &&
test -x "${PKG_CONFIG}" &&
"${PKG_CONFIG}" --version >/dev/null 2>&1; then
dnl We seem to have a working pkg-config.
for pkg in gmp mpfr flint; do
AC_MSG_CHECKING([for ${pkg}.pc in pkg-config search path])
if "${PKG_CONFIG}" --exists ${pkg}; then
AC_MSG_RESULT([yes])
save_CPPFLAGS="${CPPFLAGS}"
save_LDFLAGS="${LDFLAGS}"
save_LIBS="${LIBS}"
pkg_CPPFLAGS=`"${PKG_CONFIG}" --cflags ${pkg}`
pkg_LDFLAGS=`"${PKG_CONFIG}" --libs-only-L --libs-only-other ${pkg}`
pkg_LIBS=`"${PKG_CONFIG}" --libs-only-l ${pkg}`
CPPFLAGS="${pkg_CPPFLAGS} ${R_FLINT_CPPFLAGS} ${CPPFLAGS}"
LDFLAGS="${pkg_LDFLAGS} ${R_FLINT_CPPFLAGS} ${LDFLAGS}"
LIBS="${R_FLINT_LIBS} ${LIBS}"
AC_MSG_NOTICE([checking whether --libs suffices for linking lib${pkg}])
case ${pkg} in
gmp ) pkg_fn=__gmpz_init ;;
mpfr ) pkg_fn=mpfr_init ;;
flint ) pkg_fn=fmpz_init ;;
esac
AC_CHECK_LIB([${pkg}], [${pkg_fn}],
[pkg_found=yes], [pkg_found=no],
[${pkg_LIBS}])
if test "x${pkg_found}" = "xno"; then
pkg_LIBS=`"${PKG_CONFIG}" --libs-only-l --static flint`
AC_MSG_NOTICE([checking whether --libs --static suffices for linking lib${pkg}])
AC_CHECK_LIB([${pkg}], [${pkg_fn}],
[pkg_found=yes], [pkg_found=no],
[${pkg_LIBS}])
if test "x${pkg_found}" = "xno"; then
pkg_CPPFLAGS=
pkg_LDFLAGS=
pkg_LIBS=-l${pkg}
fi
fi
R_FLINT_CPPFLAGS="${pkg_CPPFLAGS} ${R_FLINT_CPPFLAGS}"
R_FLINT_LDFLAGS="${pkg_LDFLAGS} ${R_FLINT_LDFLAGS}"
R_FLINT_LIBS="${pkg_LIBS} ${R_FLINT_LIBS}"
CPPFLAGS="${save_CPPFLAGS}"
LDFLAGS="${save_LDFLAGS}"
LIBS="${save_LIBS}"
else
AC_MSG_RESULT([no])
R_FLINT_LIBS="-l${pkg} ${R_FLINT_LIBS}"
fi
done
dnl Use pkg-config machinery to deduplicate options.
printf "Name: config\n" > config.pc
printf "Description: The config library\n" >> config.pc
printf "URL: https://www.config.org/\n" >> config.pc
printf "Version: %s\n" "${PACKAGE_VERSION}" >> config.pc
printf "Cflags: %s\n" "${R_FLINT_CPPFLAGS}" >> config.pc
printf "Libs: %s\n" "${R_FLINT_LDFLAGS} ${R_FLINT_LIBS}" >> config.pc
R_FLINT_CPPFLAGS=`"${PKG_CONFIG}" --cflags config.pc`
R_FLINT_LDFLAGS=`"${PKG_CONFIG}" --libs-only-L --libs-only-other config.pc`
R_FLINT_LIBS=`"${PKG_CONFIG}" --libs-only-l config.pc`
rm -f config.pc
dnl Handle -lmpfr and -lgmp manually, as we have seen flint.pc and
dnl mpfr.pc misusing Requires and Libs, polluting --libs-only-l output.
for opt in -lmpfr -lgmp; do
R_FLINT_LIBS=`echo "${R_FLINT_LIBS}" | ${SED} -e ":l" -e "s/\(.*\)${opt} \(.*${opt}.*\)/\1\2/" -e "tl"`
done
else
dnl We do not seem to have a working pkg-config.
R_FLINT_LIBS="-lflint -lmpfr -lgmp"
fi
else
dnl At least one R_FLINT_* is set.
: {R_FLINT_LIBS=-lflint -lmpfr -lgmp}
fi
CPPFLAGS="${CPPFLAGS} ${R_FLINT_CPPFLAGS}"
CFLAGS="${CFLAGS} ${R_FLINT_CFLAGS}"
LDFLAGS="${LDFLAGS} ${R_FLINT_LDFLAGS}"
LIBS="${LIBS} ${R_FLINT_LIBS}"
AC_MSG_NOTICE([using R_FLINT_CPPFLAGS="${R_FLINT_CPPFLAGS}"])
AC_MSG_NOTICE([using R_FLINT_CFLAGS="${R_FLINT_CFLAGS}"])
AC_MSG_NOTICE([using R_FLINT_LDFLAGS="${R_FLINT_LDFLAGS}"])
AC_MSG_NOTICE([using R_FLINT_LIBS="${R_FLINT_LIBS}"])
AC_CHECK_LIB([gmp], [__gmpz_init], [:],
[AC_MSG_ERROR([failed to link GNU MP library, see https://gmplib.org/])])
AC_CHECK_LIB([mpfr], [mpfr_init], [:],
[AC_MSG_ERROR([failed to link GNU MPFR library, see https://www.mpfr.org/])])
AC_CHECK_LIB([flint], [fmpz_init], [:],
[AC_MSG_ERROR([failed to link FLINT library, see https://flintlib.org/])])
AC_CHECK_HEADER([gmp.h], [],
[AC_MSG_ERROR([failed to compile GNU MP header, see https://gmplib.org/])])
AC_CHECK_HEADER([mpfr.h], [],
[AC_MSG_ERROR([failed to compile GNU MPFR header, see https://www.mpfr.org/])])
AC_CHECK_HEADER([flint/flint.h], [],
[AC_MSG_ERROR([failed to compile FLINT header, see https://flintlib.org/])])
AC_CHECK_TYPE([mpfr_uprec_t], [],
[AC_MSG_ERROR([GNU MPFR missing unsigned precision type])],
[[#include <mpfr.h>]])
AC_CHECK_TYPE([mpfr_uexp_t], [],
[AC_MSG_ERROR([GNU MPFR missing unsigned exponent type])],
[[#include <mpfr.h>]])
AC_CHECK_FUNC([arb_init], [],
[AC_MSG_ERROR([FLINT missing Arb sublibrary])])
AC_MSG_CHECKING([for int with bit width 32])
AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
int main()
{
return sizeof(int) != 4;
}
]])],
[AC_MSG_RESULT([yes])],
[
AC_MSG_RESULT([no])
AC_MSG_ERROR([package requires a 32-bit int])
])
AC_MSG_CHECKING([for size_t with bit width at least 64])
AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
#include <stddef.h>
int main()
{
return sizeof(size_t) < 8;
}
]])],
[AC_MSG_RESULT([yes])],
[
AC_MSG_RESULT([no])
AC_MSG_ERROR([package requires a >= 64-bit size_t])
])
AC_MSG_CHECKING([for mpfr_exp_t in range of long int])
AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
#include <limits.h>
#include <mpfr.h>
int main()
{
return sizeof(mpfr_exp_t) > sizeof(long int);
}
]])],
[AC_MSG_RESULT([yes])],
[
AC_MSG_RESULT([no])
AC_MSG_ERROR([GNU MPFR exponent can overflow long int])
])
AC_MSG_CHECKING([for consistent limb size])
AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
#include <limits.h>
#include <gmp.h>
#include <flint/flint.h>
int main()
{
return FLINT_BITS != CHAR_BIT * sizeof(mp_limb_t) ||
FLINT_BITS != mp_bits_per_limb;
}
]])],
[AC_MSG_RESULT([yes])],
[
AC_MSG_RESULT([no])
AC_MSG_FAILURE([FLINT and GNU MP installations seem incompatible])
])
AC_SUBST(R_FLINT_CPPFLAGS)
AC_SUBST(R_FLINT_CFLAGS)
AC_SUBST(R_FLINT_LDFLAGS)
AC_SUBST(R_FLINT_LIBS)
AC_CONFIG_FILES([src/Makevars])
AC_OUTPUT