https://github.com/ecrc/exageostatR
Raw File
Tip revision: bf5de52a881dab0ea51872954b689640e5c56622 authored by Sameh Abdulah on 06 March 2023, 02:47:39 UTC
Update README.md
Tip revision: bf5de52
configure
#!/usr/bin/env bash

# Configure script for R package generation

export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:${R_HOME}/exageostat/lib/pkgconfig
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:$R_LIBS_USER/exageostat/lib/pkgconfig
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:$R_LIBS/exageostat/lib/pkgconfig
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:$R_PACKAGE_DIR/exageostat/lib/pkgconfig # if user uses -l option

export BASEDIR=$(pwd)

TMPDIR=$BASEDIR/_$$
BUILD_DEPENDENCIES='TRUE'
err=0

CUDA_VALUE="OFF"
MPI_VALUE="OFF"

mkdir -p "$TMPDIR"
SETUP_DIR=${R_PACKAGE_DIR:-''}

print_usage() {
	echo "usage: $0 [--enable-mpi|--disable-mpi] [--enable-cuda|--disable-cuda] [--build-deps|--no-build-deps]
	[--prefix /path/to/install]"
}


while [ -n "$1"  ]
do
	case "$1" in
		--enable-cuda)
			CUDA_VALUE="ON"
			shift
			;;
    --disable-cuda)
      CUDA_VALUE="OFF"
      shift
      ;;
		--enable-mpi)
			MPI_VALUE="ON"
			shift
			;;
		--disable-mpi)
			MPI_VALUE="OFF"
			shift
			;;
		--build-deps)
			BUILD_DEPENDENCIES='true'
			shift
			;;
		--no-build-deps)
			BUILD_DEPENDENCIES='false'
			shift
			;;
		--prefix)
			shift
			SETUP_DIR=$1
			# Set this paths as rpath during compilation
			r_paths="-Wl,-rpath=$SETUP_DIR/lib -L$SETUP_DIR/lib "
			echo "LDFLAGS += $r_paths " >> "$BASEDIR"/src/Makefile
			shift
			;;
		--help|-h)
			print_usage
			exit 0
			;;
		*)
			print_usage
			exit 1
			;;
	esac
done


if [ -z "$SETUP_DIR" ]; then
	# Use R Library Paths for setup dir
	mapfile -t arr < <(Rscript -e '.libPaths()')
	for i in ${!arr[*]};
	do
		dir=$(echo "${arr[$i]}"| awk  '{print $2}'| tr -d \")
		if [ -d "$dir" ] && [ -w "$dir" ]
		then
			SETUP_DIR="$dir/exageostat"
			break
		fi
	done
fi

if [ -z "$SETUP_DIR" ]
then
	echo "Check your .libPaths() in R. Could not find a writable directory."
	exit 1;
fi

PREFIX=$SETUP_DIR

echo "Installation Directory Set to $PREFIX"

############################## Check OS
echo "Finding the current os type"
echo
osType=$(uname)
case "$osType" in
	"Darwin")
		{
			echo "Running on Mac OSX."
			LIB_EXT="dylib"
			export DYLD_LIBRARY_PATH=$PREFIX/lib:$DYLD_LIBRARY_PATH
		} ;;
"Linux")
    {
      echo "Running on LINUX."
      LIB_EXT="so"
      export LD_LIBRARY_PATH=$PREFIX/lib:$LD_LIBRARY_PATH
    } ;;
*)
    {
      echo "Unsupported OS, exiting"
      exit
    } ;;
esac

##### Check and build dependencies
# Prepare environment
export PKG_CONFIG_PATH=$PREFIX/lib/pkgconfig:$PKG_CONFIG_PATH

if [ -n "$MKLROOT" ] && [ -d "$MKLROOT" ]; then
	echo "mkl_dir directory exists!"
	echo "Great... continue set-up"
	source "$MKLROOT"/bin/mklvars.sh intel64
else
	echo "MKL not found, trying to compile and use OpenBLAS"
fi

cd "$BASEDIR" || exit
rm -rf CMake*

CFLAGS="-fcommon" cmake \
-DCMAKE_INSTALL_PREFIX="$PREFIX" \
-DEXAGEOSTAT_SCHED_STARPU=ON \
-DEXAGEOSTAT_USE_MPI=OFF \
-DEXAGEOSTAT_PACKAGE=ON \
-DCMAKE_BUILD_TYPE=Release \
-DEXAGEOSTAT_USE_STARSH=ON \
-DEXAGEOSTAT_USE_HICMA=ON \
-DEXAGEOSTAT_USE_NETCDF=ON \
-DEXAGEOSTAT_USE_CHAMELEON=ON \
-DEXAGEOSTAT_INSTALL_DEPS=ON \
-DBUILD_DEPENDENCIES=ON \
-DMPI_VALUE="$MPI_VALUE" \
-DCUDA_VALUE="$CUDA_VALUE" \
-DCMAKE_C_FLAGS_RELEASE="-O3 -Ofast -w" \
-DBUILD_SHARED_LIBS=ON ./src || exit 1;

echo "CMake Configuration of Exageostat Complete!"

cat > src/Makefile << EOF
.PHONY: all clean
all:
	(cd .. && make VERBOSE=1 && cp ./lib*.${LIB_EXT} ./src/exageostat.so)

EOF
exit $err

back to top