#!/bin/ksh

# ICON
#
# ------------------------------------------
# Copyright (C) 2004-2026, DWD, MPI-M, DKRZ, KIT, ETH, MeteoSwiss
# Contact information: icon-model.org
# See AUTHORS.TXT for a list of authors
# See LICENSES/ for license information
# SPDX-License-Identifier: BSD-3-Clause
# ------------------------------------------

# usage get_atmo <icon-dev full path> <atmo only full path>
#   links from the <icon-dev full path> the atmosphere only files to <atmo only full path>
set -x
icon_dev_from=$1
icon_dev_to=$2

if [ ! -d ${icon_dev_to} ] ; then
  mkdir -p ${icon_dev_to}
fi

# cd ${icon_dev_to}


#-----------------------------------------------------------------------------------
link_source_list()
{
  source_folder=$1
  source_files_list="$2"

  if [ x${source_folder} != "x" ] ; then
    if [ ! -d ${icon_dev_to}/${source_folder} ] ; then
      mkdir -p ${icon_dev_to}/${source_folder}
    fi
  fi

  if [ "${source_files_list}" == "all" ] ; then
    ln -s ${icon_dev_from}/${source_folder}*  ${icon_dev_to}/${source_folder}
  else
    for source_file in ${source_files_list}
    do
      ln -s ${icon_dev_from}/${source_folder}${source_file}  ${icon_dev_to}/${source_folder}
    done
  fi

}


#-----------------------------------------------------------------------------------
# first get all
link_list=`ls $icon_dev_from`
link_source_list "" "$link_list"
#-----------------------------------------------------------------------------------


#-----------------------------------------------------------------------------------
# get src
rm $icon_dev_to/src

cd $icon_dev_from/src
atm_list=`ls -d atm_*`
cd-

link_source_list "src/" "$atm_list"

link_source_list "src/" "advection
art_interface
CMakeLists.txt
configure_model
diagnostics
drivers
include
io
lnd_phy_jsbach
lnd_phy_nwp
lnd_phy_schemes
namelists
parallel_infrastructure
shared
shr_horizontal
templates
testbed
testcases"


cat > ${icon_dev_to}/config/multiple_builds << EOF
#==============================================
# This file defines multiple builds for ICON
#==============================================
build_folder=gcc_yMyO configure_options=--with-fortran=gcc --with-mpi  --with-openmp --disable-ocean --disable-jsbach  --with-yac=no
build_folder=gcc_yMnO configure_options=--with-fortran=gcc --with-mpi                --disable-ocean --disable-jsbach  --with-yac=no

#==============================================
# Define the run scripts in run/ to be common along the following builds
run_scripts=*
EOF

ln -s ${icon_dev_to}/scripts/building/create_builds ${icon_dev_to}

exit
