#! /bin/sh

# Check that this is not just ./configure. We need to run this
# from R CMD INSTALL, to have the R env vars set.

if [ -z "$R_HOME" ]; then
    echo >&2 R_HOME is not set, are you running R CMD INSTALL?
    exit 1
fi

# Find the R binary we need to use. This is a bit trickier on
# Windows, because it has two architectures. On windows R_ARCH_BIN
# is set, so this should work everywhere.
RBIN="${R_HOME}/bin${R_ARCH_BIN}/R"

CHKLIBR=`${RBIN} CMD config --ldflags 2>/dev/null`
have_libR=no
if test -n "$CHKLIBR"; then
   have_libR=yes
fi

if test "${have_libR}" = yes; then
   REM="rem"
else
   REM=""
fi

cat src/Makevars.in | \
    sed "s/@REM@/${REM}/" > src/Makevars
