This repository has been archived by the owner on May 4, 2018. It is now read-only.
/
configure.ac
126 lines (111 loc) · 5.45 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
# Copyright (C) 2014 - 2015 Jack O. Wasey
#
# This file is part of icd9.
#
# icd9 is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# icd9 is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with icd9. If not, see <http:#www.gnu.org/licenses/>.
AC_PREREQ([2.62])
AC_INIT(icd9)
AC_COPYRIGHT(Copyright (C) 2014 - 2015 Jack O. Wasey)
AC_CONFIG_SRCDIR([src])
AC_CONFIG_HEADERS([src/config.h:src/config.h.in])
AC_CONFIG_FILES([src/Makevars])
AC_CONFIG_MACRO_DIR([tools/m4])
echo "Checking whether R_HOME already set? R_HOME = ${R_HOME}"
: ${R_HOME:=`R RHOME`}
if test -z "${R_HOME}"; then
echo "could not determine R_HOME"
exit 1
fi
R_BIN="${R_HOME}/bin/R"
CC=`"${R_BIN}" CMD config CC`
CXX=`"${R_BIN}" CMD config CXX`
CPP=`"${R_BIN}" CMD config CPP`
CFLAGS=`"${R_BIN}" CMD config CFLAGS`
CPPFLAGS=`"${R_BIN}" CMD config CPPFLAGS`
CXXFLAGS=`"${R_BIN}" CMD config CXXFLAGS`
# Writing R Extensions recommends the following, but I don't seem to need it, perhaps because I disable C++11 in some systems when it won't work with OpenMP:
# CXX1X=`"${R_BIN}" CMD config CXX1X`
# CXX1XSTD=`"${R_BIN}" CMD config CXX1XSTD`
CXXFLAGS=`"${R_BIN}" CMD config CXXFLAGS`
LIBS="${PKG_LIBS}"
AC_CHECK_HEADER([string.h])
AC_CHECK_HEADER_STDBOOL
AC_PROG_CC
AC_PROG_CXX
AC_TYPE_SIZE_T
AC_C_INLINE
# this macro is borrowed from R-devel source, and included in the m4 directory
# possibly do this surrounded by push C++ language, but it is probably the same for C and C++ anyway, so I'll just use OPENMP_CFLAGS in Makefile.in
R_OPENMP
# now the R openmp macro has already substituted OPENMP_CFLAGS, so can't do that again
# since some systems have broken OMP libraries
# we also check that the actual package will work
ac_pkg_openmp=no
if test -n "${OPENMP_CFLAGS}"; then
AC_MSG_CHECKING([OpenMP available, but does it work in a package])
AC_LANG_CONFTEST(
[AC_LANG_PROGRAM([[#include <omp.h>]], [[ return omp_get_num_threads (); ]])])
PKG_CFLAGS="${OPENMP_CFLAGS}" PKG_LIBS="${OPENMP_CFLAGS}" "$R_BIN" CMD SHLIB conftest.c 1>&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD && "$R_BIN" --vanilla -q -e "dyn.load(paste('conftest',.Platform\$dynlib.ext,sep=''))" 1>&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD && ac_pkg_openmp=yes
AC_MSG_RESULT([${ac_pkg_openmp}])
fi
# if ${ac_pkg_openmp} = "yes" then we have OMP, otherwise it will be "no"
if test "${ac_pkg_openmp}" = no; then
OPENMP_CFLAGS_IN_PKG=''
else
OPENMP_CFLAGS_IN_PKG=${OPENMP_CFLAGS}
AC_DEFINE(HAVE_R_OPENMP, 1, "Whether OpenMP is available in R environment.")
fi
AC_SUBST(OPENMP_CFLAGS_IN_PKG)
# this only works in C++, since it is a C++ system header...
AC_LANG_PUSH([C++])
# the shell variable $ac_cv_header_parallel_algorithm is generated by this check:
AC_CHECK_HEADERS([parallel/algorithm])
# echo "ac_cv_header_parallel_algorithm = $ac_cv_header_parallel_algorithm"
# more detailed check to actually use parallel glibc in a package:
# stay in C++ mode
ac_pkg_glibc_parallel=no
TEST_GCC_PARALLEL_CXXFLAGS='-D_GLIBCXX_PARALLEL'
if test -n "${OPENMP_CFLAGS}"; then
AC_MSG_CHECKING([is glibc parallel mode working via R, which requires stdlibc++ and OpenMP?])
AC_LANG_CONFTEST(
[AC_LANG_PROGRAM([[#include <parallel/algorithm>]], [[ std::vector<int> v; v.push_back(3); v.push_back(2); __gnu_parallel::sort(v.begin(), v.end()); ]])])
PKG_CFLAGS="${OPENMP_FLAGS}" PKG_LIBS="${OPENMP_CFLAGS}" PKG_CXXFLAGS="${OPENMP_CXXFLAGS} ${TEST_GCC_PARALLEL_CXXFLAGS}" "$R_BIN" CMD SHLIB conftest.cpp 1>&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD && "$R_BIN" --vanilla -q -e "dyn.load(paste('conftest',.Platform\$dynlib.ext,sep=''))" 1>&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD && test "${ac_cv_header_parallel_algorithm}" = yes && ac_pkg_glibc_parallel=yes
AC_MSG_RESULT([${ac_pkg_glibc_parallel}])
fi
AC_LANG_POP([C++])
if test "${ac_pkg_glibc_parallel}" = yes; then
echo "...header is both available, and useable in an R package."
echo "but disabling because it causes R CMD check --as-cran failures with 'printf' and 'abort' found in compiled code, even if parallel/algorithm is not #included."
# AC_DEFINE(WORKING_PARALLEL_ALGORITHM, 1, "Whether glibc parallel STL works in R package.")
# GCC_PARALLEL_CXXFLAGS=${TEST_GCC_PARALLEL_CXXFLAGS}
GCC_PARALLEL_CXXFLAGS=
else
GCC_PARALLEL_CXXFLAGS=""
fi
AC_SUBST(GCC_PARALLEL_CXXFLAGS)
# We do not need valgrind for normal operations, but it helps to know whether present on the platform compiling the code, so headers can be included if present (and instrumentation triggers inserted).
# this uses automake, however, and is designed to check newly compiled code: AX_VALGRIND_CHECK
AC_CHECK_HEADERS([valgrind/valgrind.h])
# C++11, autoconf should determine the correct flags
# https://www.gnu.org/software/autoconf-archive/ax_cxx_compile_stdcxx_11.html
AX_CXX_COMPILE_STDCXX_11(noext,optional)
ICD9_CXX11_FLAG=''
if test "${HAVE_CXX11}" = 1; then
AC_MSG_CHECKING([Have C++11, so set Makevars flag for R])
# ICD9_CXX11_FLAG="AS_ESCAPE([${CXX1XSTD}])"
# the following 'switch' variable is created by the AC CXX test. This is how R configure gets the flag itself.
ICD9_CXX11_FLAG=${switch}
fi
AC_SUBST(ICD9_CXX11_FLAG)
AC_OUTPUT