Skip to content
Snippets Groups Projects
maketools 5.48 KiB
Newer Older
Guillaume Samson's avatar
Guillaume Samson committed
#!/bin/bash
set -o posix
#set -x
Guillaume Samson's avatar
Guillaume Samson committed
#set -u 
#set -e
#+
#
# ===============
# maketools
# ===============
#
# --------------------------
# Compile NEMO
# --------------------------
#
# SYNOPSIS
# ========
#
# ::
#
#  $ maketools
#
#
# DESCRIPTION
# ===========
#
#
# This script aims :
#
# - to choose a tool to compile
# - to choose compiler options  
# - to compile this tool
#
#  Variables used :
#
#  From user input
#
# - CUR_CONF    : configuration to be created
Guillaume Samson's avatar
Guillaume Samson committed
# - CMP_NAM     : compiler name 
# - NBR_PRC     : number of processes used to compile  
#
#  Locally defined :
#
# - MAIN_DIR : self explaining
# - MODELES_DIR :   "    "    " 
# - TOOLS_DIR   :   "    "    " 
# - NEMO_DIR    :   "    "    "
#
# EXAMPLES
# ========
#
# ::
#
#  $ ./maketools -t ifort_osx - j3 -n NESTING
#
#
# TODO
# ====
#
#
# EVOLUTIONS
# ==========
#
# $Id: maketools 12415 2020-02-19 20:29:26Z smueller $
#
#
#
#   * creation
#
#-

#- Local variables ---
b_n=$(basename ${0})
TOOLS_DIR=$(cd $(dirname "$0"); pwd)
MAIN_DIR=${TOOLS_DIR%/tools}
COMPIL_DIR=${MAIN_DIR}/mk
NEMO_DIR=${MAIN_DIR}/NEMO
Guillaume Samson's avatar
Guillaume Samson committed
#-
#- FCM and functions location ---
PATH=${MAIN_DIR}/ext/FCM/bin:$PATH
Guillaume Samson's avatar
Guillaume Samson committed

#-
#- Choice of the options ---
x_h="";
x_n="";
x_m="";
x_b="";
Guillaume Samson's avatar
Guillaume Samson committed
x_t="";
x_c="";
x_j=1;
while getopts :hbm:n:r:j:t: V
Guillaume Samson's avatar
Guillaume Samson committed
  do
	 case $V in
		(h)  x_h=${OPTARG};
                          echo "Usage	 : "${b_n} \
					 " [-h] [-n name] [-m arch] [-j No] [-t tmpdir]";
			  echo " -h	 : help";
                          echo " -h institute : specific help for consortium members";
			  echo " -n name : tool name, [-n help] to list existing tools";
			  echo " -m arch : choose compiler, [-m help] to list exiting compilers";
			  echo " -b      : compile with debug options";
Guillaume Samson's avatar
Guillaume Samson committed
			  echo " -j No	 : number of processes used to compile (0=nocompilation)";
			  echo " -t dir  : remporary directory for compilation"
			  echo "";
			  echo "Example to compile Agrif Nesting tools";
			  echo "maketools -n NESTING" ;
			  echo "";
                          printf "%s\n" "Available tools :" `ls ${TOOLS_DIR}|grep -v COMPILE | grep -v maketools`;
			  echo "";
                          . ${COMPIL_DIR}/Flist_archfile.sh  ${x_h};
			  echo "";
			  echo "Default : previous tool and compiler";
			  exit 0;;
		(n)  x_n=${OPTARG};;
		(m)  x_m=${OPTARG};;
		(b)  x_b=1;;
Guillaume Samson's avatar
Guillaume Samson committed
		(j)  x_j=${OPTARG};;
		(t)  x_t=${OPTARG};;
		(:)  echo ${b_n}" : -"${OPTARG}" option : missing value" 1>&2;
			  exit 2;;
		(\?) echo ${b_n}" : -"${OPTARG}" option : not supported" 1>&2;
			  exit 2;;
	 esac
  done
shift $(($OPTIND-1));

#-
#- Get the clean option
[[ "${#@}" -ne 0 && "${@}" != clean ]] && echo "Invalid option "$@" " && exit
[ "${#@}" -ne 0 ] && x_c="--$@"

#-
#- Initialisation from input ---
CUR_CONF=${x_n}
Guillaume Samson's avatar
Guillaume Samson committed
NBR_PRC=${x_j}
CMP_NAM=${x_m}
NEMO_TDIR=${x_t:-$TOOLS_DIR}
Guillaume Samson's avatar
Guillaume Samson committed

#- Check if the tool or the compiler exist or list it
[ "${CUR_CONF}" == help ] && printf "%s\n"  "Available tools :" `ls ${TOOLS_DIR}|grep -v COMPILE | grep -v maketools` && exit
[ "${CMP_NAM}" ==  help ] && ${COMPIL_DIR}/Flist_archfile.sh ${MAIN_DIR} && exit 0
Guillaume Samson's avatar
Guillaume Samson committed

#- Choose a default tool if needed ---
#- REBUILD or last one used ---
${COMPIL_DIR}/Fcheck_config.sh ${TOOLS_DIR}/tools.txt ${CUR_CONF} || exit
Guillaume Samson's avatar
Guillaume Samson committed

#- Save new configuration ---
echo "${CUR_CONF} "  > ${TOOLS_DIR}/tools.txt
Guillaume Samson's avatar
Guillaume Samson committed

#- Make the building directory
${COMPIL_DIR}/Fmake_tools_bld.sh ${TOOLS_DIR} ${CUR_CONF} ${NEMO_TDIR} || exit
Guillaume Samson's avatar
Guillaume Samson committed

#- At this stage cpp keys have been updated. we can check the arch file
#- When used for the first time, choose a compiler ---
${COMPIL_DIR}/Fcheck_archfile.sh ${TOOLS_DIR}/${CUR_CONF}/BLD/arch_tools.fcm ${TOOLS_DIR}/${CUR_CONF}/BLD/cpp_tools.fcm ${MAIN_DIR}/arch/arch-${CMP_NAM}.fcm ${x_b} || exit
Guillaume Samson's avatar
Guillaume Samson committed

#- At this stage the configuration has beeen chosen
#- We coose the default light file
USEBLD=bldxag_tools.cfg
Guillaume Samson's avatar
Guillaume Samson committed

#_ END OF CONFIGURATION PHASE
Guillaume Samson's avatar
Guillaume Samson committed



#- Compile ---

if [ "${NBR_PRC}" -gt 0 ]; then

	## if AGRIF we do a first preprocessing
        grep key_agrif ${TOOLS_DIR}/${CUR_CONF}/BLD/cpp_tools.fcm && USEBLD=${USEBLD/xag/}
	if [[ ${#x_c} -eq 0 && ! ${USEBLD} =~ "xag" ]]; then
                ${COMPIL_DIR}/Fprep_agrif.sh ${MAIN_DIR} ${TOOLS_DIR}/${CUR_CONF} || exit 3

                # compile & copy conv
                sed -e "s~MAIN_DIR~${MAIN_DIR}~; s~NEMO_TDIR~${NEMO_TDIR}~; s~CUR_CONF~${CUR_CONF}~; s~COMPIL_DIR~${COMPIL_DIR}~; s~arch_nemo~arch_tools~" ${COMPIL_DIR}/conv.cfg > ${NEMO_TDIR}/${CUR_CONF}/BLD/conv.cfg
                fcm build ${NEMO_TDIR}/${CUR_CONF}/BLD/conv.cfg || exit 1
                cp -fa ${MAIN_DIR}/ext/AGRIF/agrif_oce.in ${NEMO_TDIR}/${CUR_CONF}/AGRIFLIB/bin/conv ${NEMO_TDIR}/${CUR_CONF}/NEMOFILES/.

                sed -e "s~MAIN_DIR~${MAIN_DIR}~; s~TOOLS_DIR~${TOOLS_DIR}~; s~CUR_CONF~${CUR_CONF}~; s~COMPIL_DIR~${COMPIL_DIR}~" ${COMPIL_DIR}/bld_preproagr_tools.cfg > ${NEMO_TDIR}/${CUR_CONF}/BLD/bld_preproagr_tools.cfg
		fcm build --ignore-lock -j 1 ${NEMO_TDIR}/${CUR_CONF}/BLD/bld_preproagr_tools.cfg || exit 1
		echo
Guillaume Samson's avatar
Guillaume Samson committed
		echo "---------------------------------"
		echo "CONV preprocessing successfull !!"
		echo "---------------------------------"
   sed -e "s~MAIN_DIR~${MAIN_DIR}~; s~TOOLS_DIR~${TOOLS_DIR}~; s~CUR_CONF~${CUR_CONF}~; s~COMPIL_DIR~${COMPIL_DIR}~" ${COMPIL_DIR}/${USEBLD} > ${NEMO_TDIR}/${CUR_CONF}/BLD/${USEBLD}
   fcm build ${x_c} --ignore-lock -v 1 -j ${NBR_PRC} ${NEMO_TDIR}/${CUR_CONF}/BLD/${USEBLD}

   if ls ${NEMO_TDIR}/${CUR_CONF}/BLD/bin/*.exe 2>/dev/null && [ -z "${x_c}" ]; then
      for i in ${NEMO_TDIR}/${CUR_CONF}/BLD/bin/*.exe
Guillaume Samson's avatar
Guillaume Samson committed
      do
         ln -sfv ${i} ${TOOLS_DIR}/${CUR_CONF}/.