Permalink
Fetching contributors…
Cannot retrieve contributors at this time
executable file 82 lines (72 sloc) 3.07 KB
#!/bin/bash
# Anticonf script by Jeroen Ooms (2017)
# The script will try 'mariadb_config' and 'mysql_config' to find required
# cflags and ldflags. Make sure this executable is in PATH when installing
# the package. Alternatively, you can set INCLUDE_DIR and LIB_DIR manually:
# R CMD INSTALL --configure-vars='INCLUDE_DIR=/.../include LIB_DIR=/.../lib'
# Library settings
PKG_CONFIG_NAME="libmysqlclient"
PKG_DEB_NAME="libmariadbclient-dev"
PKG_DEB_NAME_DEBIAN="libmariadb-client-lgpl-dev"
PKG_RPM_NAME="mariadb-devel | mysql-devel"
PKG_CSW_NAME="mysql56_dev"
PKG_BREW_NAME="mariadb-connector-c"
PKG_TEST_HEADER="<mysql.h>"
PKG_LIBS="-lmysqlclient"
PKG_LIBS_STATIC="-lmysqlclient -lssl -lcrypto -lz"
# Use mysql_config (on Solaris /opt/csw/bin must be in PATH)
if [ $(command -v mariadb_config) ]; then
PKGCONFIG_CFLAGS=$(mariadb_config --cflags)
PKGCONFIG_LIBS=$(mariadb_config --libs)
elif [ $(command -v mysql_config) ]; then
PKGCONFIG_CFLAGS=$(mysql_config --cflags)
PKGCONFIG_LIBS=$(mysql_config --libs)
fi
# Note that cflags may be empty in case of success
if [ "$INCLUDE_DIR" ] || [ "$LIB_DIR" ]; then
echo "Found INCLUDE_DIR and/or LIB_DIR!"
PKG_CFLAGS="-I$INCLUDE_DIR $PKG_CFLAGS"
PKG_LIBS="-L$LIB_DIR $PKG_LIBS"
elif [ "$PKGCONFIG_CFLAGS" ] || [ "$PKGCONFIG_LIBS" ]; then
echo "Found mysql_config cflags and libs!"
PKG_CFLAGS=${PKGCONFIG_CFLAGS}
PKG_LIBS=${PKGCONFIG_LIBS}
elif [[ "$OSTYPE" == "darwin"* ]]; then
if [ $(command -v brew) ]; then
BREWDIR=$(brew --prefix)
else
curl -sfL "https://jeroen.github.io/autobrew/$PKG_BREW_NAME" > autobrew
source autobrew
fi
PKG_CFLAGS="-I$BREWDIR/opt/mariadb-connector-c/include/mariadb"
PKG_LIBS="-L$BREWDIR/opt/{openssl/lib,mariadb-connector-c/lib/mariadb} $PKG_LIBS_STATIC"
fi
# Find compiler
CC=$(${R_HOME}/bin/R CMD config CC)
CFLAGS=$(${R_HOME}/bin/R CMD config CFLAGS)
CPPFLAGS=$(${R_HOME}/bin/R CMD config CPPFLAGS)
# For debugging
echo "Using PKG_CFLAGS=$PKG_CFLAGS"
echo "Using PKG_LIBS=$PKG_LIBS"
# Test configuration
echo "#include $PKG_TEST_HEADER" | ${CC} ${CPPFLAGS} ${PKG_CFLAGS} ${CFLAGS} -E -xc - >/dev/null 2>&1 || R_CONFIG_ERROR=1;
# Customize the error
if [ $R_CONFIG_ERROR ]; then
echo "------------------------- ANTICONF ERROR ---------------------------"
echo "Configuration failed because $PKG_CONFIG_NAME was not found. Try installing:"
echo " * deb: $PKG_DEB_NAME_DEBIAN (Debian, Ubuntu 16.04)"
echo " $PKG_DEB_NAME (Ubuntu 14.04)"
echo " * rpm: $PKG_RPM_NAME (Fedora, CentOS, RHEL)"
echo " * csw: $PKG_CSW_NAME (Solaris)"
echo " * brew: $PKG_BREW_NAME (OSX)"
echo "If $PKG_CONFIG_NAME is already installed, check that 'pkg-config' is in your"
echo "PATH and PKG_CONFIG_PATH contains a $PKG_CONFIG_NAME.pc file. If pkg-config"
echo "is unavailable you can set INCLUDE_DIR and LIB_DIR manually via:"
echo "R CMD INSTALL --configure-vars='INCLUDE_DIR=... LIB_DIR=...'"
echo "--------------------------------------------------------------------"
exit 1;
fi
# Write to Makevars
sed -e "s|@cflags@|$PKG_CFLAGS|" -e "s|@libs@|$PKG_LIBS|" src/Makevars.in > src/Makevars
# Success
exit 0