10
0
mirror of https://github.com/QuantumPackage/qp2.git synced 2024-12-22 12:23:43 +01:00
QuantumPackage/configure

535 lines
15 KiB
Plaintext
Raw Normal View History

2020-02-26 15:58:14 +01:00
#!/bin/bash
2019-01-25 11:39:31 +01:00
#
# Quantum Package configuration script
#
TEMP=$(getopt -o c:i:h -l config:,install:,help -n $0 -- "$@") || exit 1
eval set -- "$TEMP"
export QP_ROOT="$( cd "$(dirname "$0")" ; pwd -P )"
echo "QP_ROOT="$QP_ROOT
2019-10-24 13:55:38 +02:00
unset CC
unset CCXX
2019-01-25 11:39:31 +01:00
2019-11-19 18:55:21 +01:00
# Force GCC instead of ICC for dependencies
export CC=gcc
2019-01-25 11:39:31 +01:00
2020-02-20 19:33:42 +01:00
# /!\ When updating version, update also etc files
2019-10-21 14:32:25 +02:00
2020-08-03 22:08:29 +02:00
EZFIO_TGZ="EZFIO-v2.0.3.tar.gz"
2019-10-21 14:11:47 +02:00
BATS_URL="https://github.com/bats-core/bats-core/archive/v1.1.0.tar.gz"
BUBBLE_URL="https://github.com/projectatomic/bubblewrap/releases/download/v0.3.3/bubblewrap-0.3.3.tar.xz"
DOCOPT_URL="https://github.com/docopt/docopt/archive/0.6.2.tar.gz"
BSE_URL="https://github.com/MolSSI-BSE/basis_set_exchange/archive/v0.8.11.tar.gz"
2019-10-21 14:11:47 +02:00
F77ZMQ_URL="https://github.com/scemama/f77_zmq/archive/v4.2.5.tar.gz"
GMP_URL="ftp://ftp.gnu.org/gnu/gmp/gmp-6.1.2.tar.bz2"
2020-12-05 16:29:36 +01:00
IRPF90_URL="https://gitlab.com/scemama/irpf90/-/archive/v2.0.3/irpf90-v2.0.3.tar.gz"
2019-10-21 14:11:47 +02:00
LIBCAP_URL="https://git.kernel.org/pub/scm/linux/kernel/git/morgan/libcap.git/snapshot/libcap-2.25.tar.gz"
NINJA_URL="https://github.com/ninja-build/ninja/releases/download/v1.8.2/ninja-linux.zip"
OCAML_URL="https://raw.githubusercontent.com/ocaml/opam/master/shell/install.sh"
2020-02-12 21:12:19 +01:00
RESULTS_URL="https://gitlab.com/scemama/resultsFile/-/archive/v2.0/resultsFile-v2.0.tar.gz"
2019-10-21 14:11:47 +02:00
ZEROMQ_URL="https://github.com/zeromq/libzmq/releases/download/v4.2.5/zeromq-4.2.5.tar.gz"
ZLIB_URL="https://www.zlib.net/zlib-1.2.11.tar.gz"
2019-01-25 11:39:31 +01:00
function help()
{
cat <<EOF
Quantum Package configuration script.
Usage:
$(basename $0) -c <file> | --config=<file>
$(basename $0) -h | --help
$(basename $0) -i <package> | --install=<package>
Options:
-c, --config=<file> Define a COMPILATION configuration file,
2020-02-26 15:58:14 +01:00
in "${QP_ROOT}/config/".
2019-01-25 11:39:31 +01:00
-h, --help Print the HELP message
-i, --install=<package> INSTALL <package>. Use at your OWN RISK:
no support will be provided for the installation of
dependencies.
Example:
./$(basename $0) -c config/gfortran.cfg
Note:
Users are encouraged to create their own configuration files instead of
modifying the existing ones.
EOF
exit
}
function error() {
>&2 echo "$(basename $0): $@"
exit 2
}
function execute () {
local _command
echo "Executing:"
while read -r line; do
echo " " $line
_command+="${line} ;"
2020-02-26 15:58:14 +01:00
done
2019-01-25 11:39:31 +01:00
sleep 1
echo ""
printf "\e[0;94m"
( eval "set -x ; $_command set +x" ) || exit -1
printf "\e[m"
echo ""
}
PACKAGES=""
2020-01-07 09:25:00 +01:00
OCAML_PACKAGES="ocamlbuild cryptokit zmq sexplib ppx_sexp_conv ppx_deriving getopt"
2019-01-25 11:39:31 +01:00
while true ; do
case "$1" in
2020-02-26 15:58:14 +01:00
-c|--config)
2019-01-25 11:39:31 +01:00
case "$2" in
"") help ; break;;
*) if [[ -f $2 ]] ; then
CONFIG="$2"
else
error "error: configuration file $2 not found."
exit 1
fi
2020-02-26 15:58:14 +01:00
esac
2019-01-25 11:39:31 +01:00
shift 2;;
-i|--install)
case "$2" in
"") help ; break;;
*) PACKAGES="${PACKAGE} $2"
2020-02-26 15:58:14 +01:00
esac
2019-01-25 11:39:31 +01:00
shift 2;;
2020-02-26 15:58:14 +01:00
-h|-help|--help)
2019-01-25 11:39:31 +01:00
help
exit 0;;
--) shift ; break ;;
*)
error $(basename $0)": unknown option $1, try --help"
exit 2;;
esac
done
# Trim leading and trailing spaces
PACKAGES=$(echo $PACKAGES | xargs)
echo "export QP_ROOT=\"$QP_ROOT\"" > ${QP_ROOT}/etc/00.qp_root.rc
source quantum_package.rc
function fail() {
echo "You can try to install it using the -i option."
echo "Please refer to INSTALL.rst to install the missing dependencies."
exit 1
}
function success() {
echo ""
echo "Configuration successful."
exit 1
}
function download() {
echo "Downloading $1"
echo ""
printf "\e[0;34m"
wget --no-check-certificate $1 --output-document=$2 || error "Unable to download $1"
printf "\e[m"
echo "Saved dowloaded file as $2"
echo ""
}
function not_found() {
echo 'not_found'
}
function find_exe() {
which $1 2> /dev/null || not_found
}
function find_python_lib() {
2020-03-17 16:39:43 +01:00
python3 -c "import $1" &> /dev/null && echo "$1" || not_found
2019-01-25 11:39:31 +01:00
}
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
not_found
fi
}
function find_dir() {
if [[ -d $1 ]] ; then
echo "$1"
else
not_found
fi
}
2020-02-20 19:33:42 +01:00
# Extract EZFIO if needed
EZFIO=$(find_dir "${QP_ROOT}"/external/ezfio)
if [[ ${EZFIO} = $(not_found) ]] ; then
execute << EOF
cd "\${QP_ROOT}"/external
2020-02-26 15:58:14 +01:00
tar --gunzip --extract --file ${EZFIO_TGZ}
2020-02-20 19:33:42 +01:00
rm -rf ezfio
2020-08-03 22:08:29 +02:00
mv EZFIO ezfio || mv EZFIO-v*/ ezfio
2020-02-20 19:33:42 +01:00
EOF
fi
2019-01-25 11:39:31 +01:00
if [[ "${PACKAGES}.x" != ".x" ]] ; then
printf "\e[0;31m"
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 "#########################################################"
printf "\e[m"
echo ""
sleep 1
fi
if [[ ${PACKAGES} = all ]] ; then
2020-12-05 16:30:26 +01:00
PACKAGES="zlib ninja irpf90 zeromq f77zmq gmp libcap bwrap ocaml docopt resultsFile bats"
2019-01-25 11:39:31 +01:00
fi
for PACKAGE in ${PACKAGES} ; do
if [[ ${PACKAGE} = ninja ]] ; then
2019-10-21 14:11:47 +02:00
download ${NINJA_URL} "${QP_ROOT}"/external/ninja.zip
2019-01-25 11:39:31 +01:00
execute << EOF
rm -f "\${QP_ROOT}"/bin/ninja
unzip "\${QP_ROOT}"/external/ninja.zip -d "\${QP_ROOT}"/bin
EOF
elif [[ ${PACKAGE} = gmp ]] ; then
2019-10-21 14:11:47 +02:00
download ${GMP_URL} "${QP_ROOT}"/external/gmp.tar.bz2
execute << EOF
cd "\${QP_ROOT}"/external
tar --bzip2 --extract --file gmp.tar.bz2
rm gmp.tar.bz2
cd gmp*
./configure --prefix=$QP_ROOT && make -j 8
make install
EOF
2020-02-26 15:58:14 +01:00
2019-06-05 17:39:01 +02:00
elif [[ ${PACKAGE} = libcap ]] ; then
2019-10-21 14:11:47 +02:00
download ${LIBCAP_URL} "${QP_ROOT}"/external/libcap.tar.gz
2019-06-05 17:39:01 +02:00
execute << EOF
cd "\${QP_ROOT}"/external
tar --gunzip --extract --file libcap.tar.gz
rm libcap.tar.gz
cd libcap-*/libcap
prefix=$QP_ROOT make install
EOF
2019-06-05 17:28:15 +02:00
elif [[ ${PACKAGE} = bwrap ]] ; then
2019-10-21 14:11:47 +02:00
download ${BUBBLE_URL} "${QP_ROOT}"/external/bwrap.tar.xz
2019-06-05 17:28:15 +02:00
execute << EOF
cd "\${QP_ROOT}"/external
tar --xz --extract --file bwrap.tar.xz
rm bwrap.tar.xz
cd bubblewrap*
./configure --prefix=$QP_ROOT && make -j 8
make install-exec-am
EOF
2019-01-25 11:39:31 +01:00
elif [[ ${PACKAGE} = irpf90 ]] ; then
# When changing version of irpf90, don't forget to update etc/irpf90.rc
2019-10-21 14:11:47 +02:00
download ${IRPF90_URL} "${QP_ROOT}"/external/irpf90.tar.gz
2019-01-25 11:39:31 +01:00
execute << EOF
cd "\${QP_ROOT}"/external
tar --gunzip --extract --file irpf90.tar.gz
rm irpf90.tar.gz
cd irpf90-*
make
EOF
2020-02-26 15:58:14 +01:00
2019-01-25 11:39:31 +01:00
elif [[ ${PACKAGE} = zeromq ]] ; then
2019-10-21 14:11:47 +02:00
download ${ZEROMQ_URL} "${QP_ROOT}"/external/zeromq.tar.gz
2019-01-25 11:39:31 +01:00
execute << EOF
2020-03-05 08:51:39 +01:00
export CC=gcc
export CXX=g++
2019-01-25 11:39:31 +01:00
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
EOF
elif [[ ${PACKAGE} = f77zmq ]] ; then
2019-10-21 14:11:47 +02:00
download ${F77ZMQ_URL} "${QP_ROOT}"/external/f77_zmq.tar.gz
2019-01-25 11:39:31 +01:00
execute << EOF
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
EOF
2020-02-26 15:58:14 +01:00
2019-01-25 11:39:31 +01:00
elif [[ ${PACKAGE} = ocaml ]] ; then
2019-10-21 14:11:47 +02:00
download ${OCAML_URL} "${QP_ROOT}"/external/opam_installer.sh
2019-01-25 11:39:31 +01:00
if [[ -n ${TRAVIS} ]] ; then
# Special commands for Travis CI
chmod +x "${QP_ROOT}"/external/opam_installer.sh
rm --force ${QP_ROOT}/bin/opam
if [[ -n ${NO_CACHE} ]] ; then
rm -rf ${HOME}/.opam
fi
2019-01-25 11:39:31 +01:00
export OPAMROOT=${HOME}/.opam
2020-02-26 15:58:14 +01:00
cat << EOF | bash ${QP_ROOT}/external/opam_installer.sh --no-backup
2019-01-25 11:39:31 +01:00
${QP_ROOT}/bin
2019-07-24 08:11:17 +02:00
2019-01-25 11:39:31 +01:00
EOF
rm ${QP_ROOT}/external/opam_installer.sh
2019-08-19 17:42:54 +02:00
# source ${OPAMROOT}/opam-init/init.sh > /dev/null 2> /dev/null || true
#
2020-03-05 08:51:39 +01:00
# opam switch create ocaml-base-compiler.4.10.0
opam init --verbose --yes --compiler=4.10.0 --disable-sandboxing
2019-01-25 11:39:31 +01:00
2019-07-24 12:33:08 +02:00
eval $(opam env)
2019-01-25 11:39:31 +01:00
opam install -y ${OCAML_PACKAGES} || exit 1
2019-07-24 12:33:08 +02:00
2019-01-25 11:39:31 +01:00
else
# Conventional commands
execute << EOF
chmod +x "${QP_ROOT}"/external/opam_installer.sh
2020-02-26 15:58:14 +01:00
"${QP_ROOT}"/external/opam_installer.sh --no-backup
2019-07-24 09:06:11 +02:00
EOF
execute << EOF
rm --force ${QP_ROOT}/bin/opam
export OPAMROOT=${OPAMROOT:-${QP_ROOT}/external/opam}
echo ${QP_ROOT}/bin \
2020-02-26 15:58:14 +01:00
| sh ${QP_ROOT}/external/opam_installer.sh
2019-07-24 09:06:11 +02:00
EOF
2019-07-26 12:38:34 +02:00
rm ${QP_ROOT}/external/opam_installer.sh
2019-08-19 17:42:54 +02:00
# source ${OPAMROOT}/opam-init/init.sh > /dev/null 2> /dev/null || true
2020-03-05 08:51:39 +01:00
# opam switch create ocaml-base-compiler.4.10.0 || exit 1
2020-03-05 08:51:39 +01:00
opam init --verbose --yes --compiler=4.10.0 --disable-sandboxing
2019-07-24 12:33:08 +02:00
eval $(opam env)
2019-07-24 09:06:11 +02:00
execute << EOF
2019-01-25 11:39:31 +01:00
opam install -y \${OCAML_PACKAGES} || exit 1
EOF
fi
elif [[ ${PACKAGE} = bse ]] ; then
2019-01-25 11:39:31 +01:00
download ${BSE_URL} "${QP_ROOT}"/external/bse.tar.gz
2019-01-25 11:39:31 +01:00
execute << EOF
cd "\${QP_ROOT}"/external
tar --gunzip --extract --file bse.tar.gz
pip install -e basis_set_exchange-*
2019-01-25 11:39:31 +01:00
EOF
elif [[ ${PACKAGE} = zlib ]] ; then
2019-10-21 14:11:47 +02:00
download ${ZLIB_URL} "${QP_ROOT}"/external/zlib.tar.gz
2019-01-25 11:39:31 +01:00
execute << EOF
cd "\${QP_ROOT}"/external
tar --gunzip --extract --file zlib.tar.gz
rm zlib.tar.gz && \
cd zlib-*/
./configure --prefix=${QP_ROOT} && \
make && make install
EOF
2020-02-26 15:58:14 +01:00
2019-01-25 11:39:31 +01:00
elif [[ ${PACKAGE} = docopt ]] ; then
2019-10-21 14:11:47 +02:00
download ${DOCOPT_URL} "${QP_ROOT}"/external/docopt.tar.gz
2019-01-25 11:39:31 +01:00
execute << EOF
cd "\${QP_ROOT}"/external
2020-02-26 15:58:14 +01:00
tar --gunzip --extract --file docopt.tar.gz
2019-01-25 11:39:31 +01:00
mv docopt-*/docopt.py "\${QP_ROOT}/external/Python"
rm --recursive --force -- docopt-*/ docopt.tar.gz
EOF
elif [[ ${PACKAGE} = resultsFile ]] ; then
2019-10-21 14:11:47 +02:00
download ${RESULTS_URL} "${QP_ROOT}"/external/resultsFile.tar.gz
2019-01-25 11:39:31 +01:00
execute << EOF
cd "\${QP_ROOT}"/external
2020-02-26 15:58:14 +01:00
tar --gunzip --extract --file resultsFile.tar.gz
2020-02-12 21:42:49 +01:00
mv resultsFile-*/resultsFile "\${QP_ROOT}/external/Python/"
rm --recursive --force resultsFile-* resultsFile.tar.gz
2019-01-25 11:39:31 +01:00
EOF
elif [[ ${PACKAGE} = bats ]] ; then
2019-10-21 14:11:47 +02:00
download ${BATS_URL} "${QP_ROOT}"/external/bats.tar.gz
2019-01-25 11:39:31 +01:00
execute << EOF
cd "\${QP_ROOT}"/external
2020-02-26 15:58:14 +01:00
tar -zxf bats.tar.gz
2019-01-25 11:39:31 +01:00
( cd bats-core-1.1.0/ ; ./install.sh \${QP_ROOT})
rm --recursive --force -- bats-core-1.1.0 \ "\${QP_ROOT}"/external/bats.tar.gz
EOF
2020-12-04 11:03:51 +01:00
else
error "${PACKAGE} unknown."
fail
2019-01-25 11:39:31 +01:00
fi
done
2019-02-04 13:14:57 +01:00
source quantum_package.rc
2019-01-25 11:39:31 +01:00
NINJA=$(find_exe ninja)
if [[ ${NINJA} = $(not_found) ]] ; then
2019-02-04 13:14:57 +01:00
error "Ninja (ninja) is not installed."
2019-01-25 11:39:31 +01:00
fail
fi
IRPF90=$(find_exe irpf90)
if [[ ${IRPF90} = $(not_found) ]] ; then
2020-12-05 17:03:04 +01:00
error "IRPF90 (irpf90) is not installed."
2019-01-25 11:39:31 +01:00
fail
fi
ZEROMQ=$(find_lib -lzmq)
if [[ ${ZEROMQ} = $(not_found) ]] ; then
2019-02-04 13:14:57 +01:00
error "ZeroMQ (zeromq) is not installed."
2019-01-25 11:39:31 +01:00
fail
fi
2019-04-12 13:34:17 +02:00
F77ZMQ=$(find_lib -lzmq -lf77zmq -lpthread)
2019-01-25 11:39:31 +01:00
if [[ ${F77ZMQ} = $(not_found) ]] ; then
error "Fortran binding of ZeroMQ (f77zmq) is not installed."
fail
fi
GMP=$(find_lib -lgmp)
if [[ ${ZLIB} = $(not_found) ]] ; then
error "GMP (gmp) is not installed."
fail
fi
2019-06-05 17:28:15 +02:00
LIBCAP=$(find_lib -lcap)
if [[ ${LIBCAP} = $(not_found) ]] ; then
error "Libcap (libcap) is not installed."
fail
fi
2019-07-31 16:25:23 +02:00
BWRAP=$(find_exe bwrap)
if [[ ${BWRAP} = $(not_found) ]] ; then
error "Bubblewrap (bwrap) is not installed."
fail
fi
2019-01-25 11:39:31 +01:00
OPAM=$(find_exe opam)
if [[ ${OPAM} = $(not_found) ]] ; then
error "OPAM (ocaml) package manager is not installed."
fail
fi
OCAML=$(find_exe ocaml)
if [[ ${OCAML} = $(not_found) ]] ; then
2019-02-04 13:14:57 +01:00
error "OCaml (ocaml) compiler is not installed."
2019-01-25 11:39:31 +01:00
fail
fi
ZLIB=$(find_lib -lz)
if [[ ${ZLIB} = $(not_found) ]] ; then
2019-02-04 13:14:57 +01:00
error "Zlib (zlib) is not installed."
2019-01-25 11:39:31 +01:00
fail
fi
DOCOPT=$(find_python_lib docopt)
if [[ ${DOCOPT} = $(not_found) ]] ; then
2019-02-04 13:14:57 +01:00
error "docopt (docopt) is not installed."
2019-01-25 11:39:31 +01:00
fail
fi
RESULTSFILE=$(find_python_lib resultsFile)
if [[ ${RESULTSFILE} = $(not_found) ]] ; then
2019-02-04 13:14:57 +01:00
error "resultsFile (resultsFile) is not installed."
2019-01-25 11:39:31 +01:00
fail
fi
printf "\e[0;34m"
echo " ___________________________ "
echo "< All dependencies installed. >"
echo " --------------------------- "
echo " \ ^__^ "
echo " \ (oo)\_______ "
echo " (__)\ )\/\. "
echo " ||----w | "
echo " || || "
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
2020-02-04 19:04:36 +01:00
echo ""
2020-08-26 10:19:40 +02:00
echo "If you have PIP, you can install the Basis Set Exchange command-line tool:"
2020-02-04 19:04:36 +01:00
echo ""
echo " ./configure -i bse"
echo ""
2020-02-04 19:30:04 +01:00
echo "This will enable the usage of qp_basis to install extra basis sets."
2020-02-04 19:04:36 +01:00
echo ""
echo ""
2019-01-25 11:39:31 +01:00
printf "\e[m\n"
if [[ -n $CONFIG ]] ; then
"${QP_ROOT}"/scripts/compilation/qp_create_ninja create --development "${CONFIG}"
fi
if [[ -f ${QP_ROOT}/build.ninja ]] ; then
[[ -z ${TRAVIS} ]] && echo "You can now run ./bin/qpsh to enter in the QP shell mode :)"
2020-02-26 15:58:14 +01:00
else
2019-01-25 11:39:31 +01:00
echo ""
echo "${QP_ROOT}/build.ninja does not exist,"
echo "you need to specify the COMPILATION configuration file."
2020-02-26 15:58:14 +01:00
echo "See ./configure --help for more details."
2019-01-25 11:39:31 +01:00
echo ""
fi
2019-01-25 11:39:31 +01:00
exit 0
2020-02-26 15:58:14 +01:00
2019-01-25 11:39:31 +01:00