New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
maketools in trunk/NEMOGCM/TOOLS – NEMO

source: trunk/NEMOGCM/TOOLS/maketools @ 2528

Last change on this file since 2528 was 2331, checked in by rblod, 14 years ago

Light improvement of maketools

  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 3.8 KB
Line 
1#!/bin/bash
2#set -x
3set -o posix
4#set -u
5#set -e
6#+
7#
8# ===============
9# maketools
10# ===============
11#
12# --------------------------
13# Compile NEMO
14# --------------------------
15#
16# SYNOPSIS
17# ========
18#
19# ::
20#
21#  $ maketools
22#
23#
24# DESCRIPTION
25# ===========
26#
27#
28# This script aims :
29#
30# - to choose a tool to compile
31# - to choose compiler options 
32# - to compile this tool
33#
34#  Variables used :
35#
36#  From user input
37#
38# - NEW_CONF    : configuration to be created
39# - CMP_NAM     : compiler name
40# - NBR_PRC     : number of processes used to compile 
41#
42#  Locally defined :
43#
44# - MAIN_DIR : self explaining
45# - MODELES_DIR :   "    "    "
46# - TOOLS_DIR   :   "    "    "
47# - NEMO_DIR    :   "    "    "
48#
49# EXAMPLES
50# ========
51#
52# ::
53#
54#  $ ./maketools -t ifort_osx - j3 -n NESTING
55#
56#
57# TODO
58# ====
59#
60# option debug
61#
62#
63# EVOLUTIONS
64# ==========
65#
66# $Id$
67#
68#
69#
70#   * creation
71#
72#-
73
74#- Local variables ---
75b_n=$(basename ${0})
76export MAIN_DIR=${PWD%/TOOLS*}
77export TOOLS_DIR=${MAIN_DIR}/TOOLS
78export COMPIL_DIR=${MAIN_DIR}/TOOLS/COMPILE
79export NEMO_DIR=${MAIN_DIR}/NEMO
80#-
81#- FCM and functions location ---
82export PATH=${MAIN_DIR}/EXTERNAL/fcm/bin:$PATH
83
84#-
85#- Choice of the options ---
86x_n="";
87x_m="";
88x_t="";
89x_c="";
90x_j=1;
91while getopts :hm:n:r:j:t: V
92  do
93    case $V in
94      (h)  echo "Usage   : "${b_n} \
95                " [-h] [-n name] [-m arch] [-j No] [-t tmpdir]";
96           echo " -h  : help";
97           echo " -n name : tool name, [-n help] to list existing tools";
98           echo " -m arch : choose compiler, [-m help] to list exiting compilers";
99           echo " -j No  : number of processes used to compile (0=nocompilation)";
100           echo " -t dir  : remporary directory for compilation"
101           echo "";
102           echo "Example to compile Agrif Nesting tools";
103           echo "maketools -n NESTING" ;
104           echo "";
105                          printf "%s\n" "Available tools :" `ls ${TOOLS_DIR}|grep -v COMPILE | grep -v maketools`;
106           echo "";
107                          . ${COMPIL_DIR}/Flist_archfile.sh  ;
108           echo "";
109           echo "Default : previous tool and compiler";
110           exit 0;;
111      (n)  x_n=${OPTARG};;
112      (m)  x_m=${OPTARG};;
113      (j)  x_j=${OPTARG};;
114      (t)  x_t=${OPTARG};;
115      (:)  echo ${b_n}" : -"${OPTARG}" option : missing value" 1>&2;
116           exit 2;;
117      (\?) echo ${b_n}" : -"${OPTARG}" option : not supported" 1>&2;
118           exit 2;;
119    esac
120  done
121shift $(($OPTIND-1));
122
123#-
124#- Get the clean option
125[[ "${#@}" -ne 0 && "${@}" != clean ]] && echo "Invalid option "$@" " && exit
126[ "${#@}" -ne 0 ] && x_c="--$@"
127
128#-
129#- Go to NEMOGCM/TOOLS directory ---
130cd ${TOOLS_DIR}
131
132#-
133#- Initialisation from input ---
134export NEW_CONF=${x_n}
135NBR_PRC=${x_j}
136CMP_NAM=${x_m}
137NEMO_TDIR=${x_t:-$NEMO_TDIR}
138export NEMO_TDIR=${NEMO_TDIR:-$TOOLS_DIR}
139
140#- Check if the tool or the compiler exist or list it
141[ "${NEW_CONF}" == help ] && printf "%s\n"  "Available tools :" `ls ${TOOLS_DIR}|grep -v COMPILE | grep -v maketools` && exit
142[ "${CMP_NAM}" ==  help ] && . ${COMPIL_DIR}/Flist_archfile.sh && exit
143
144#- When used for the first time, choose a compiler ---
145. ${COMPIL_DIR}/Fcheck_archfile.sh arch_tools.fcm ${CMP_NAM} || exit
146
147#- Choose a default tool if needed ---
148#- REBUILD or last one used ---
149. ${COMPIL_DIR}/Fcheck_config.sh tools.txt ${NEW_CONF} || exit
150
151#- Save new configuration ---
152echo "${NEW_CONF} "  > ${COMPIL_DIR}/tools.txt
153
154#- Make the building directory
155. ${COMPIL_DIR}/Fmake_bld.sh ${TOOLS_DIR} ${NEW_CONF} ${NEMO_TDIR} || exit
156
157#-
158#_ END OF CONFIGURATION PHASE
159#_
160
161#-
162#- Compile ---
163
164if [ "${NBR_PRC}" -gt 0 ]; then
165cd ${NEMO_TDIR}/${NEW_CONF} || cd -
166
167fcm build ${x_c} --ignore-lock -v 1 -j ${NBR_PRC} ${COMPIL_DIR}/bld_tools.cfg || cd -
168if [ -n "$(ls ${NEMO_TDIR}/${NEW_CONF}/BLD/bin/*.exe)" ]; then
169for i in `ls ${NEMO_TDIR}/${NEW_CONF}/BLD/bin/*.exe`
170   do
171      ln -sf ${i}  ${TOOLS_DIR}/${NEW_CONF}/.
172   done
173fi
174fi
175#-
176#- Come back to original directory ---
177cd -
178
179#-
180#- Unset variables
181${COMPIL_DIR}/Fclean_var.sh
182
183exit 0;
Note: See TracBrowser for help on using the repository browser.