-
Notifications
You must be signed in to change notification settings - Fork 1
/
configure.ac
executable file
·200 lines (179 loc) · 5.49 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
# Initialization
## setup configure
AC_PREREQ([2.69])
AC_INIT([surveyvoi], [see.DESCRIPTION], [https://github.com/prioritizr/surveyvoi/issues])
## set GMP variables
GMP_NAME="gmp"
GMP_CONFIG_NAME="gmpxx"
GMP_DEB_NAME="libgmp3-dev"
GMP_RPM_NAME="gmp-devel"
GMP_CSW_NAME=""
GMP_BREW_NAME="gmp"
GMP_TEST_C_HEADER="<gmp.h>"
GMP_TEST_CXX_HEADER="<gmpxx.h>"
## set MFRP variables
MPFR_NAME="mpfr"
MPFR_CONFIG_NAME="mpfr"
MPFR_DEB_NAME="libmpfr-dev"
MPFR_RPM_NAME="mpfr-devel"
MPFR_CSW_NAME=""
MPFR_BREW_NAME="mpfr"
MPFR_TEST_HEADER="<mpfr.h>"
# Preliminary processing
## print status message
AC_MSG_CHECKING([if R found])
## ensure C++ is set up as R expects
: ${R_HOME=`R RHOME`}
if test -z "${R_HOME}"; then
AC_MSG_RESULT([no])
AC_MSG_ERROR([Could not determine R_HOME.])
fi
AC_MSG_RESULT([yes])
## verify suitable R version
RBIN="${R_HOME}/bin/R"
RSCRIPT="${R_HOME}/bin/Rscript"
RVER=`"${RSCRIPT}" -e 'writeLines(paste(sep=".", base::version$major, base::version$minor))'`
RVER_MAJOR=`echo ${RVER} | cut -f1 -d"."`
RVER_MINOR=`echo ${RVER} | cut -f2 -d"."`
RVER_PATCH=`echo ${RVER} | cut -f3 -d"."`
if test [$RVER_MAJOR = "development"]; then
AC_MSG_NOTICE([R version: development])
CXX11=`"${RBIN}" CMD config CXX11`
CXX11STD=`"${RBIN}" CMD config CXX11STD`
else
AC_MSG_NOTICE([R version: ${RVER_MAJOR}.${RVER_MINOR}.${RVER_PATCH}])
if test [$RVER_MAJOR -lt 4]; then
AC_MSG_ERROR([surveyvoi is not compatible with R versions before 4.0.0])
else
CXX11=`"${RBIN}" CMD config CXX11`
CXX11STD=`"${RBIN}" CMD config CXX11STD`
fi
fi
# pick all flags for testing from R
: ${CC=`"${RBIN}" CMD config CC`}
: ${CXX=${CXX11} ${CXX11STD}}
: ${CFLAGS=`"${RBIN}" CMD config CFLAGS`}
: ${CPPFLAGS=`"${RBIN}" CMD config CPPFLAGS`}
: ${CXXFLAGS=`"${RBIN}" CMD config CXXFLAGS`}
: ${LDFLAGS=`"${RBIN}" CMD config LDFLAGS`}
# Specify settings
## set up pkgconfig
AC_DEFUN([AC_PROG_PKGCONFIG], [AC_CHECK_PROG(PKGCONFIG,pkg-config,yes)])
AC_PROG_PKGCONFIG
## specify flags and library paths
if test x"${PKGCONFIG}" == x"yes"; then
### GMP settings
if pkg-config --exists ${GMP_CONFIG_NAME}; then
GMP_CFLAGS=`pkg-config --cflags --silence-errors ${GMP_CONFIG_NAME}`
GMP_LIBS=`pkg-config --libs --silence-errors ${GMP_CONFIG_NAME}`
else
GMP_CFLAGS=""
GMP_LIBS="-lgmpxx -lgmp"
fi
### MPFR settings
if pkg-config --exists ${MPFR_CONFIG_NAME}; then
MPFR_CFLAGS=`pkg-config --cflags --silence-errors ${MPFR_CONFIG_NAME}`
MPFR_LIBS=`pkg-config --libs --silence-errors ${MPFR_CONFIG_NAME}`
else
MPFR_CFLAGS=""
MPFR_LIBS="-lmpfr -lgmp"
fi
else
## manually specify defaults if pkg-config missing
GMP_CFLAGS=""
GMP_LIBS="-lgmpxx -lgmp"
MPFR_CFLAGS=""
MPFR_LIBS="-lmpfr -lgmp"
fi
## add flags for subsequent tests
PKG_CPPFLAGS="${CPPFLAGS} ${GMP_CFLAGS} ${MPFR_CFLAGS}"
PKG_LIBS="${LIBS} ${GMP_LIBS} ${MPFR_LIBS}"
CPPFLAGS="${PKG_CPPFLAGS}"
LIBS="${PKG_LIBS}"
## display compiler flags
AC_MSG_NOTICE([Package PKG_CPPFLAGS: ${CPPFLAGS}])
AC_MSG_NOTICE([Package PKG_LIBS: ${LIBS}])
# Verify GMP settings work
## display message
AC_MSG_CHECKING([if ${GMP_NAME} compiles])
## try compiling file with settings
[cat > gmp_test.cpp <<_EOCONF
#include ${GMP_TEST_C_HEADER}
#include ${GMP_TEST_CXX_HEADER}
#if defined(__GNU_MP_VERSION)
#define SUCCESS 0
#else
#define SUCCESS 1
#endif
int main() {
return SUCCESS;
}
_EOCONF]
${CXX} ${CPPFLAGS} -o gmp_test gmp_test.cpp ${LIBS} 2> errors.txt
if test `echo $?` -ne 0 ; then
gmp_ok=no
AC_MSG_RESULT([no])
else
gmp_ok=yes
AC_MSG_RESULT([yes])
fi
## throw error if needed
if test x"${gmp_ok}" == x"no"; then
AC_MSG_NOTICE([Configuration failed because ${GMP_NAME} was not found. Try installing:])
AC_MSG_NOTICE([ * deb: ${GMP_DEB_NAME} (Debian, Ubuntu)])
AC_MSG_NOTICE([ * rpm: ${GMP_RPM_NAME} (Fedora, EPEL)])
AC_MSG_NOTICE([ * brew: ${GMP_BREW_NAME} (Mac OSX)])
AC_MSG_NOTICE([])
AC_MSG_NOTICE([If ${GMP_NAME} is already installed, check that 'pkg-config' is in])
AC_MSG_NOTICE([your PATH and PKG_CONFIG_PATH contains a ${GMP_CONFIG_NAME}.pc file.])
AC_MSG_NOTICE([])
AC_MSG_ERROR([ERROR: Installation failed])
fi
## clean up
rm -f gmp_test errors.txt gmp_test.cpp
# Verify MFPR settings work
## display message
AC_MSG_CHECKING([if ${MPFR_NAME} compiles])
## try compiling file with settings
[cat > mpfr_test.cpp <<_EOCONF
#include ${MPFR_TEST_HEADER}
#if defined(MPFR_VERSION_MAJOR)
#define SUCCESS 0
#else
#define SUCCESS 1
#endif
int main() {
return SUCCESS;
}
_EOCONF]
${CXX} ${CPPFLAGS} -o mpfr_test mpfr_test.cpp ${LIBS} 2> errors.txt
if test `echo $?` -ne 0 ; then
mpfr_ok=no
AC_MSG_RESULT([no])
else
mpfr_ok=yes
AC_MSG_RESULT([yes])
fi
## throw error if needed
if test x"${mpfr_ok}" == x"no"; then
AC_MSG_NOTICE([Configuration failed because ${MPFR_NAME} was not found. Try installing:])
AC_MSG_NOTICE([ * deb: ${MPFR_DEB_NAME} (Debian, Ubuntu)])
AC_MSG_NOTICE([ * rpm: ${MPFR_RPM_NAME} (Fedora, EPEL)])
AC_MSG_NOTICE([ * brew: ${MPFR_BREW_NAME} (Mac OSX)])
AC_MSG_NOTICE([])
AC_MSG_NOTICE([If ${MPFR_NAME} is already installed, check that 'pkg-config' is in])
AC_MSG_NOTICE([your PATH and PKG_CONFIG_PATH contains a ${MPFR_CONFIG_NAME}.pc file.])
AC_MSG_NOTICE([])
AC_MSG_ERROR([ERROR: Installation failed])
fi
## clean up
rm -f mpfr_test errors.txt mpfr_test.cpp
# Export settings
## save settings to Makevars
AC_SUBST([PKG_CPPFLAGS],["${PKG_CPPFLAGS}"])
AC_SUBST([PKG_LIBS],["${PKG_LIBS}"])
AC_CONFIG_FILES([src/Makevars])
# print message indicating success
AC_MSG_NOTICE([configuration successful!])
## finish
AC_OUTPUT