Skip to content

Commit

Permalink
Merge pull request #47 from lavakin/master
Browse files Browse the repository at this point in the history
config mac distrs
  • Loading branch information
HajkD authored Oct 2, 2024
2 parents 7753da2 + 6b7dcb4 commit ec6a58a
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 17 deletions.
57 changes: 41 additions & 16 deletions configure
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env sh

R_HOME=$(R RHOME)
# Find R compilers
CC=`${R_HOME}/bin/R CMD config CC`
CFLAGS=`${R_HOME}/bin/R CMD config CFLAGS`
Expand Down Expand Up @@ -84,6 +85,7 @@ EOF

detect_openmp () {
export PKG_CXXFLAGS=""
export PKG_CPPFLAGS=""
if [ "$(uname)" = "Linux" ]; then

printf "%s" "* checking if R installation supports OpenMP without any extra hints... "
Expand All @@ -109,45 +111,67 @@ detect_openmp () {

if [ "$(uname)" = "Darwin" ]; then
export openmapp="-fopenmp"

if CPPFLAGS="${CPPFLAGS} -Xclang -fopenmp" PKG_LIBS="-lomp" "${R_HOME}/bin/R" CMD SHLIB test-omp.c >> config.log 2>&1; then
# https://mac.r-project.org/openmp
printf "%s" "* checking if R installation supports OpenMP with \"-Xclang -fopenmp\" ... "
printf "%s" "* checking if R installation supports OpenMP with \"-Xclang -fopenmp\" ... "

echo "yes"
export PKG_CFLAGS="${PKG_CFLAGS} -Xclang -fopenmp"
export PKG_LIBS="${PKG_LIBS} -lomp"
export R_OPENMP_ENABLED=1

export PKG_CXXFLAGS="-Xpreprocessor -fopenmp"
return
else
echo "no"
fi

printf "%s" "* checking if R installation supports OpenMP with \"-fopenmp\" ... "

printf "%s" "* checking if R installation supports OpenMP with \"-fopenmp\" ... "
if CPPFLAGS="${CPPFLAGS} -fopenmp" "${R_HOME}/bin/R" CMD SHLIB test-omp.c >> config.log 2>&1; then
echo "yes"
export PKG_CFLAGS="${PKG_CFLAGS} -fopenmp"
export R_OPENMP_ENABLED=1
export PKG_CXXFLAGS="-Xpreprocessor -fopenmp"
return
else
echo "no"
fi

if [ "$(uname -m)" = "arm64" ]; then
HOMEBREW_PREFIX=/usr/local
else
HOMEBREW_PREFIX=/usr/local

HOMEBREW_PREFIX=/usr/local

if [ -e "${HOMEBREW_PREFIX}/opt/libomp" ]; then
printf "%s" "* checking if libomp installation at ${HOMEBREW_PREFIX}/opt/libomp can be used... "
LIBOMP_INCLUDE="-I${HOMEBREW_PREFIX}/opt/libomp/include -Xclang -fopenmp"
LIBOMP_LINK="-L${HOMEBREW_PREFIX}/opt/libomp/lib -lomp"
#if ${CC} ${CFLAGS} ${LIBOMP_INCLUDE} ${LIBOMP_LINK} test-omp.c >> config.log 2>&1; then
echo "yes"
export PKG_CFLAGS="${PKG_CFLAGS} -Xclang -fopenmp"
export PKG_LIBS="${PKG_LIBS} -lomp"
export R_OPENMP_ENABLED=1
export PKG_CXXFLAGS="-Xpreprocessor -fopenmp"
export PKG_CPPFLAGS="-I/usr/local/opt/libomp/include"
return
else
echo "no"
fi

HOMEBREW_PREFIX=/opt/homebrew

if [ -e "${HOMEBREW_PREFIX}/opt/libomp" ]; then
printf "%s" "* checking if libomp installation at ${HOMEBREW_PREFIX}/opt/libomp can be used...
"
printf "%s" "* checking if libomp installation at ${HOMEBREW_PREFIX}/opt/libomp can be used... "
LIBOMP_INCLUDE="-I${HOMEBREW_PREFIX}/opt/libomp/include -Xclang -fopenmp"
LIBOMP_LINK="-L${HOMEBREW_PREFIX}/opt/libomp/lib -lomp"
if ${CC} ${CFLAGS} ${LIBOMP_INCLUDE} ${LIBOMP_LINK} test-omp.c >> config.log 2>&1; then
#if ${CC} ${CFLAGS} ${LIBOMP_INCLUDE} ${LIBOMP_LINK} test-omp.c >> config.log 2>&1; then
echo "yes"
export PKG_CFLAGS="${PKG_CFLAGS} ${LIBOMP_INCLUDE}"
export PKG_LIBS="${PKG_LIBS} ${LIBOMP_LINK}"
export R_OPENMP_ENABLED=1
return
export PKG_CFLAGS="${PKG_CFLAGS} -Xclang -fopenmp"
export PKG_LIBS="-L/opt/homebrew/opt/libomp/lib -lomp"
export R_OPENMP_ENABLED=1
export PKG_CXXFLAGS="-I/opt/homebrew/opt/libomp/include -Xpreprocessor -fopenmp"
export PKG_CPPFLAGS="-I/opt/homebrew/opt/libomp/include"
return
else
echo "no"
fi
fi

fi # uname=Darwin
Expand Down Expand Up @@ -176,6 +200,7 @@ fi
sed -e "s|@PKG_CFLAGS@|$PKG_CFLAGS|" src/Makevars > src/Makevars.tmp && mv src/Makevars.tmp src/Makevars
sed -e "s|@PKG_CXXFLAGS@|$PKG_CXXFLAGS|" 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
sed -e "s|@PKG_CPPFLAGS@|$PKG_CPPFLAGS|" src/Makevars > src/Makevars.tmp && mv src/Makevars.tmp src/Makevars

# optional dependency on zlib
if [ "$NOZLIB" = "1" ]; then
Expand Down
2 changes: 1 addition & 1 deletion src/Makevars.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
PKG_CPPFLAGS = -I/usr/local/opt/libomp/include
PKG_CPPFLAGS = @PKG_CPPFLAGS@
PKG_CXXFLAGS = @PKG_CXXFLAGS@
#PKG_CFLAGS = @PKG_CFLAGS@ @openmp_cflags@ @zlib_cflags@
PKG_LIBS = @PKG_LIBS@ @openmp_cflags@ @zlib_libs@
Expand Down

0 comments on commit ec6a58a

Please sign in to comment.