
# YL 12/01/2021: we simply replace the version number 6.8 with 7.0 as we find nothing change needs to be made to compile 7.0
def getScriptTemplate(version=7):
    '''Return a template of the NWChem 7 compile script according to version number'''


    strbuff0 = '''#!/bin/bash --login

echo
echo "##################################################################"
echo "# Script for Compiling NWChem {_nwchem_version} to Link against Py-ChemShell #"
echo "##################################################################"
echo
echo generated {_now} by Py-ChemShell
echo
echo Please feel free to bring up questions at www.chemshell.org should you have any troubles compiling NWChem

{_unload_modules}
{_restore_modules}
{_swap_modules}
{_load_modules}

# number of cpu cores for compiling NWChem (make -j )
njobs={_njobs}

###
export NWCHEM_TOP={_nwchem}
export NWCHEM_MODULES=all
export NWCHEM_TARGET=LINUX64
###

###
export USE_MPI=yes
export USE_MPIF=yes
export USE_MPIF4=yes
export LIBMPI=" "
export MPI_INCLUDE={_mpi_include_path}
export MPI_LIB={_mpi_lib_path}
export FORCE_MPI_ENV=yes
###

###
export USE_OPENMP=yes
###

#export USE_FPICF=yes
#export USE_TCGMSG=yes
###
export ARMCI_NETWORK=MPI-TS
###

# here will be always absolute path as generated by ChemShell (on some systems there are no symlinks)
# MKL_LIBS_DIR=
{_mkl_libs_dir}
# MKL_INCL_DIR=
{_mkl_incl_dir}

###
# NB: if the math libs size is 4 we do the 64_to_32 trick to rename the functions from "dxxxx_" to "yxxx_"
#     because the NWChem integer size depends on the computer (32- or 64-bit) rather than hard declaration 
# NB: lp for 32-bit libraries, while no need of 64_to_32 if we link against ilp64 libs (then we need XXXX_SIZE=8 but MA may fail in ChemShell so do not try)
export USE_SCALAPACK=y
export SCALAPACK_SIZE=4
export HAVE_SCALAPACK=yes
export SCALAPACK={_mkl_opt}
export HAS_BLAS=yes
export BLAS_SIZE=4
{_blas_opt}
export LAPACK_LIB={_lapack_opt}
export LAPACK_SIZE=4
export INSTALL_PREFIX=$NWCHEM_TOP
###

# the original source code contain only 64-bit names, once we set USE_64to32 (whether y or n) a Perl script will be run to convert all dxxx names to yxxx
###
export USE_64TO32=yes
###

# NB: use the -D_Floatxx=yyy definitions when Intel compilers 17/18 are incompatible with glibs on Ubuntu
#     see https://software.intel.com/en-us/forums/intel-c-compiler/topic/760979
#     in this case ./setup --f128 required for compiling Py-ChemShell
{_fc}
{_cc}
{_foptions}
{_coptions}
{_ldflags}
# OPTIMIZE prevents FDEBUG
#export OPTIMIZE=yes
#export USE_FPE=yes

echo
echo Uncomment these lines to clear previous compilations if necessary:
echo "#cd $NWCHEM_TOP/src/tools/{_ga_name}"
echo "#make -j $njobs distclean"
echo and
echo "#cd $NWCHEM_TOP/src"
echo "#cd tools/{_ga_name}"
echo "#make distclean"
echo "#cd ../.."
echo "#make -j $njobs clean"
echo "#make -j $njobs realclean"
echo "#make -j $njobs clear_64_to_32"
echo "#make -j $njobs clear_32_to_64"
echo

# clear GA version {_ga_name} for NWChem {_nwchem_version}
#cd $NWCHEM_TOP/src/tools/{_ga_name}
#make -j $njobs distclean

cd $NWCHEM_TOP/src
#cd tools/{_ga_name}
#make distclean
#cd ../..
#make -j $njobs clean
#make -j $njobs realclean
#make -j $njobs clear_64_to_32
#make -j $njobs clear_32_to_64

{_m_pi}

{_progress}

echo making nwchem_config... see config.log
make -j $njobs nwchem_config &> config.log

echo making 64_to_32... see 64_to_32.log
make -j $njobs 64_to_32 &> 64_to_32.log

echo making all... see make.log
make -j $njobs &> make.log

#echo making link... see link.log
#make link &> link.log

make install &> install.log
'''

    return { 7: strbuff0 }.get(version, strbuff0)
