10
0
mirror of https://github.com/LCPQ/quantum_package synced 2024-06-02 11:25:26 +02:00
quantum_package/scripts/qp_export_as_tgz
2019-01-12 15:24:58 +01:00

188 lines
4.1 KiB
Bash
Executable File

#!/bin/bash -x
#
# Creates a self-contained binary distribution in the form of a tar.gz file
#
# Mon Nov 26 22:57:50 CET 2018
#
# Check the QP_ROOT directory
if [[ -z ${QP_ROOT} ]]
then
echo "The QP_ROOT environment variable is not set."
echo "Please reload the quantum_package.rc file."
exit 1
fi
cd ${QP_ROOT}
if [[ -f quantum_package.rc \
&& -f README.md \
&& -d src \
&& -d bin \
&& -d ocaml \
&& -d external \
&& -d scripts ]]
then
: # OK, this is a quantum_package directory
else
echo "This doesn't look like a quantum_package directory"
exit 1
fi
# Build all sources
ninja
if [[ $? -ne 0 ]]
then
echo "Error building ${dir}"
fi
# Copy the files in the static directory
QPACKAGE_STATIC=${QP_ROOT}/quantum_package_static
function find_libs ()
{
for i in "$@"
do
ldd $i
done | sort | grep '/' | cut --delimiter=' ' --fields=3 | uniq
}
function find_exec ()
{
find ${QP_ROOT}/$1 -perm /u+x -type f
}
#
echo "Creating root of static directory"
# ---------------------------------
rm --recursive --force -- "${QPACKAGE_STATIC}"
mkdir --parents -- ${QPACKAGE_STATIC}/{bin,lib,extra_lib,external}
if [[ $? -ne 0 ]] ;
then
echo "Error creating ${QPACKAGE_STATIC}/{bin,lib,extra_lib,external}"
exit 1
fi
#
echo "Copying binary files"
# --------------------
FORTRAN_EXEC=$(find_exec src)
if [[ -z $FORTRAN_EXEC ]] ;
then
echo 'Error : No Fortran binaries found.'
exit 1
fi
OCAML_EXEC=$(find_exec ocaml | grep .native )
if [[ -z $OCAML_EXEC ]] ;
then
echo 'Error : No ocaml binaries found.'
exit 1
fi
cp -- ${FORTRAN_EXEC} ${OCAML_EXEC} ${QPACKAGE_STATIC}/bin
if [[ $? -ne 0 ]] ;
then
cp -- ${FORTRAN_EXEC} ${OCAML_EXEC} ${QPACKAGE_STATIC}/bin
exit 1
fi
(
cd ${QPACKAGE_STATIC}/bin
for i in *.native
do
mv "$i" $(basename "$i" .native)
done
)
cp --recursive -- ${QP_ROOT}/data ${QPACKAGE_STATIC}/data
for i in ${FORTRAN_EXEC}
do
i=$(basename $i)
echo $i \$QP_ROOT/bin/$i
done > ${QPACKAGE_STATIC}/data/executables
mkdir --parents -- ${QPACKAGE_STATIC}/src/Bitmask
cp ${QP_ROOT}/src/Bitmask/bitmasks_module.f90 ${QPACKAGE_STATIC}/src/Bitmask
#
echo "Copying dynamic libraries"
# --------------------------
MKL_LIBS=$(find_libs ${FORTRAN_EXEC} | grep libmkl | head -1)
if [[ -n ${MKL_LIBS} ]]
then
MKL_LIBS=$(dirname ${MKL_LIBS})
MKL_LIBS=$(ls ${MKL_LIBS}/libmkl_{def,avx,avx2}.so)
fi
ALL_LIBS=$(find_libs ${OCAML_EXEC} ${FORTRAN_EXEC})
for i in ${ALL_LIBS} ${MKL_LIBS}
do
cp -- ${i} ${QPACKAGE_STATIC}/extra_lib
done
if [[ $? -ne 0 ]] ;
then
echo 'cp -- ${ALL_LIBS} ${MKL_LIBS} ${QPACKAGE_STATIC}/extra_lib'
exit 1
fi
cp -- ${QPACKAGE_STATIC}/extra_lib/lib{[gi]omp*,mkl*,lapack*,blas*,z*} ${QPACKAGE_STATIC}/lib/
#
echo "Copying scripts directory"
# -------------------------
cp --recursive -- ${QP_ROOT}/scripts ${QPACKAGE_STATIC}/
if [[ $? -ne 0 ]] ;
then
echo 'cp --recursive -- ${QP_ROOT}/scripts ${QPACKAGE_STATIC}/'
exit 1
fi
#
echo "Copying external libraries"
# --------------------------
cp --recursive -- ${QP_ROOT}/external/emsl ${QPACKAGE_STATIC}/external
if [[ $? -ne 0 ]] ;
then
echo 'cp --recursive -- ${QP_ROOT}/external/emsl ${QPACKAGE_STATIC}/'
exit 1
fi
cp --recursive -- ${QP_ROOT}/external/Python ${QPACKAGE_STATIC}/external/
mkdir ${QPACKAGE_STATIC}/external/ezfio
cp --recursive -- ${QP_ROOT}/external/ezfio/Python ${QPACKAGE_STATIC}/external/ezfio/
cp --recursive -- ${QP_ROOT}/external/ezfio/Bash ${QPACKAGE_STATIC}/external/ezfio/
#
echo "Creating quantum_package.rc"
# ---------------------------
sed "s!^export QP_ROOT=.*\$!export QP_ROOT=\$( cd \$(dirname "\${BASH_SOURCE}") ; pwd -P )!" ${QP_ROOT}/quantum_package.rc.default > ${QPACKAGE_STATIC}/quantum_package.rc
#exit 0
#
echo "Creating the archive"
# --------------------
tar --create --gzip --file "${QPACKAGE_STATIC}".tar.gz quantum_package_static && rm --recursive --force -- "${QPACKAGE_STATIC}"
if [[ $? -ne 0 ]] ;
then
echo 'tar --create --gzip --file "${QPACKAGE_STATIC}".tar.gz "${QPACKAGE_STATIC}" && rm --recursive --force -- "${QPACKAGE_STATIC}"'
exit 1
fi
echo "Done : ${QPACKAGE_STATIC}.tar.gz"