source: modipsl/trunk/util/ins_make @ 5482

Last change on this file since 5482 was 5482, checked in by aclsce, 12 months ago
  • Modified to run with IPSLCM7 configurations
  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 5.9 KB
Line 
1#!/bin/bash
2# $Id$
3#---------------------------------------------------------------------
4#- Installation of Makefiles according to an environment
5#---------------------------------------------------------------------
6shopt -s extglob
7#-
8function ins_make_Usage
9{
10typeset v0 v1 v2 v3 v4 v5 v6 v7 h_n;
11echo -e "
12ins_make install the Makefile in the directories
13
14Usage :
15  ${b_n} [-h] [-v] [-d] [-p r] [-t h] [-m m]
16
17Options :
18  -h   : help
19  -v   : verbose mode
20  -d   : debug mode
21  -p p : int and real precision I4R4/I4R8/I8R8/4/8
22  -t h : target host_name
23  -m m : mpi context choosen for the coupling MPI1/MPI2
24
25Defaults :
26   -t local_host -p I4R8
27
28Example for remote host compilation :
29  ins_make -t sx8brodie
30"
31echo -e "Supported targets :\n"
32[[ ! -f "${MKTG}" ]] && { echo -e "? (${MKTG} unreachable)\n"; exit 3; }
33while read v1 v2 v3 v4 v5 v6 v7
34  do
35    [[ -n "${v1}" && "${v1}${v3}" = '#-Q-#-'                       && \
36       -n "${v4}" && "${v4}${v5}${v6}" = 'Globaldefinitionsfor' ]] && \
37     { h_n=${v2}'           '; echo -e "${h_n:0:13} : ${v7}"; }
38  done <${MKTG}
39echo -e "
40For other targets, look in ${MKTG}.
41"
42}
43#-    dirname     and      basename
44d_n=$(dirname ${0}); b_n=$(basename ${0});
45#- File containing global definitions
46MKTG=${d_n}'/AA_make.gdef'
47
48#- Retrieving and validation of the options
49x_v='silencious'; x_d='normal'; x_p="??"; x_t="??"; x_m='??';
50while getopts :hvdp:m:t: V
51  do
52   case ${V} in
53    (h)  ins_make_Usage; exit 0;;
54    (v)  x_v='verbose';;
55    (d)  x_d='debug';;
56    (p)  x_p=${OPTARG};;
57    (t)  x_t=${OPTARG};;
58    (m)  x_m=${OPTARG};;
59    (:)  echo ${b_n}" : -"${OPTARG}" option : missing value" 1>&2;
60         exit 2;;
61    (\?) echo ${b_n}" : -"${OPTARG}" option : not supported" 1>&2;
62         exit 2;;
63   esac
64  done
65shift $(($OPTIND-1));
66#-
67# Treatment of the options
68#-
69# Default INTEGER and REAL precision
70case ${x_p} in
71 ( I4R4 | 4 )  x_p='I4R4'; w_ip='4'; w_rp='4';;
72 ( I4R8 | ?? ) x_p='I4R8'; w_ip='4'; w_rp='8';;
73 ( I8R8 | 8 )  x_p='I8R8'; w_ip='8'; w_rp='8';;
74 (*)
75   echo 'Invalid precision ' 1>&2;
76   echo ${x_p}' (must be I4R4, I4R8, I8R8, 4 or 8)' 1>&2;
77   exit 1;;
78esac
79#-
80# Target_Host Name
81[[ ${x_t} = '??' ]] && \
82 { x_t=$(${d_n}/w_i_h);
83   { [[ ${?} != 0 ]] && \
84      { echo "Bad installation : w_i_h/uname unreachable" 1>&2;
85        exit 1; }; } || \
86     [[ ${x_t} = "Unknown" ]] && \
87      { echo "Local_Host not supported" 1>&2; exit 1; }; }
88#-
89# Get editing header
90#x_h=$(${d_n}/w_i_p ${x_t});
91x_h=${x_t};
92#-
93[[ ! -f "${MKTG}" ]] && { echo "${MKTG} unreachable ..."; exit 3; }
94#-
95W_X1=$(sed -n -e "s/^#-Q-  *\(${x_h}\)[\t ].*$/\1/p" ${MKTG} | sort -u);
96[[ '\?'"${W_X1}" != '\?'"${x_h}" ]] && \
97  { echo "Target_Host  "${x_t}"  not supported" 1>&2; exit 1; }
98#-
99case ${x_m} in
100 ( mpi1 | mpi2 | MPI1 | MPI2 | ?? );;
101 (*) echo "MPI context "${x_m}" not supported" 1>&2; exit 1;;
102esac
103#-
104[[ ${x_v} = 'verbose' ]] && \
105 { echo "";
106   echo '--- Mode         : '${x_v};
107   echo '--- Compilation  : '${x_d};
108   echo '--- Precision    : '${x_p};
109   echo '--- Target       : '${x_t};
110   echo '--- MPI context  : '${x_m}; }
111#-
112echo "";
113echo "Installation of makefiles, scripts and data for ${x_t}";
114echo "";
115#-
116w_t='AA_make';
117l_rep=$(cd ${d_n};find .. -name ${w_t} -print)
118for i in ${l_rep}
119do
120  k=${i%/${w_t}}; k=${k#./}; j=${d_n}'/'${k}; j=${j#./};
121  echo "Installation in ${j}";
122  MKTL="${j}"'/AA_make.ldef';
123  [[ ! -f "${MKTL}" ]] && { echo "${MKTL} unreachable ..."; exit 3; }
124  MKTR="${j}"'/AA_make';
125  cat ${MKTL} ${MKTG} ${MKTR} > mk1.$$;
126  W_PR='#-Q-  *'; W_X1=${W_PR}${x_h};
127  sed -e "/^${W_X1}[\t ]/ s/^${W_X1} *//" -e "/^${W_PR}/d" mk1.$$ > mk2.$$;
128#-
129# Default INTEGER and REAL precision
130  W_PR='#-P- '; W_X1=${W_PR}${x_p};
131  sed -e "/^${W_X1} */ s///" -e "/^${W_PR}/d" mk2.$$ > mk1.$$;
132#-
133# Handle the precision module "defprec.f90" in "IOIPSL/src"
134  [[ '!!'${j##*/modeles} = '!!/IOIPSL/src' ]] && \
135   { [[ ${x_v} = 'verbose' ]] && W_X1='-v' || W_X1="";
136     ${d_n}/ins_m_prec ${W_X1} -i ${w_ip} -r ${w_rp}; r_c=${?};
137     unset w_ip w_rp;
138     [[ ${r_c} != 0 ]] && exit ${r_c}; }
139#-
140# Debug
141  W_PR='#-D- ';
142  [[ ${x_d} = 'debug' ]] && W_X1=${W_PR}'MD' || W_X1=${W_PR}'MN';
143  sed -e "/^${W_X1} */ s///" -e "/^${W_PR}/d" mk1.$$ > mk2.$$;
144#-
145# Retrieve the path of the Makefile directory
146# and the path from the directory to modipsl/util
147  mk_dir=$(cd ${j};/bin/pwd;);
148  ut_dir=''; for ww in ${k//\//' '}; do ut_dir=${ut_dir}'../'; done
149  ut_dir=${ut_dir%'../'}'util';
150  echo "Path from Makefile to modipsl/util : ${ut_dir}";
151# Update the values
152  W_X1='UTIL_DIR ='; W_X2='MAKE_DIR =';
153  sed -e "s!^${W_X1}.*!${W_X1} ${ut_dir}!" \
154      -e "s!^${W_X2}.*!${W_X2} ${mk_dir}!" \
155      mk2.$$ > mk1.$$
156  unset mk_dir ut_dir;
157#-
158# Choice of mpi library for the coupling
159  W_X1='LIB_MPI ='; W_X2='LIB_MPI_BIS =';
160  case ${x_m} in
161   ( mpi1 | MPI1 )
162    lib_mpi='MPI1'; lib_mpi_bis='MPI1';
163    sed -e "s!^${W_X1}.*!${W_X1} ${lib_mpi}!" \
164        -e "s!^${W_X2}.*!${W_X2} ${lib_mpi_bis}!" \
165      mk1.$$ > ${j}/Makefile;;
166   ( mpi2 | MPI2 )
167    lib_mpi='MPI2'; lib_mpi_bis='';
168    sed -e "s!^${W_X1}.*!${W_X1} ${lib_mpi}!" \
169        -e "s!^${W_X2}.*!${W_X2} ${lib_mpi_bis}!" \
170      mk1.$$ > ${j}/Makefile;;
171   (??) 
172    cp mk1.$$ ${j}/Makefile;;
173   (*) ;;
174  esac
175  unset lib_mpi lib_mpi_bis;
176#-
177done
178#-
179#- Specific to OASIS3-MCT
180if [ -d ${d_n}/../oasis3-mct ] ;
181then
182    l_dir=$(find ${d_n}/../config  -maxdepth 1 \( -name "IPSLCM6*" -o -name "IPSLCM5A2*"  -o -name "IPSLESM6*" -name "IPSLCM7*" \) -print)
183    for i in ${l_dir}
184    do
185        mk_dir=$(cd ${d_n}/../oasis3-mct;/bin/pwd;);
186        l_make=$(find ${i}/SOURCES/OASIS3-MCT -maxdepth 1 -name "make*" -print)
187        W_X1="COUPLE          ="
188        for j in ${l_make}
189        do     
190            cp ${j} ${i}/SOURCES/OASIS3-MCT/mk3.$$
191            sed -e "s!^${W_X1}.*!${W_X1} ${mk_dir}!" ${i}/SOURCES/OASIS3-MCT/mk3.$$ > ${j}
192            rm -f ${i}/SOURCES/OASIS3-MCT/mk3.$$
193        done
194    done
195
196fi
197# Creating environment file
198echo ${x_t} > ${d_n}/.host_target
199#-
200echo "";
201unset W_X1 W_X2 w_t; rm -f mk1.$$ mk2.$$;
202#-
203exit 0;
Note: See TracBrowser for help on using the repository browser.