#This is the configuration file for the BigDFT installer
#This is a python script which is executed by the build suite

#Add the condition testing to run tests and includes PyYaml
conditions.add("bio")
conditions.add("ase")
conditions.add("sirius")
conditions.add("dill")
conditions.add("boost")
#List the module the this rcfile will build
modules = ['spred',]
#example of the potentialities of the python syntax in this file
def cuda_ocl():
    return """ --enable-opencl --enable-cuda-gpu "--with-ocl-path=${CUDA_ROOT}" "--with-cuda-path=${CUDA_ROOT}" "NVCC_FLAGS=--compiler-options -fPIC" """
    # "LIBS=-ldl -lstdc++ -lgfortran"" "CFLAGS="""+flags+""" -fPIC -O2 -fopenmp" "FC=mpif90" "F77=mpif77" "FCLIBS= " "LIBS=-ldl -lstdc++ -lgfortran -lgomp" """+ linalgs +""" "NVCC_FLAGS="""+cuda_gencodes+""" --compiler-options -fPIC" "FCLIBS= " "LIBS=-ldl -lstdc++ -lgfortran -lgomp" """+ linalgs +"""
def env_configuration():
    return  """ FCFLAGS="-I${MKLROOT}/include -O2 -fPIC -qopenmp -g" FC="mpif90 -fc=ifort" CC=icc CFLAGS=-fPIC --with-ext-linalg="-L${MKLROOT}/lib/intel64 -lmkl_scalapack_lp64 -lmkl_intel_lp64 -lmkl_intel_thread -lmkl_core -lmkl_blacs_intelmpi_lp64 -liomp5 -lpthread -lm -ldl -lstdc++" --enable-dynamic-libraries CXX=icpc""" + \
        cuda_ocl()
#the following command sets the environment variable to give these settings
#to all the modules
import os
from os.path import join
os.environ['BIGDFT_CONFIGURE_FLAGS']=env_configuration()
#here follow the configuration instructions for the modules built
#we specify the configurations for the modules to customize the options if needed
autogenargs = env_configuration()

module_autogenargs.update({
'biopython': "", 'simtk': "", 'pdbfixer': "", 'ase': "", 'dill': "", 'dnaviewer': "", 'lsim-f2py': ""
})

module_cmakeargs.update({
    'ntpoly': "-DFORTRAN_ONLY=Yes -DCMAKE_Fortran_COMPILER='mpiifort' -DCMAKE_Fortran_FLAGS_RELEASE='-O2 -g -qopenmp -fPIC' -DBUILD_SHARED_LIBS=Yes",
    'rdkit': "-DPYTHON_EXECUTABLE=/opt/intel/oneapi/intelpython/latest/bin/python -DPYTHON_LIBRARY=/opt/intel/oneapi/intelpython/latest/lib -DPYTHON_INCLUDE_DIR=/opt/intel/oneapi/intelpython/latest/include/python3.9"
})

module_cmakeargs['spfft'] = "-DCMAKE_CXX_COMPILER=mpiicpc -DCMAKE_BUILD_TYPE=RELEASE -DSPFFT_SINGLE_PRECISION=OFF -DSPFFT_MPI=ON -DSPFFT_OMP=ON " # -DSPFFT_STATIC=ON -DSPFFT_GPU_BACKEND=CUDA  " #"-DCMAKE_CUDA_COMPILER= -DCMAKE_CUDA_FLAGS=-ccbin=gcc-8 "
module_autogenargs['gsl'] = env_configuration()
module_autogenargs['hdf5'] = env_configuration() + " --enable-fortran --disable-deprecated-symbols --disable-filters --disable-parallel --with-zlib=no --with-szlib=no"
module_cmakeargs['sirius'] = "-DUSE_MKL=ON -DMKL_DEF_LIBRARY=${MKLROOT}/lib/intel64"

cwd = os.environ['PWD']
prefix=join(cwd,'core-upstream')
extra_prefixes=[join(cwd,'/opt/client-upstream')]


#example of the potentialities of the python syntax in this file
#def env_configuration():
#    cuda_gencodes=os.environ.get('CUDA_GENCODES')
#    if cuda_gencodes is None:
#      cuda_gencodes=""
#    mkl=os.environ.get('MKLROOT')
#    armpl=os.environ.get('ARMPL')
#    if mkl is not None:
#      lininc="""-I"""+mkl+"""/include"""
#      linalgs="""  --with-blas=no --with-lapack=no "--with-ext-linalg=-L"""+mkl+"""/lib/intel64 -L"""+mkl+"""/lib/ -Wl,--no-as-needed -lmkl_gf_lp64 -lmkl_gnu_thread -lmkl_core -lgomp -lpthread -lm -ldl" """
#    elif armpl is not None:
#      lininc="""-I"""+armpl+"""/include"""
#      linalgs="""  --with-blas=no --with-lapack=no  "--with-ext-linalg=-L"""+armpl+"""/lib -larmpl -lgfortran -lamath -lm -ldl" """
#    else:
#      lininc=""
#      linalgs=""
#    flags=os.environ.get('BIGDFT_OPTFLAGS')
#    if flags is None:
#      flags=""
#    return  """  "FCFLAGS="""+flags+" "+lininc+""" -O2 -fPIC -fopenmp"  "--enable-opencl" "--with-ocl-path=/usr/local/cuda" "--enable-cuda-gpu" "--with-cuda-path=/usr/local/cuda" "CFLAGS="""+flags+""" -fPIC -O2 -fopenmp" "FC=mpif90" "F77=mpif77" "FCLIBS= " "LIBS=-ldl -lstdc++ -lgfortran -lgomp" """+ linalgs +""" "NVCC_FLAGS="""+cuda_gencodes+""" --compiler-options -fPIC" "--enable-dynamic-libraries"  """
