1 | #!/bin/bash |
---|
2 | # $Id$ |
---|
3 | #--------------------------------------------------------------------- |
---|
4 | #- Installation of Makefiles according to an environment |
---|
5 | #--------------------------------------------------------------------- |
---|
6 | shopt -s extglob |
---|
7 | #- |
---|
8 | function ins_make_Usage |
---|
9 | { |
---|
10 | typeset v0 v1 v2 v3 v4 v5 v6 v7 h_n; |
---|
11 | echo -e " |
---|
12 | ins_make install the Makefile in the directories |
---|
13 | |
---|
14 | Usage : |
---|
15 | ${b_n} [-h] [-v] [-d] [-p r] [-t h] [-m m] |
---|
16 | |
---|
17 | Options : |
---|
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 | |
---|
25 | Defaults : |
---|
26 | -t local_host -p I4R8 |
---|
27 | |
---|
28 | Example for remote host compilation : |
---|
29 | ins_make -t sx8brodie |
---|
30 | " |
---|
31 | echo -e "Supported targets :\n" |
---|
32 | [[ ! -f "${MKTG}" ]] && { echo -e "? (${MKTG} unreachable)\n"; exit 3; } |
---|
33 | while 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} |
---|
39 | echo -e " |
---|
40 | For other targets, look in ${MKTG}. |
---|
41 | " |
---|
42 | } |
---|
43 | #- dirname and basename |
---|
44 | d_n=$(dirname ${0}); b_n=$(basename ${0}); |
---|
45 | #- File containing global definitions |
---|
46 | MKTG=${d_n}'/AA_make.gdef' |
---|
47 | |
---|
48 | #- Retrieving and validation of the options |
---|
49 | x_v='silencious'; x_d='normal'; x_p="??"; x_t="??"; x_m='??'; |
---|
50 | while 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 |
---|
65 | shift $(($OPTIND-1)); |
---|
66 | #- |
---|
67 | # Treatment of the options |
---|
68 | #- |
---|
69 | # Default INTEGER and REAL precision |
---|
70 | case ${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;; |
---|
78 | esac |
---|
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}); |
---|
91 | x_h=${x_t}; |
---|
92 | #- |
---|
93 | [[ ! -f "${MKTG}" ]] && { echo "${MKTG} unreachable ..."; exit 3; } |
---|
94 | #- |
---|
95 | W_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 | #- |
---|
99 | case ${x_m} in |
---|
100 | ( mpi1 | mpi2 | MPI1 | MPI2 | ?? );; |
---|
101 | (*) echo "MPI context "${x_m}" not supported" 1>&2; exit 1;; |
---|
102 | esac |
---|
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 | #- |
---|
112 | echo ""; |
---|
113 | echo "Installation of makefiles, scripts and data for ${x_t}"; |
---|
114 | echo ""; |
---|
115 | #- |
---|
116 | w_t='AA_make'; |
---|
117 | l_rep=$(cd ${d_n};find .. -name ${w_t} -print) |
---|
118 | for i in ${l_rep} |
---|
119 | do |
---|
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 | #- |
---|
177 | done |
---|
178 | #- |
---|
179 | #- Specific to OASIS3-MCT |
---|
180 | if [ -d ${d_n}/../oasis3-mct ] ; |
---|
181 | then |
---|
182 | mk_dir=$(cd ${d_n}/../oasis3-mct;/bin/pwd;); |
---|
183 | l_make=$(find ${d_n}/../config/IPSLCM6/SOURCES/OASIS3-MCT -maxdepth 1 -name "make*" -print) |
---|
184 | W_X1="COUPLE =" |
---|
185 | for j in ${l_make} |
---|
186 | do |
---|
187 | cp ${j} ${d_n}/../config/IPSLCM6/SOURCES/OASIS3-MCT/mk3.$$ |
---|
188 | sed -e "s!^${W_X1}.*!${W_X1} ${mk_dir}!" ${d_n}/../config/IPSLCM6/SOURCES/OASIS3-MCT/mk3.$$ > ${j} |
---|
189 | rm -f ${d_n}/../config/IPSLCM6/SOURCES/OASIS3-MCT/mk3.$$ |
---|
190 | done |
---|
191 | fi |
---|
192 | # Creating environment file |
---|
193 | echo ${x_t} > ${d_n}/.host_target |
---|
194 | #- |
---|
195 | echo ""; |
---|
196 | unset W_X1 W_X2 w_t; rm -f mk1.$$ mk2.$$; |
---|
197 | #- |
---|
198 | exit 0; |
---|