SCRIPT_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

EXECUTION_SPACE=$1
EXECUTION_SPACE_DIR=$2
SCALAR_TYPE=$3
INDEX_TYPE=$4
LAYOUT_TYPE=$5
RANK=$6
RANK_STARS=$7


echo "KOKKOS_IMPL_VIEWCOPY_ETI_AVAIL(${SCALAR_TYPE}${RANK_STARS},${LAYOUT_TYPE},LayoutRight, KOKKOS_IMPL_VIEWCOPY_ETI_AVAIL_EXECSPACE,${INDEX_TYPE})" >> common/Kokkos_ViewFillCopyETIAvail_Macros.hpp
echo "KOKKOS_IMPL_VIEWCOPY_ETI_AVAIL(${SCALAR_TYPE}${RANK_STARS},${LAYOUT_TYPE},LayoutLeft,  KOKKOS_IMPL_VIEWCOPY_ETI_AVAIL_EXECSPACE,${INDEX_TYPE})" >> common/Kokkos_ViewFillCopyETIAvail_Macros.hpp
echo "KOKKOS_IMPL_VIEWCOPY_ETI_AVAIL(${SCALAR_TYPE}${RANK_STARS},${LAYOUT_TYPE},LayoutStride,KOKKOS_IMPL_VIEWCOPY_ETI_AVAIL_EXECSPACE,${INDEX_TYPE})" >> common/Kokkos_ViewFillCopyETIAvail_Macros.hpp
echo "KOKKOS_IMPL_VIEWFILL_ETI_AVAIL(${SCALAR_TYPE}${RANK_STARS},${LAYOUT_TYPE}, KOKKOS_IMPL_VIEWCOPY_ETI_AVAIL_EXECSPACE,${INDEX_TYPE})" >> common/Kokkos_ViewFillCopyETIAvail_Macros.hpp
echo "KOKKOS_IMPL_VIEWCOPY_ETI_DECL(${SCALAR_TYPE}${RANK_STARS},${LAYOUT_TYPE},LayoutRight, KOKKOS_IMPL_VIEWCOPY_ETI_AVAIL_EXECSPACE,${INDEX_TYPE})" >> common/Kokkos_ViewFillCopyETIDecl_Macros.hpp
echo "KOKKOS_IMPL_VIEWCOPY_ETI_DECL(${SCALAR_TYPE}${RANK_STARS},${LAYOUT_TYPE},LayoutLeft,  KOKKOS_IMPL_VIEWCOPY_ETI_AVAIL_EXECSPACE,${INDEX_TYPE})" >> common/Kokkos_ViewFillCopyETIDecl_Macros.hpp
echo "KOKKOS_IMPL_VIEWCOPY_ETI_DECL(${SCALAR_TYPE}${RANK_STARS},${LAYOUT_TYPE},LayoutStride,KOKKOS_IMPL_VIEWCOPY_ETI_AVAIL_EXECSPACE,${INDEX_TYPE})" >> common/Kokkos_ViewFillCopyETIDecl_Macros.hpp
echo "KOKKOS_IMPL_VIEWFILL_ETI_DECL(${SCALAR_TYPE}${RANK_STARS},${LAYOUT_TYPE},KOKKOS_IMPL_VIEWCOPY_ETI_AVAIL_EXECSPACE,${INDEX_TYPE})" >> common/Kokkos_ViewFillCopyETIDecl_Macros.hpp


FileName=${EXECUTION_SPACE_DIR}/Kokkos_${EXECUTION_SPACE_DIR}_ViewCopyETIInst_${INDEX_TYPE}_${SCALAR_TYPE}_${LAYOUT_TYPE}_Rank${RANK}.cpp
ObjectName=Kokkos_${EXECUTION_SPACE_DIR}_ViewCopyETIInst_${INDEX_TYPE}_${SCALAR_TYPE}_${LAYOUT_TYPE}_Rank${RANK}.o

cp ${SCRIPT_PATH}/../../LICENSE ${FileName}

echo "" >> ${FileName}
echo "#define KOKKOS_IMPL_COMPILING_LIBRARY true" >> ${FileName}
echo "#include<Kokkos_Core.hpp>" >> ${FileName}
echo "namespace Kokkos {" >> ${FileName}
echo "namespace Impl {" >> ${FileName}
echo "KOKKOS_IMPL_VIEWCOPY_ETI_INST(${SCALAR_TYPE}${RANK_STARS},${LAYOUT_TYPE},LayoutRight, ${EXECUTION_SPACE},${INDEX_TYPE})" >> ${FileName}
echo "KOKKOS_IMPL_VIEWCOPY_ETI_INST(${SCALAR_TYPE}${RANK_STARS},${LAYOUT_TYPE},LayoutLeft,  ${EXECUTION_SPACE},${INDEX_TYPE})" >> ${FileName}
echo "KOKKOS_IMPL_VIEWCOPY_ETI_INST(${SCALAR_TYPE}${RANK_STARS},${LAYOUT_TYPE},LayoutStride,${EXECUTION_SPACE},${INDEX_TYPE})" >> ${FileName}
echo "KOKKOS_IMPL_VIEWFILL_ETI_INST(${SCALAR_TYPE}${RANK_STARS},${LAYOUT_TYPE},${EXECUTION_SPACE},${INDEX_TYPE})" >> ${FileName}
echo "" >> ${FileName}
echo "}" >> ${FileName}
echo "}" >> ${FileName}

echo "${ObjectName}: \$(KOKKOS_CPP_DEPENDS) \$(KOKKOS_ETI_PATH)/${FileName}" >> ${EXECUTION_SPACE_DIR}/Makefile.eti_${EXECUTION_SPACE_DIR}
echo -e "\t\$(CXX) \$(KOKKOS_CPPFLAGS) \$(KOKKOS_CXXFLAGS) \$(CXXFLAGS) -c \$(KOKKOS_ETI_PATH)/${FileName}" >> ${EXECUTION_SPACE_DIR}/Makefile.eti_${EXECUTION_SPACE_DIR}
