# load Intel compilers and mkl
source /theoryfs2/common/software/intel2015/bin/compilervars.sh intel64
# force static link to Intel mkl, except for openmp
MKLROOT=/theoryfs2/common/software/intel2015/composer_xe_2015.3.187/mkl/lib/intel64
LAPACK_INTERJECT="${MKLROOT}/libmkl_intel_lp64.a ${MKLROOT}/libmkl_intel_thread.a ${MKLROOT}/libmkl_core.a -liomp5 -lm"
#INTEL="-L/theoryfs2/common/software/intel2015/composer_xe_2015.3.187/compiler/lib/intel64:/theoryfs2/common/software/intel2015/composer_xe_2015.3.187/mpirt/lib/intel64:/theoryfs2/common/software/intel2015/composer_xe_2015.3.187/ipp/../compiler/lib/intel64:/theoryfs2/common/software/intel2015/composer_xe_2015.3.187/ipp/lib/intel64:/theoryfs2/common/software/intel2015/composer_xe_2015.3.187/ipp/tools/intel64/perfsys:/theoryfs2/common/software/intel2015/composer_xe_2015.3.187/compiler/lib/intel64:/theoryfs2/common/software/intel2015/composer_xe_2015.3.187/mkl/lib/intel64:/theoryfs2/common/software/intel2015/composer_xe_2015.3.187/tbb/lib/intel64/gcc4.4:/theoryfs2/common/software/intel2015/composer_xe_2015.3.187/debugger/libipt/intel64/lib"
# link against older libc for generic linux
TLIBC=/theoryfs2/ds/cdsgroup/psi4-compile/psi4cmake/psi4/glibc2.12rpm
LIBC_INTERJECT="-L${TLIBC}/usr/lib64 ${TLIBC}/lib64/libpthread.so.0 ${TLIBC}/lib64/libc.so.6"
LAPACK_INTERJECT="-Wl,-Bstatic;${MKLROOT}/libmkl_intel_lp64.a;${MKLROOT}/libmkl_intel_thread.a;${MKLROOT}/libmkl_core.a;-Wl,-Bdynamic;${PREFIX}/lib/libiomp5.so;-lm"
#    -DLAPACK_LIBRARIES="${LIBC_INTERJECT} ${LAPACK_INTERJECT}" \
#    -DLAPACK_LIBRARIES="${LAPACK_INTERJECT}" \
#    -DMKL=ON \
# round off with pre-detected dependencies
MCONDA=${PREFIX}/lib
HDF5_INTERJECT="-L${MCONDA};-lhdf5;-lhdf5_hl;-lhdf5;-lpthread;-lz;-lrt;-ldl;-lm"
GSL_INTERJECT="-L${MCONDA};-lgsl;-lgslcblas;-lm"

mkdir build
cd build
cmake \
    -DCMAKE_CXX_COMPILER=icpc \
    -DMKL=ON \
    -DBUILD_DOXYGEN=OFF \
    -DBUILD_SPHINX=OFF \
    -DENABLE_TESTS=OFF \
    -DENABLE_GENERIC=ON \
    -DENABLE_XHOST=OFF \
    -DLAPACK_LIBRARIES="${LAPACK_INTERJECT}" \
    -DGSL_LIBRARIES="${GSL_INTERJECT}" \
    -DHDF5_LIBRARIES="${HDF5_INTERJECT}" \
    -DHDF5_INCLUDE_DIRS="${MCONDA}/../include" \
    -DCMAKE_INSTALL_PREFIX=${PREFIX} \
    -DCMAKE_INSTALL_LIBDIR=lib \
    ${SRC_DIR}
make -j${CPU_COUNT} VERBOSE=1
make install

    #-DLAPACK_LIBRARIES="${LIBC_INTERJECT} ${LAPACK_INTERJECT}" \
    #-MKL=ON \
#NLIBC=""
#LIBC_INTERJECT="-L${TLIBC}/usr/lib64 ${TLIBC}/lib64/libpthread.so.0 ${TTLIBC}/lib64/libgcc_s.so.1 ${TLIBC}/lib64/libc.so.6 ${TTLIBC}/lib64/libgcc_s.so.1"
#LIBC_INTERJECT="-L${TLIBC}/usr/lib64 ${TLIBC}/lib64/libpthread.so.0 ${TLIBC}/lib64/libc.so.6 ${NLIBC}/lib64/libgcc_s.so.1 ${TLIBC}/lib64/libc.so.6"
#make -j${CPU_COUNT} VERBOSE=1

#           linux-vdso.so.1 =>  (0x00007ffd5ebbe000)
#    /lib64/ld-linux-x86-64.so.2 (0x00007f47cd897000)
#           libchemps2.so.2 => /theoryfs2/ds/cdsgroup/miniconda/envs/_build/bin/../lib/libchemps2.so.2 (0x00007f47cd2fd000)
#      libmkl_intel_lp64.so => /theoryfs2/common/software/intel2015/composer_xe_2015.3.187/mkl/lib/intel64/libmkl_intel_lp64.so (0x00007f47cc9e6000)
#    libmkl_intel_thread.so => /theoryfs2/common/software/intel2015/composer_xe_2015.3.187/mkl/lib/intel64/libmkl_intel_thread.so (0x00007f47cb596000)
#            libmkl_core.so => /theoryfs2/common/software/intel2015/composer_xe_2015.3.187/mkl/lib/intel64/libmkl_core.so (0x00007f47c9a28000)
#               libiomp5.so => /theoryfs2/ds/cdsgroup/miniconda/envs/_build/bin/../lib/libiomp5.so (0x00007f47c96e5000)
#             libhdf5.so.10 => /theoryfs2/ds/cdsgroup/miniconda/envs/_build/bin/../lib/libhdf5.so.10 (0x00007f47c8ee3000)
#          libhdf5_hl.so.10 => /theoryfs2/ds/cdsgroup/miniconda/envs/_build/bin/../lib/libhdf5_hl.so.10 (0x00007f47c8cc4000)
#                 libz.so.1 => /theoryfs2/ds/cdsgroup/miniconda/envs/_build/bin/../lib/libz.so.1 (0x00007f47c8891000)
#               libgsl.so.0 => /theoryfs2/ds/cdsgroup/miniconda/envs/_build/bin/../lib/libgsl.so.0 (0x00007f47c8042000)
#          libgslcblas.so.0 => /theoryfs2/ds/cdsgroup/miniconda/envs/_build/bin/../lib/libgslcblas.so.0 (0x00007f47c7e03000)
#             libgcc_s.so.1 => /theoryfs2/ds/cdsgroup/miniconda/envs/_build/bin/../lib/./libgcc_s.so.1 (0x00007f47c782b000)
#           libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f47c8aa8000)
#                 libc.so.6 => /lib64/libc.so.6 (0x00007f47c7a42000)
#                 libm.so.6 => /lib64/libm.so.6 (0x00007f47c93bd000)
#                librt.so.1 => /lib64/librt.so.1 (0x00007f47c8689000)
#                libdl.so.2 => /lib64/libdl.so.2 (0x00007f47c8485000)


#/theoryfs2/common/software/intel2015/composer_xe_2015.3.187/bin/intel64/icpc \
#  -g -O3  -qopenmp -ipo -static-libstdc++ -static-libgcc -static-intel -wd10237 \
#  CMakeFiles/chemps2bin.dir/executable.cpp.o  -o chemps2 \
#
# -L/theoryfs2/common/software/intel2015/composer_xe_2015.3.187/compiler/lib/intel64
#:/theoryfs2/common/software/intel2015/composer_xe_2015.3.187/mpirt/lib/intel64
#:/theoryfs2/common/software/intel2015/composer_xe_2015.3.187/ipp/../compiler/lib/intel64
#:/theoryfs2/common/software/intel2015/composer_xe_2015.3.187/ipp/lib/intel64
#:/theoryfs2/common/software/intel2015/composer_xe_2015.3.187/ipp/tools/intel64/perfsys
#:/theoryfs2/common/software/intel2015/composer_xe_2015.3.187/compiler/lib/intel64
#:/theoryfs2/common/software/intel2015/composer_xe_2015.3.187/mkl/lib/intel64
#:/theoryfs2/common/software/intel2015/composer_xe_2015.3.187/tbb/lib/intel64/gcc4.4
#:/theoryfs2/common/software/intel2015/composer_xe_2015.3.187/debugger/libipt/intel64/lib
##LAPACK_INTERJECT="${MKLROOT}/libmkl_intel_lp64.a ${MKLROOT}/libmkl_intel_thread.a ${MKLROOT}/libmkl_core.a -liomp5 -lm"
#
#      libmkl_intel_lp64.so => /theoryfs2/common/software/intel2015/composer_xe_2015.3.187/mkl/lib/intel64/libmkl_intel_lp64.so (0x00007f31a8b79000)
#    libmkl_intel_thread.so => /theoryfs2/common/software/intel2015/composer_xe_2015.3.187/mkl/lib/intel64/libmkl_intel_thread.so (0x00007f31a7729000)
#            libmkl_core.so => /theoryfs2/common/software/intel2015/composer_xe_2015.3.187/mkl/lib/intel64/libmkl_core.so (0x00007f31a5bbb000)
#                      MKLROOT=/theoryfs2/common/software/intel2015/composer_xe_2015.3.187/mkl/lib/intel64
#
#
#
#
#  -L/theoryfs2/ds/cdsgroup/miniconda/conda-bld/work/build/CheMPS2 \
#  -L/theoryfs2/ds/cdsgroup/miniconda/lib \
#  -rdynamic -lchemps2 
#  -lmkl_intel_lp64 -lmkl_intel_thread -lmkl_core
#  /theoryfs2/ds/cdsgroup/miniconda/envs/_build/lib/libiomp5.so
#  -lm
#  -L/theoryfs2/ds/cdsgroup/miniconda/envs/_build/lib
#  -lhdf5 -lhdf5_hl -lhdf5 -lpthread -lz -lrt -ldl -lm
#  -L/theoryfs2/ds/cdsgroup/miniconda/envs/_build/lib
#  -lgsl -lgslcblas -lm -lhdf5 -lhdf5_hl -lpthread -lz -lrt -ldl -lgsl -lgslcblas
#
#
#  -Wl,-rpath,/theoryfs2/common/software/intel2015/composer_xe_2015.3.187/compiler/lib/intel64
#:/theoryfs2/common/software/intel2015/composer_xe_2015.3.187/mpirt/lib/intel64
#:/theoryfs2/common/software/intel2015/composer_xe_2015.3.187/ipp/../compiler/lib/intel64
#:/theoryfs2/common/software/intel2015/composer_xe_2015.3.187/ipp/lib/intel64
#:/theoryfs2/common/software/intel2015/composer_xe_2015.3.187/ipp/tools/intel64/perfsys
#:/theoryfs2/common/software/intel2015/composer_xe_2015.3.187/compiler/lib/intel64
#:/theoryfs2/common/software/intel2015/composer_xe_2015.3.187/mkl/lib/intel64
#:/theoryfs2/common/software/intel2015/composer_xe_2015.3.187/tbb/lib/intel64/gcc4.4
#:/theoryfs2/common/software/intel2015/composer_xe_2015.3.187/debugger/libipt/intel64/lib
#:/theoryfs2/ds/cdsgroup/miniconda/conda-bld/work/build/CheMPS2
#:/theoryfs2/ds/cdsgroup/miniconda/envs/_build/lib
#:/theoryfs2/ds/cdsgroup/miniconda/lib
#
