#!/bin/sh

tarfile=$1
distrobase=$2
doc=$3

# all remaining inputs are for tar command
shift 3
tar=$*

echo "   --- Add cvode module to $tarfile"

if [ $doc = "T" ]; then
    $tar $tarfile $distrobase/doc/cvode/cv_guide.pdf    || exit 1
    $tar $tarfile $distrobase/doc/cvode/cv_examples.pdf || exit 1
fi

$tar $tarfile $distrobase/include/cvode/cvode.h         || exit 1
$tar $tarfile $distrobase/include/cvode/cvode_bandpre.h || exit 1
$tar $tarfile $distrobase/include/cvode/cvode_bbdpre.h  || exit 1
$tar $tarfile $distrobase/include/cvode/cvode_diag.h    || exit 1
$tar $tarfile $distrobase/include/cvode/cvode_direct.h  || exit 1
$tar $tarfile $distrobase/include/cvode/cvode_ls.h      || exit 1
$tar $tarfile $distrobase/include/cvode/cvode_proj.h    || exit 1
$tar $tarfile $distrobase/include/cvode/cvode_spils.h   || exit 1

$tar $tarfile $distrobase/src/cvode/LICENSE        || exit 1
$tar $tarfile $distrobase/src/cvode/NOTICE         || exit 1
$tar $tarfile $distrobase/src/cvode/README.md      || exit 1
$tar $tarfile $distrobase/src/cvode/CMakeLists.txt || exit 1

$tar $tarfile $distrobase/src/cvode/cvode.c              || exit 1
$tar $tarfile $distrobase/src/cvode/cvode_fused_stubs.c  || exit 1
$tar $tarfile $distrobase/src/cvode/cvode_fused_gpu.cpp  || exit 1
$tar $tarfile $distrobase/src/cvode/cvode_bandpre.c      || exit 1
$tar $tarfile $distrobase/src/cvode/cvode_bandpre_impl.h || exit 1
$tar $tarfile $distrobase/src/cvode/cvode_bbdpre.c       || exit 1
$tar $tarfile $distrobase/src/cvode/cvode_bbdpre_impl.h  || exit 1
$tar $tarfile $distrobase/src/cvode/cvode_diag.c         || exit 1
$tar $tarfile $distrobase/src/cvode/cvode_diag_impl.h    || exit 1
$tar $tarfile $distrobase/src/cvode/cvode_direct.c       || exit 1
$tar $tarfile $distrobase/src/cvode/cvode_impl.h         || exit 1
$tar $tarfile $distrobase/src/cvode/cvode_io.c           || exit 1
$tar $tarfile $distrobase/src/cvode/cvode_ls.c           || exit 1
$tar $tarfile $distrobase/src/cvode/cvode_ls_impl.h      || exit 1
$tar $tarfile $distrobase/src/cvode/cvode_nls.c          || exit 1
$tar $tarfile $distrobase/src/cvode/cvode_proj.c         || exit 1
$tar $tarfile $distrobase/src/cvode/cvode_proj_impl.h    || exit 1
$tar $tarfile $distrobase/src/cvode/cvode_spils.c        || exit 1

echo "   --- Add fcvode module to $tarfile"

$tar $tarfile $distrobase/src/cvode/fcmix/CMakeLists.txt || exit 1

$tar $tarfile $distrobase/src/cvode/fcmix/fcvband.c          || exit 1
$tar $tarfile $distrobase/src/cvode/fcmix/fcvbbd.c           || exit 1
$tar $tarfile $distrobase/src/cvode/fcmix/fcvbbd.h           || exit 1
$tar $tarfile $distrobase/src/cvode/fcmix/fcvbp.c            || exit 1
$tar $tarfile $distrobase/src/cvode/fcmix/fcvbp.h            || exit 1
$tar $tarfile $distrobase/src/cvode/fcmix/fcvdense.c         || exit 1
$tar $tarfile $distrobase/src/cvode/fcmix/fcvewt.c           || exit 1
$tar $tarfile $distrobase/src/cvode/fcmix/fcvjtimes.c        || exit 1
$tar $tarfile $distrobase/src/cvode/fcmix/fcvnulllinsol.c    || exit 1
$tar $tarfile $distrobase/src/cvode/fcmix/fcvnullmatrix.c    || exit 1
$tar $tarfile $distrobase/src/cvode/fcmix/fcvnullnonlinsol.c || exit 1
$tar $tarfile $distrobase/src/cvode/fcmix/fcvode.c           || exit 1
$tar $tarfile $distrobase/src/cvode/fcmix/fcvode.h           || exit 1
$tar $tarfile $distrobase/src/cvode/fcmix/fcvpreco.c         || exit 1
$tar $tarfile $distrobase/src/cvode/fcmix/fcvroot.c          || exit 1
$tar $tarfile $distrobase/src/cvode/fcmix/fcvroot.h          || exit 1
$tar $tarfile $distrobase/src/cvode/fcmix/fcvsparse.c        || exit 1

echo "   --- Add cvode F2003 interface to $tarfile"

$tar $tarfile $distrobase/src/cvode/fmod/CMakeLists.txt     || exit 1
$tar $tarfile $distrobase/src/cvode/fmod/fcvode_mod.c       || exit 1
$tar $tarfile $distrobase/src/cvode/fmod/fcvode_mod.f90     || exit 1

echo "   --- Add cvode examples to $tarfile"

$tar $tarfile $distrobase/examples/cvode/CMakeLists.txt || exit 1

$tar $tarfile $distrobase/examples/cvode/serial/README                        || exit 1
$tar $tarfile $distrobase/examples/cvode/serial/CMakeLists.txt                || exit 1
$tar $tarfile $distrobase/examples/cvode/serial/cvAdvDiff_bnd.c               || exit 1
$tar $tarfile $distrobase/examples/cvode/serial/cvAdvDiff_bndL.c              || exit 1
$tar $tarfile $distrobase/examples/cvode/serial/cvAdvDiff_bndL.out            || exit 1
$tar $tarfile $distrobase/examples/cvode/serial/cvAdvDiff_bnd.out             || exit 1
$tar $tarfile $distrobase/examples/cvode/serial/cvAnalytic_mels.c             || exit 1
$tar $tarfile $distrobase/examples/cvode/serial/cvAnalytic_mels.out           || exit 1
$tar $tarfile $distrobase/examples/cvode/serial/cvDirectDemo_ls.c             || exit 1
$tar $tarfile $distrobase/examples/cvode/serial/cvDirectDemo_ls.out           || exit 1
$tar $tarfile $distrobase/examples/cvode/serial/cvDisc_dns.c                  || exit 1
$tar $tarfile $distrobase/examples/cvode/serial/cvDisc_dns.out                || exit 1
$tar $tarfile $distrobase/examples/cvode/serial/cvDiurnal_kry_bp.c            || exit 1
$tar $tarfile $distrobase/examples/cvode/serial/cvDiurnal_kry_bp.out          || exit 1
$tar $tarfile $distrobase/examples/cvode/serial/cvDiurnal_kry.c               || exit 1
$tar $tarfile $distrobase/examples/cvode/serial/cvDiurnal_kry.out             || exit 1
$tar $tarfile $distrobase/examples/cvode/serial/cvKrylovDemo_ls.c             || exit 1
$tar $tarfile $distrobase/examples/cvode/serial/cvKrylovDemo_ls.out           || exit 1
$tar $tarfile $distrobase/examples/cvode/serial/cvKrylovDemo_ls_1.out         || exit 1
$tar $tarfile $distrobase/examples/cvode/serial/cvKrylovDemo_ls_2.out         || exit 1
$tar $tarfile $distrobase/examples/cvode/serial/cvKrylovDemo_ls_0_1.out       || exit 1
$tar $tarfile $distrobase/examples/cvode/serial/cvKrylovDemo_prec.c           || exit 1
$tar $tarfile $distrobase/examples/cvode/serial/cvKrylovDemo_prec.out         || exit 1
$tar $tarfile $distrobase/examples/cvode/serial/cvParticle_dns.c              || exit 1
$tar $tarfile $distrobase/examples/cvode/serial/cvParticle_dns.out            || exit 1
$tar $tarfile $distrobase/examples/cvode/serial/cvPendulum_dns.c              || exit 1
$tar $tarfile $distrobase/examples/cvode/serial/cvPendulum_dns.out            || exit 1
$tar $tarfile $distrobase/examples/cvode/serial/cvRoberts_dns.c               || exit 1
$tar $tarfile $distrobase/examples/cvode/serial/cvRoberts_dns.out             || exit 1
$tar $tarfile $distrobase/examples/cvode/serial/cvRoberts_dns_constraints.c   || exit 1
$tar $tarfile $distrobase/examples/cvode/serial/cvRoberts_dns_constraints.out || exit 1
$tar $tarfile $distrobase/examples/cvode/serial/cvRoberts_dnsL.c              || exit 1
$tar $tarfile $distrobase/examples/cvode/serial/cvRoberts_dnsL.out            || exit 1
$tar $tarfile $distrobase/examples/cvode/serial/cvRoberts_dns_uw.c            || exit 1
$tar $tarfile $distrobase/examples/cvode/serial/cvRoberts_dns_uw.out          || exit 1
$tar $tarfile $distrobase/examples/cvode/serial/cvRoberts_dns_negsol.c        || exit 1
$tar $tarfile $distrobase/examples/cvode/serial/cvRoberts_dns_negsol.out      || exit 1
$tar $tarfile $distrobase/examples/cvode/serial/cvRoberts_klu.c               || exit 1
$tar $tarfile $distrobase/examples/cvode/serial/cvRoberts_klu.out             || exit 1
$tar $tarfile $distrobase/examples/cvode/serial/cvRoberts_block_klu.c         || exit 1
$tar $tarfile $distrobase/examples/cvode/serial/cvRoberts_block_klu.out       || exit 1
$tar $tarfile $distrobase/examples/cvode/serial/cvRoberts_sps.c               || exit 1
$tar $tarfile $distrobase/examples/cvode/serial/cvRoberts_sps.out             || exit 1
$tar $tarfile $distrobase/examples/cvode/serial/plot_cvParticle.py            || exit 1
$tar $tarfile $distrobase/examples/cvode/serial/plot_cvPendulum.py            || exit 1

$tar $tarfile $distrobase/examples/cvode/fcmix_serial/README                         || exit 1
$tar $tarfile $distrobase/examples/cvode/fcmix_serial/CMakeLists.txt                 || exit 1
$tar $tarfile $distrobase/examples/cvode/fcmix_serial/fcvAdvDiff_bnd.f               || exit 1
$tar $tarfile $distrobase/examples/cvode/fcmix_serial/fcvAdvDiff_bnd.out             || exit 1
$tar $tarfile $distrobase/examples/cvode/fcmix_serial/fcvDiurnal_kry_bp.f            || exit 1
$tar $tarfile $distrobase/examples/cvode/fcmix_serial/fcvDiurnal_kry_bp.out          || exit 1
$tar $tarfile $distrobase/examples/cvode/fcmix_serial/fcvDiurnal_kry.f               || exit 1
$tar $tarfile $distrobase/examples/cvode/fcmix_serial/fcvDiurnal_kry.out             || exit 1
$tar $tarfile $distrobase/examples/cvode/fcmix_serial/fcvRoberts_dns.f               || exit 1
$tar $tarfile $distrobase/examples/cvode/fcmix_serial/fcvRoberts_dns.out             || exit 1
$tar $tarfile $distrobase/examples/cvode/fcmix_serial/fcvRoberts_dns_constraints.f   || exit 1
$tar $tarfile $distrobase/examples/cvode/fcmix_serial/fcvRoberts_dns_constraints.out || exit 1
$tar $tarfile $distrobase/examples/cvode/fcmix_serial/fcvRoberts_dnsL.f              || exit 1
$tar $tarfile $distrobase/examples/cvode/fcmix_serial/fcvRoberts_dnsL.out            || exit 1
$tar $tarfile $distrobase/examples/cvode/fcmix_serial/fcvRoberts_klu.f               || exit 1
$tar $tarfile $distrobase/examples/cvode/fcmix_serial/fcvRoberts_klu.out             || exit 1
$tar $tarfile $distrobase/examples/cvode/fcmix_serial/fcvRoberts_sps.f               || exit 1
$tar $tarfile $distrobase/examples/cvode/fcmix_serial/fcvRoberts_sps.out             || exit 1

$tar $tarfile $distrobase/examples/cvode/F2003_serial/README                            || exit 1
$tar $tarfile $distrobase/examples/cvode/F2003_serial/CMakeLists.txt                    || exit 1
$tar $tarfile $distrobase/examples/cvode/F2003_serial/cv_analytic_fp_f2003.f90          || exit 1
$tar $tarfile $distrobase/examples/cvode/F2003_serial/cv_analytic_fp_f2003.out          || exit 1
$tar $tarfile $distrobase/examples/cvode/F2003_serial/cv_analytic_sys_dns_f2003.f90     || exit 1
$tar $tarfile $distrobase/examples/cvode/F2003_serial/cv_analytic_sys_dns_f2003.out     || exit 1
$tar $tarfile $distrobase/examples/cvode/F2003_serial/cv_analytic_sys_dns_jac_f2003.f90 || exit 1
$tar $tarfile $distrobase/examples/cvode/F2003_serial/cv_analytic_sys_dns_jac_f2003.out || exit 1
$tar $tarfile $distrobase/examples/cvode/F2003_serial/cv_analytic_sys_klu_f2003.f90     || exit 1
$tar $tarfile $distrobase/examples/cvode/F2003_serial/cv_analytic_sys_klu_f2003.out     || exit 1
$tar $tarfile $distrobase/examples/cvode/F2003_serial/cv_brusselator_dns_f2003.f90      || exit 1
$tar $tarfile $distrobase/examples/cvode/F2003_serial/cv_brusselator_dns_f2003.out      || exit 1

$tar $tarfile $distrobase/examples/cvode/C_openmp/README                || exit 1
$tar $tarfile $distrobase/examples/cvode/C_openmp/CMakeLists.txt        || exit 1
$tar $tarfile $distrobase/examples/cvode/C_openmp/cvAdvDiff_bnd_omp.c   || exit 1
$tar $tarfile $distrobase/examples/cvode/C_openmp/cvAdvDiff_bnd_omp.out || exit 1

$tar $tarfile $distrobase/examples/cvode/C_openmpdev/README                   || exit 1
$tar $tarfile $distrobase/examples/cvode/C_openmpdev/CMakeLists.txt           || exit 1
$tar $tarfile $distrobase/examples/cvode/C_openmpdev/cvAdvDiff_kry_ompdev.c   || exit 1
$tar $tarfile $distrobase/examples/cvode/C_openmpdev/cvAdvDiff_kry_ompdev.out || exit 1

$tar $tarfile $distrobase/examples/cvode/parallel/README                  || exit 1
$tar $tarfile $distrobase/examples/cvode/parallel/CMakeLists.txt          || exit 1
$tar $tarfile $distrobase/examples/cvode/parallel/cvAdvDiff_non_p.c       || exit 1
$tar $tarfile $distrobase/examples/cvode/parallel/cvAdvDiff_non_p.out     || exit 1
$tar $tarfile $distrobase/examples/cvode/parallel/cvAdvDiff_diag_p.c      || exit 1
$tar $tarfile $distrobase/examples/cvode/parallel/cvAdvDiff_diag_p.out    || exit 1
$tar $tarfile $distrobase/examples/cvode/parallel/cvDiurnal_kry_bbd_p.c   || exit 1
$tar $tarfile $distrobase/examples/cvode/parallel/cvDiurnal_kry_bbd_p.out || exit 1
$tar $tarfile $distrobase/examples/cvode/parallel/cvDiurnal_kry_p.c       || exit 1
$tar $tarfile $distrobase/examples/cvode/parallel/cvDiurnal_kry_p.out     || exit 1

$tar $tarfile $distrobase/examples/cvode/superludist/README                   || exit 1
$tar $tarfile $distrobase/examples/cvode/superludist/CMakeLists.txt           || exit 1
$tar $tarfile $distrobase/examples/cvode/superludist/cvAdvDiff_sludist.cpp    || exit 1
$tar $tarfile $distrobase/examples/cvode/superludist/cvAdvDiff_sludist_32.out || exit 1
$tar $tarfile $distrobase/examples/cvode/superludist/cvAdvDiff_sludist_64.out || exit 1

$tar $tarfile $distrobase/examples/cvode/parhyp/README               || exit 1
$tar $tarfile $distrobase/examples/cvode/parhyp/CMakeLists.txt       || exit 1
$tar $tarfile $distrobase/examples/cvode/parhyp/cvAdvDiff_non_ph.c   || exit 1
$tar $tarfile $distrobase/examples/cvode/parhyp/cvAdvDiff_non_ph.out || exit 1

$tar $tarfile $distrobase/examples/cvode/petsc/README                  || exit 1
$tar $tarfile $distrobase/examples/cvode/petsc/CMakeLists.txt          || exit 1
$tar $tarfile $distrobase/examples/cvode/petsc/cv_petsc_ex7.c          || exit 1
$tar $tarfile $distrobase/examples/cvode/petsc/cv_petsc_ex7.out        || exit 1
$tar $tarfile $distrobase/examples/cvode/petsc/cvAdvDiff_petsc.c       || exit 1
$tar $tarfile $distrobase/examples/cvode/petsc/cvAdvDiff_petsc.out     || exit 1

$tar $tarfile $distrobase/examples/cvode/C_mpimanyvector/README                       || exit 1
$tar $tarfile $distrobase/examples/cvode/C_mpimanyvector/CMakeLists.txt               || exit 1
$tar $tarfile $distrobase/examples/cvode/C_mpimanyvector/cvDiurnal_kry_mpimanyvec.c   || exit 1
$tar $tarfile $distrobase/examples/cvode/C_mpimanyvector/cvDiurnal_kry_mpimanyvec.out || exit 1

$tar $tarfile $distrobase/examples/cvode/fcmix_parallel/README                || exit 1
$tar $tarfile $distrobase/examples/cvode/fcmix_parallel/CMakeLists.txt        || exit 1
$tar $tarfile $distrobase/examples/cvode/fcmix_parallel/fcvDiag_non_p.f       || exit 1
$tar $tarfile $distrobase/examples/cvode/fcmix_parallel/fcvDiag_non_p.out     || exit 1
$tar $tarfile $distrobase/examples/cvode/fcmix_parallel/fcvDiag_kry_bbd_p.f   || exit 1
$tar $tarfile $distrobase/examples/cvode/fcmix_parallel/fcvDiag_kry_bbd_p.out || exit 1
$tar $tarfile $distrobase/examples/cvode/fcmix_parallel/fcvDiag_kry_p.f       || exit 1
$tar $tarfile $distrobase/examples/cvode/fcmix_parallel/fcvDiag_kry_p.out     || exit 1

$tar $tarfile $distrobase/examples/cvode/cuda/README                                  || exit 1
$tar $tarfile $distrobase/examples/cvode/cuda/CMakeLists.txt                          || exit 1
$tar $tarfile $distrobase/examples/cvode/cuda/cvAdvDiff_diag_cuda.cu                  || exit 1
$tar $tarfile $distrobase/examples/cvode/cuda/cvAdvDiff_diag_cuda_0_0.out             || exit 1
$tar $tarfile $distrobase/examples/cvode/cuda/cvAdvDiff_diag_cuda_0_1.out             || exit 1
$tar $tarfile $distrobase/examples/cvode/cuda/cvAdvDiff_diag_cuda_1_1.out             || exit 1
$tar $tarfile $distrobase/examples/cvode/cuda/cvAdvDiff_kry_cuda.cu                   || exit 1
$tar $tarfile $distrobase/examples/cvode/cuda/cvAdvDiff_kry_cuda.out                  || exit 1
$tar $tarfile $distrobase/examples/cvode/cuda/cvAdvDiff_kry_cuda_managed.cu           || exit 1
$tar $tarfile $distrobase/examples/cvode/cuda/cvAdvDiff_kry_cuda_managed.out          || exit 1
$tar $tarfile $distrobase/examples/cvode/cuda/cvRoberts_block_cusolversp_batchqr.cu   || exit 1
$tar $tarfile $distrobase/examples/cvode/cuda/cvRoberts_block_cusolversp_batchqr.out  || exit 1

$tar $tarfile $distrobase/examples/cvode/hip/README                                 || exit 1
$tar $tarfile $distrobase/examples/cvode/hip/CMakeLists.txt                         || exit 1
$tar $tarfile $distrobase/examples/cvode/hip/cvAdvDiff_diag_hip.cpp                 || exit 1
$tar $tarfile $distrobase/examples/cvode/hip/cvAdvDiff_diag_hip_0_0.out             || exit 1
$tar $tarfile $distrobase/examples/cvode/hip/cvAdvDiff_diag_hip_0_1.out             || exit 1
$tar $tarfile $distrobase/examples/cvode/hip/cvAdvDiff_diag_hip_1_1.out             || exit 1
$tar $tarfile $distrobase/examples/cvode/hip/cvAdvDiff_kry_hip.cpp                  || exit 1
$tar $tarfile $distrobase/examples/cvode/hip/cvAdvDiff_kry_hip.out                  || exit 1

$tar $tarfile $distrobase/examples/cvode/magma/README                         || exit 1
$tar $tarfile $distrobase/examples/cvode/magma/CMakeLists.txt                 || exit 1
$tar $tarfile $distrobase/examples/cvode/magma/cvRoberts_blockdiag_magma.cpp  || exit 1
$tar $tarfile $distrobase/examples/cvode/magma/cvRoberts_blockdiag_magma.out  || exit 1

$tar $tarfile $distrobase/examples/cvode/raja/README                 || exit 1
$tar $tarfile $distrobase/examples/cvode/raja/CMakeLists.txt         || exit 1
$tar $tarfile $distrobase/examples/cvode/raja/cvAdvDiff_kry_raja.cpp  || exit 1
$tar $tarfile $distrobase/examples/cvode/raja/cvAdvDiff_kry_raja.out || exit 1

$tar $tarfile $distrobase/examples/cvode/CXX_onemkl/CMakeLists.txt                  || exit 1
$tar $tarfile $distrobase/examples/cvode/CXX_onemkl/README                          || exit 1
$tar $tarfile $distrobase/examples/cvode/CXX_onemkl/cvRoberts_blockdiag_onemkl.cpp  || exit 1
$tar $tarfile $distrobase/examples/cvode/CXX_onemkl/cvRoberts_blockdiag_onemkl.out  || exit 1

$tar $tarfile $distrobase/examples/cvode/CXX_serial/CMakeLists.txt || exit 1
$tar $tarfile $distrobase/examples/cvode/CXX_serial/README         || exit 1
$tar $tarfile $distrobase/examples/cvode/CXX_serial/cv_heat2D.cpp  || exit 1
$tar $tarfile $distrobase/examples/cvode/CXX_serial/cv_heat2D.out  || exit 1
$tar $tarfile $distrobase/examples/cvode/CXX_serial/plot_heat2D.py || exit 1

$tar $tarfile $distrobase/examples/cvode/CXX_parallel/CMakeLists.txt           || exit 1
$tar $tarfile $distrobase/examples/cvode/CXX_parallel/README                   || exit 1
$tar $tarfile $distrobase/examples/cvode/CXX_parallel/cv_heat2D_p.cpp          || exit 1
$tar $tarfile $distrobase/examples/cvode/CXX_parallel/cv_heat2D_p_--np_2_2.out || exit 1
$tar $tarfile $distrobase/examples/cvode/CXX_parallel/plot_heat2D_p.py         || exit 1

$tar $tarfile $distrobase/examples/cvode/CXX_parhyp/CMakeLists.txt                    || exit 1
$tar $tarfile $distrobase/examples/cvode/CXX_parhyp/README                            || exit 1
$tar $tarfile $distrobase/examples/cvode/CXX_parhyp/cv_heat2D_hypre_ls.cpp            || exit 1
$tar $tarfile $distrobase/examples/cvode/CXX_parhyp/cv_heat2D_hypre_ls_--np_2_2.out   || exit 1
$tar $tarfile $distrobase/examples/cvode/CXX_parhyp/cv_heat2D_hypre_pfmg.cpp          || exit 1
$tar $tarfile $distrobase/examples/cvode/CXX_parhyp/cv_heat2D_hypre_pfmg_--np_2_2.out || exit 1
$tar $tarfile $distrobase/examples/cvode/CXX_parhyp/plot_heat2D_p.py                  || exit 1

$tar $tarfile $distrobase/examples/cvode/CXX_sycl/CMakeLists.txt          || exit 1
$tar $tarfile $distrobase/examples/cvode/CXX_sycl/README                  || exit 1
$tar $tarfile $distrobase/examples/cvode/CXX_sycl/cvAdvDiff_kry_sycl.cpp  || exit 1
$tar $tarfile $distrobase/examples/cvode/CXX_sycl/cvAdvDiff_kry_sycl.out  || exit 1
