-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconfigure
executable file
·63 lines (52 loc) · 2.57 KB
/
configure
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
#!/usr/bin/env sh
# Much of this is borrowed from the configure script for R package data.table.
# With thanks to the package authors and contributors.
# Find R compilers
CC=`${R_HOME}/bin/R CMD config CC`
CFLAGS=`${R_HOME}/bin/R CMD config CFLAGS`
# 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). Hence use -fopenmp directly for this detection step.
# printf not echo to pass checkbashisms w.r.t. to the \n
cat <<EOF > test-omp.c
#include <omp.h>
int main() {
return omp_get_num_threads();
}
EOF
# First, try R CMD SHLIB to see if R can already compile
# things using OpenMP without any extra help from data.table
"${R_HOME}/bin/R" CMD SHLIB test-omp.c >/dev/null 2>&1 || R_NO_OPENMP=1
if [ "$R_NO_OPENMP" = "1" ]; then
# Compilation failed -- try forcing -fopenmp instead.
# TODO: doesn't R_NO_OPENMP need to be set to 0 before next line?
${CC} ${CFLAGS} -fopenmp test-omp.c || R_NO_OPENMP=1
# TODO: and then nothing seems to be done with this outcome
else
echo "R CMD SHLIB supports OpenMP without any extra hint"
fi
# Clean up.
rm -f test-omp.* a.out
# Test if the compiler is Apple clang, in which case we need some different flags for OpenMP.
${CC} -v 2>&1 >/dev/null | grep 'Apple clang' >/dev/null || NOT_APPLE_CLANG=1
# Write to Makevars
if [ "$R_NO_OPENMP" = "1" ]; then
echo "*** OpenMP not supported! covidm uses OpenMP to speed up simulations"
echo "*** by running them across multiple processors. For details on how to"
echo "*** install OpenMP, see"
echo "*** https://github.com/nicholasdavies/covidm-alpha/"
echo "*** Continuing installation without OpenMP support..."
sed -e "s|@openmp_cflags@||" src/Makevars.in > src/Makevars
elif [ "$NOT_APPLE_CLANG" = "1" ]; then
sed -e "s|@openmp_cflags@|\$(SHLIB_OPENMP_CFLAGS)|" src/Makevars.in > src/Makevars
else
echo "Apple clang detected."
sed -e "s|@openmp_cflags@|-Xclang -fopenmp|" src/Makevars.in > src/Makevars
fi
# retain user supplied PKG_ env variables.
sed -e "s|@PKG_CXXFLAGS@|$PKG_CXXFLAGS|" src/Makevars > src/Makevars.tmp && mv src/Makevars.tmp src/Makevars
sed -e "s|@PKG_CPPFLAGS@|$PKG_CPPFLAGS|" src/Makevars > src/Makevars.tmp && mv src/Makevars.tmp src/Makevars
sed -e "s|@PKG_LIBS@|$PKG_LIBS|" src/Makevars > src/Makevars.tmp && mv src/Makevars.tmp src/Makevars
exit 0