-
Notifications
You must be signed in to change notification settings - Fork 1k
Expand file tree
/
Copy pathconfigure
More file actions
executable file
·186 lines (164 loc) · 7 KB
/
configure
File metadata and controls
executable file
·186 lines (164 loc) · 7 KB
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
#!/usr/bin/env sh
# Find R compilers
CC=`${R_HOME}/bin/R CMD config CC`
CFLAGS=`${R_HOME}/bin/R CMD config CFLAGS`
# compiler and flags to 'cc' file
echo "CC=${CC}" > inst/cc
echo "CFLAGS=${CFLAGS}" >> inst/cc
# gcc compiler info to output #3291
case $CC in gcc*)
GCCV=`${CC} -dumpfullversion -dumpversion`
echo "$CC $GCCV"
esac
# Let's keep this simple. If pkg-config is available, use it. Otherwise print
# the helpful message to aid user if compilation does fail. Note 25 of R-exts:
# "[pkg-config] is available on the machines used to produce the CRAN binary packages"
# This script should pass `checkbashisms` for portability; e.g. CRAN's Solaris 10,
# and R-exts note 24 now suggests 'checkbashisms' as we proposed.
msg=0
NOZLIB=1 # if pkg-config is not available then zlib will be disabled for higher chance of compilation success
pkg-config --version > config.log 2>&1
if [ $? -ne 0 ]; then
echo "*** pkg-config is not installed."
msg=1
else
pkg-config --exists zlib
if [ $? -ne 0 ]; then
echo "*** pkg-config is installed but 'pkg-config --exists zlib' did not return 0."
msg=1
else
NOZLIB=0
lib=`pkg-config --libs zlib`
cflag=`pkg-config --cflags zlib`
echo "$lib" | grep -qE '[-]lz($| )' >> config.log
if [ $? -ne 0 ]; then
echo "*** pkg-config is installed and 'pkg-config --exists zlib' succeeds but"
echo "*** 'pkg-config --libs zlib' returns '${lib}' which does not include the standard -lz."
msg=1
fi
fi
fi
if [ $msg -ne 0 ]; then
echo "*** Compilation will now be attempted and if it works you can ignore this message. In"
echo "*** particular, this should be the case on Mac where zlib is built in or pkg-config"
echo "*** is not installed. However, if compilation fails, try 'locate zlib.h zconf.h' and"
echo "*** ensure the zlib development library is installed :"
echo "*** deb: zlib1g-dev (Debian, Ubuntu, ...)"
echo "*** rpm: zlib-devel (Fedora, EPEL, ...)"
echo "*** There is a zlib in brew for OSX but the built in zlib should work."
echo "*** Note that zlib is required to compile R itself so you may find the advice in the R-admin"
echo "*** guide helpful regarding zlib. On Debian/Ubuntu, zlib1g-dev is a dependency of r-base as"
echo "*** shown by 'apt-cache showsrc r-base | grep ^Build-Depends | grep zlib', and therefore"
echo "*** 'sudo apt-get build-dep r-base' should be sufficient too."
echo "*** To silence this message, please ensure that :"
echo "*** 1) 'pkg-config --exists zlib' succeeds (i.e. \$? -eq 0)"
echo "*** 2) 'pkg-config --libs zlib' contains -lz"
echo "*** Compilation will now be attempted ..."
else
version=`pkg-config --modversion zlib`
echo "zlib ${version} is available ok"
fi
# Test if we have a OPENMP compatible compiler
# Aside: ${SHLIB_OPENMP_CFLAGS} does not appear to be defined at this point according to Matt's testing on
# Linux, and R CMD config SHLIB_OPENMP_CFLAGS also returns 'no information for variable'. That's not
# inconsistent with R-exts$1.2.1.1, though, which states it's 'available for use in Makevars' (so not
# necessarily here in configure).
# printf not echo to pass checkbashisms w.r.t. to the \n
# Specifically use schedule(dynamic) to distinguish incompatibilities in OpenMP runtime on macOS, #7318
cat <<EOF > test-omp.c
#ifdef _OPENMP
#include <omp.h>
#endif
void test_openmp(int * result) {
int sum = 0;
#ifdef _OPENMP
#pragma omp parallel for reduction(+:sum) num_threads(2) schedule(dynamic)
for (int i = 1; i <= 2; ++i) sum += i;
#endif
*result = sum;
}
EOF
test_openmp_variant () {
# Observed in GitHub Actions: if test_openmp_variant is too fast to compile the next object file,
# Make (invoked by R CMD SHLIB) will not consider the previous shared object old enough and won't
# link it anew. --preclean only removes the object files; remove the target as well.
"${R_HOME}"/bin/Rscript -e 'unlink(paste0("test-omp", .Platform$dynlib.ext))'
cflags="${PKG_CFLAGS:+${PKG_CFLAGS} }$1"
libs="${PKG_LIBS:+${PKG_LIBS} }$2"
printf "%s" "* checking if OpenMP works with CFLAGS='$cflags' LIBS='$libs'... "
if ! PKG_CFLAGS="$cflags" PKG_LIBS="$libs" "${R_HOME}"/bin/R CMD SHLIB --preclean --clean test-omp.c >>config.log 2>&1; then
echo "no"
return 1
fi
if ! "${R_HOME}"/bin/Rscript -e '
dll <- paste0("test-omp", .Platform$dynlib.ext)
dyn.load(dll)
ans <- .C("test_openmp", ans = integer(1))$ans
stopifnot(identical(ans, 3L))
' >> config.log 2>&1; then
echo "no"
return 1
fi
export PKG_CFLAGS="${PKG_CFLAGS} ${1}"
export PKG_LIBS="${PKG_LIBS} ${2}"
export R_OPENMP_ENABLED=1
echo "yes"
return 0
}
detect_openmp () {
# OpenMP flags provided in environment variables or specified when configuring R? Does -fopenmp work?
test_openmp_variant "" "" \
|| test_openmp_variant '$(SHLIB_OPENMP_CFLAGS)' '$(SHLIB_OPENMP_CFLAGS)' \
|| test_openmp_variant -fopenmp -fopenmp \
&& return
case "$(uname)" in
Darwin)
# https://mac.r-project.org/openmp
test_openmp_variant "-Xclang -fopenmp" "-lomp" && return
if [ "$(uname -m)" = "arm64" ]; then
HOMEBREW_PREFIX=/opt/homebrew
else
HOMEBREW_PREFIX=/usr/local
fi
test -e "${HOMEBREW_PREFIX}/opt/libomp" \
&& test_openmp_variant \
"-I${HOMEBREW_PREFIX}/opt/libomp/include -Xclang -fopenmp" \
"-L${HOMEBREW_PREFIX}/opt/libomp/lib -lomp" \
&& return
if test -e /usr/local/lib/libomp.dylib \
&& test_openmp_variant "-Xclang -fopenmp" "/usr/local/lib/libomp.dylib"; then
echo "*** Using the OpenMP runtime from /usr/local/lib/libomp.dylib."
echo "*** Please be careful when mixing the result with CRAN binaries."
return
fi
echo "*** All OpenMP tests failed and you're running macOS."
echo "*** Do you need an OpenMP runtime from <https://mac.r-project.org/openmp/>?"
;;
esac
# No support for OpenMP available
export R_OPENMP_ENABLED=0
}
detect_openmp
# Clean up.
rm -f test-omp.* a.out
if [ "${R_OPENMP_ENABLED}" = "0" ]; then
echo "***"
echo "*** OpenMP not supported! data.table uses OpenMP to automatically"
echo "*** parallelize operations like sorting, grouping, file reading, etc."
echo "*** For details on how to install the necessary toolchains on your OS see:"
echo "*** https://github.com/Rdatatable/data.table/wiki/Installation"
echo "*** Continuing installation without OpenMP support..."
echo "***"
fi
# retain user supplied PKG_ env variables, #4664. See comments in Makevars.in too.
sed -e "s|@PKG_CFLAGS@|$PKG_CFLAGS|" -e "s|@PKG_LIBS@|$PKG_LIBS|" src/Makevars.in > src/Makevars
# optional dependency on zlib
if [ "$NOZLIB" = "1" ]; then
echo "*** Compilation without compression support in fwrite"
sed -e "s|@zlib_cflags@|-DNOZLIB|" src/Makevars > src/Makevars.tmp && mv src/Makevars.tmp src/Makevars
sed -e "s|@zlib_libs@||" src/Makevars > src/Makevars.tmp && mv src/Makevars.tmp src/Makevars
else
sed -e "s|@zlib_cflags@|${cflag}|" src/Makevars > src/Makevars.tmp && mv src/Makevars.tmp src/Makevars
sed -e "s|@zlib_libs@|${lib}|" src/Makevars > src/Makevars.tmp && mv src/Makevars.tmp src/Makevars
fi
exit 0