Newer
Older
#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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# - 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
#-
#- Choice of the options ---
x_h="";
x_n="";
x_m="";
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 " -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};;
(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 ---
#- 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
#- Choose a default tool if needed ---
#- REBUILD or last one used ---
${COMPIL_DIR}/Fcheck_config.sh ${TOOLS_DIR}/tools.txt ${CUR_CONF} || exit
echo "${CUR_CONF} " > ${TOOLS_DIR}/tools.txt
${COMPIL_DIR}/Fmake_tools_bld.sh ${TOOLS_DIR} ${CUR_CONF} ${NEMO_TDIR} || exit
#- 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
#- At this stage the configuration has beeen chosen
#- We coose the default light file
#- 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
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