#!/bin/bash # # Quantum Package configuration script # export QP_ROOT="$( cd "$(dirname "$0")" ; pwd --physical )" echo "QP_ROOT="$QP_ROOT help() { cat < | --config configure -h | --help configure -i | --install Options: -c , --config define a configuration file, in "${QP_ROOT}/config/". -h, --help print the help message -i , --install install . Use at your own risk: no support will be provided for the installation of dependencies. Example: ./configure -c config/gfortran.cfg Note: - Users are encouraged to create their own configuration files instead of modifying the existing ones. EOF exit } PACKAGES="" OCAML_PACKAGES="ocamlbuild cryptokit zmq core sexplib ppx_sexp_conv ppx_deriving getopt" while : ; do case "$1" in "") break;; -c|--config) CONFIG="$2" shift;; -i|--install) PACKAGES="${PACKAGE} $2" shift;; -h|-help|--help) help;; *) echo "unknown option $1, try --help" exit 2;; esac shift done # Trim leading and trailing spaces PACKAGES=$(echo $PACKAGES | xargs) echo "export QP_ROOT=\"$QP_ROOT\"" > ${QP_ROOT}/etc/00.qp_root source quantum_package.rc function fail() { echo "Please refer to INSTALL.rst to install the missing dependencies." exit 1 } function success() { echo "" echo "Configuration successful." exit 1 } function error() { echo "Error : $1" exit 2 } function download() { wget --no-check-certificate $1 --output-document=$2 || error "Unable to download $1" } function find_exe() { which $1 2> /dev/null || echo 'not_found' } function find_python_lib() { python2 -c "import $1" &> /dev/null && echo "$1" || echo 'not_found' } function find_lib() { echo "int main() { return 0; }" > "${QP_ROOT}"/external/tmp.c gcc $@ "${QP_ROOT}"/external/tmp.c -o "${QP_ROOT}"/external/tmp.exe 2> /dev/null if [[ -x "${QP_ROOT}"/external/tmp.exe ]] ; then rm "${QP_ROOT}"/external/tmp.exe "${QP_ROOT}"/external/tmp.c echo "$lib" else rm "${QP_ROOT}"/external/tmp.c echo "not_found" fi } function find_dir() { if [[ -d $1 ]] ; then echo "$1" else echo "not_found" fi } if [[ "${PACKAGES}.x" != ".x" ]] ; then echo "" echo "#########################################################" echo "# #" echo "# Automatic installation of dependencies #" echo "# #" echo "# USE AT YOUR OWN RISK : #" echo "# No support will be provided by the quantum package #" echo "# developers for the installation of external software. #" echo "# #" echo "# You may refer to the INSTALL.rst file for help. #" echo "# #" echo "#########################################################" echo "" fi if [[ ${PACKAGES} = all ]] ; then PACKAGES="ninja irpf90 zeromq f77zmq ocaml ezfio emsl docopt resultsFile bats" fi for PACKAGE in ${PACKAGES} ; do if [[ ${PACKAGE} = ninja ]] ; then download \ "https://github.com/ninja-build/ninja/releases/download/v1.8.2/ninja-linux.zip" \ "${QP_ROOT}"/external/ninja.zip unzip "${QP_ROOT}"/external/ninja.zip -d "${QP_ROOT}"/bin elif [[ ${PACKAGE} = irpf90 ]] ; then download \ "https://gitlab.com/scemama/irpf90/-/archive/v1.7.4/irpf90-v1.7.4.tar.gz" \ "${QP_ROOT}"/external/irpf90.tar.gz ( cd "${QP_ROOT}"/external tar --gunzip --extract --file irpf90.tar.gz rm irpf90.tar.gz cd irpf90-* make for i in irpf90 irpman irpf90_indent do cat << EOF > "${QP_ROOT}"/bin/$i #!/bin/sh exec $PWD/bin/$i \$@ EOF chmod +x "${QP_ROOT}"/bin/$i done ) elif [[ ${PACKAGE} = zeromq ]] ; then download \ "https://github.com/zeromq/libzmq/releases/download/v4.2.5/zeromq-4.2.5.tar.gz" \ "${QP_ROOT}"/external/zeromq.tar.gz ( cd "${QP_ROOT}"/external tar --gunzip --extract --file zeromq.tar.gz rm zeromq.tar.gz cd zeromq-* ./configure --prefix="$QP_ROOT" --without-libsodium --enable-libunwind=no make make install ) elif [[ ${PACKAGE} = f77zmq ]] ; then download \ "https://github.com/scemama/f77_zmq/archive/v4.2.5.tar.gz" \ "${QP_ROOT}"/external/f77_zmq.tar.gz ( cd "${QP_ROOT}"/external tar --gunzip --extract --file f77_zmq.tar.gz rm f77_zmq.tar.gz cd f77_zmq-* export ZMQ_H="$QP_ROOT"/include/zmq.h make cp libf77zmq.a "${QP_ROOT}"/lib cp libf77zmq.so "${QP_ROOT}"/lib cp f77_zmq_free.h "${QP_ROOT}"/include ) elif [[ ${PACKAGE} = ocaml ]] ; then download \ "https://raw.githubusercontent.com/ocaml/opam/master/shell/install.sh" \ "${QP_ROOT}"/external/opam_installer.sh chmod +x "${QP_ROOT}"/external/opam_installer.sh rm --force ${QP_ROOT}/bin/opam if [[ -n ${TRAVIS} ]] ; then # Special commands for Travis CI export OPAMROOT=${HOME}/.opam cat << EOF | bash ${QP_ROOT}/external/opam_installer.sh --no-backup ${QP_ROOT}/bin EOF else # Conventional commands export OPAMROOT=${OPAMROOT:-${QP_ROOT}/external/opam} echo "QP>> Please install it here: " ${QP_ROOT}/bin sh ${QP_ROOT}/external/opam_installer.sh fi source ${OPAMROOT}/opam-init/init.sh > /dev/null 2> /dev/null || true rm ${QP_ROOT}/external/opam_installer.sh ${QP_ROOT}/bin/opam init --disable-sandboxing --verbose \ --yes --comp=4.07.0 eval $(${QP_ROOT}/bin/opam env) opam install -y ${OCAML_PACKAGES} elif [[ ${PACKAGE} = ezfio ]] ; then download \ "https://gitlab.com/scemama/EZFIO/-/archive/v1.3.4/EZFIO-v1.3.4.tar.gz" \ "${QP_ROOT}"/external/ezfio.tar.gz ( cd "${QP_ROOT}"/external tar --gunzip --extract --file ezfio.tar.gz mv EZFIO-* ezfio ) elif [[ ${PACKAGE} = emsl ]] ; then download \ "https://github.com/LCPQ/EMSL_Basis_Set_Exchange_Local/archive/v1.0.tar.gz" \ "${QP_ROOT}"/external/EMSL.tar.gz ( cd "${QP_ROOT}"/external tar --gunzip --extract --file EMSL.tar.gz mv EMSL_Basis* emsl ) elif [[ ${PACKAGE} = docopt ]] ; then download \ "https://github.com/docopt/docopt/archive/0.6.2.tar.gz" \ "${QP_ROOT}"/external/docopt.tar.gz ( cd "${QP_ROOT}"/external tar --gunzip --extract --file docopt.tar.gz mv docopt-*/docopt.py "${QP_ROOT}/external/Python" rm --recursive --force -- docopt-*/ docopt.tar.gz ) elif [[ ${PACKAGE} = resultsFile ]] ; then download \ "https://gitlab.com/scemama/resultsFile/-/archive/master/resultsFile-master.tar.gz" \ "${QP_ROOT}"/external/resultsFile.tar.gz ( cd "${QP_ROOT}"/external tar --gunzip --extract --file resultsFile.tar.gz mv resultsFile-master/resultsFile "${QP_ROOT}/external/Python" rm --recursive --force resultsFile-master resultsFile.tar.gz ) elif [[ ${PACKAGE} = bats ]] ; then download \ "https://github.com/bats-core/bats-core/archive/v1.1.0.tar.gz" \ "${QP_ROOT}"/external/bats.tar.gz ( cd "${QP_ROOT}"/external tar -zxf bats.tar.gz ( cd bats-core-1.1.0/ ./install.sh $QP_ROOT ) rm --recursive --force -- bats-core-1.1.0 \ "${QP_ROOT}"/external/bats.tar.gz ) fi done NINJA=$(find_exe ninja) if [[ ${NINJA} = not_found ]] ; then echo "Ninja is not installed." fail fi IRPF90=$(find_exe irpf90) if [[ ${IRPF90} = not_found ]] ; then echo "IRPf90 is not installed." fail fi ZEROMQ=$(find_lib -lzmq) if [[ ${ZEROMQ} = not_found ]] ; then echo "ZeroMQ is not installed." fail fi F77ZMQ=$(find_lib -lzmq -lf77zmq) if [[ ${F77ZMQ} = not_found ]] ; then echo "Fortran binding of ZeroMQ (f77zmq) is not installed." fail fi OPAM=$(find_exe opam) if [[ ${OPAM} = not_found ]] ; then echo "OPAM (ocaml) package manager is not installed." fail fi OCAML=$(find_exe ocaml) if [[ ${OCAML} = not_found ]] ; then echo "OCaml compiler is not installed." fail fi EZFIO=$(find_dir "${QP_ROOT}"/external/ezfio) if [[ ${EZFIO} = not_found ]] ; then echo "EZFIO is not installed." fail fi EMSL=$(find_dir "${QP_ROOT}"/external/emsl) if [[ ${EMSL} = not_found ]] ; then echo "EMSL is not installed." fail fi DOCOPT=$(find_python_lib docopt) if [[ ${DOCOPT} = not_found ]] ; then echo "docopt is not installed." fail fi RESULTSFILE=$(find_python_lib resultsFile) if [[ ${RESULTSFILE} = not_found ]] ; then echo "resultsFile is not installed." fail fi echo " ___________________________ " echo "< All dependencies installed. >" echo " --------------------------- " echo " \ ^__^ " echo " \ (oo)\_______ " echo " (__)\ )\/\. " echo " ||----w | " echo " || || " echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" echo "" echo "Now, if you want to use the current shell," echo "" echo " source $QP_ROOT/quantum_package.rc" echo "" echo "Or if you want to use a Bash shell adapted for QP:" echo "" echo " $QP_ROOT/qpsh" echo "" if [[ -n $CONFIG ]] ; then "${QP_ROOT}"/scripts/compilation/qp_create_ninja create --development "${CONFIG}" fi