source: modipsl/tags/v2_1_2/util/ins_make @ 3093

Last change on this file since 3093 was 294, checked in by bellier, 17 years ago

JB:

  • updated ins_make to avoid conflicts with target names
  • enhanced the help of ins_make
  • updated AA_make.gdef
  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 4.8 KB
Line 
1#!/bin/ksh
2# $Id$
3#---------------------------------------------------------------------
4#- Installation of Makefiles according to an environment
5#---------------------------------------------------------------------
6function ins_make_Usage
7{
8typeset -L13 h_n; typeset v0 v1 v2 v3 v4 v5 v6 v7;
9print - "
10ins_make install the Makefile in the directories
11
12Usage :
13  ${b_n} [-h] [-v] [-d] [-p r] [-t h] [-m m]
14
15Options :
16  -h   : help
17  -v   : verbose mode
18  -d   : debug mode
19  -p p : int and real precision I4R4/I4R8/I8R8/4/8
20  -t h : target host_name
21  -m m : mpi context choosen for the coupling MPI1/MPI2
22
23Defaults :
24   -t local_host -p I4R8
25
26Example for remote host compilation :
27  ins_make -t sx8brodie
28"
29print - "Supported targets :\n"
30[[ ! -f "${MKTG}" ]] && { print - "? (${MKTG} unreachable)\n"; exit 3; }
31while read v1 v2 v3 v4 v5 v6 v7
32  do
33    [[ -n "${v1}" && "${v1}${v3}" = '#-Q-#-'                       && \
34       -n "${v4}" && "${v4}${v5}${v6}" = 'Globaldefinitionsfor' ]] && \
35     { h_n=${v2}; print - "${h_n} : ${v7}"; }
36  done <${MKTG}
37print - "
38Fot other targets, look in ${MKTG}.
39"
40}
41#-    dirname     and      basename
42d_n=$(dirname ${0}); b_n=$(basename ${0});
43#- File containing global definitions
44MKTG=${d_n}'/AA_make.gdef'
45#- Retrieving and validation of the options
46x_v='silencious'; x_d='normal'; x_p="??"; x_t="??"; x_m='??';
47while getopts :hvdp:m:t: V
48  do
49   case ${V} in
50    (h)  ins_make_Usage; exit 0;;
51    (v)  x_v='verbose';;
52    (d)  x_d='debug';;
53    (p)  x_p=${OPTARG};;
54    (t)  x_t=${OPTARG};;
55    (m)  x_m=${OPTARG};;
56    (:)  echo ${b_n}" : -"${OPTARG}" option : missing value" 1>&2;
57         exit 2;;
58    (\?) echo ${b_n}" : -"${OPTARG}" option : not supported" 1>&2;
59         exit 2;;
60   esac
61  done
62shift $(($OPTIND-1));
63#-
64# Treatment of the options
65#-
66# Default INTEGER and REAL precision
67case ${x_p} in
68 ( I4R4 | 4 )  x_p='I4R4'; w_ip='4'; w_rp='4';;
69 ( I4R8 | ?? ) x_p='I4R8'; w_ip='4'; w_rp='8';;
70 ( I8R8 | 8 )  x_p='I8R8'; w_ip='8'; w_rp='8';;
71 (*)
72   echo 'Invalid precision ' 1>&2;
73   echo ${x_p}' (must be I4R4, I4R8, I8R8, 4 or 8)' 1>&2;
74   exit 1;;
75esac
76#-
77# Target_Host Name
78[[ ${x_t} = '??' ]] && \
79 { x_t=$(${d_n}/w_i_h);
80   { [[ ${?} != 0 ]] && \
81      { echo "Bad installation : w_i_h/uname unreachable" 1>&2;
82        exit 1; }; } || \
83     [[ ${x_t} = "Unknown" ]] && \
84      { echo "Local_Host not supported" 1>&2; exit 1; }; }
85#-
86[[ ! -f "${MKTG}" ]] && { echo "${MKTG} unreachable ..."; exit 3; }
87#-
88W_XX=$(sed -n -e "s/^#-Q-  *\(${x_t}\)[\t ].*$/\1/p" ${MKTG} | sort -u);
89[[ '\?'"${W_XX}" != '\?'"${x_t}" ]] && \
90  { echo "Target_Host  "${x_t}"  not supported" 1>&2; exit 1; }
91#-
92case ${x_m} in
93 ( mpi1 | mpi2 | MPI1 | MPI2 | ?? );;
94 (*) echo "MPI context "${x_m}" not supported" 1>&2; exit 1;;
95esac
96#-
97[[ ${x_v} = 'verbose' ]] && \
98 { echo "";
99   echo '--- Mode         : '${x_v};
100   echo '--- Compilation  : '${x_d};
101   echo '--- Precision    : '${x_p};
102   echo '--- Target       : '${x_t};
103   echo '--- MPI context  : '${x_m}; }
104#-
105echo ""; echo "Installation of makefiles for ${x_t}"; echo "";
106#-
107l_rep=$(find ${d_n}/.. -name AA_make -print)
108for i in ${l_rep}
109do
110  j=${i%/AA_make};
111  echo "Installation in ${j}";
112  MKTL="${j}"'/AA_make.ldef';
113  [[ ! -f "${MKTL}" ]] && { echo "${MKTL} unreachable ..."; exit 3; }
114  MKTR="${j}"'/AA_make';
115  cat ${MKTL} ${MKTG} ${MKTR} > mk1.$$;
116  W_PR='#-Q-  *'; W_XX=${W_PR}${x_t};
117  sed -e "/^${W_XX}[\t ]/ s/^${W_XX} *//" -e "/^${W_PR}/d" mk1.$$ > mk2.$$;
118#-
119# Default INTEGER and REAL precision
120  W_PR='#-P- '; W_XX=${W_PR}${x_p};
121  sed -e "/^${W_XX} */ s///" -e "/^${W_PR}/d" mk2.$$ > mk1.$$;
122#-
123# Handle the precision module "defprec.f90" in "IOIPSL/src"
124  [[ '!!'${j##*/modeles} = '!!/IOIPSL/src' ]] && \
125   { [[ ${x_v} = 'verbose' ]] && W_XX='-v' || W_XX="";
126     ${d_n}/ins_m_prec ${W_XX} -i ${w_ip} -r ${w_rp}; r_c=${?};
127     unset w_ip w_rp;
128     [[ ${r_c} != 0 ]] && exit ${r_c}; }
129#-
130# Debug
131  W_PR='#-D- ';
132  [[ ${x_d} = 'debug' ]] && W_XX=${W_PR}'MD' || W_XX=${W_PR}'MN';
133  sed -e "/^${W_XX} */ s///" -e "/^${W_PR}/d" mk1.$$ > mk2.$$;
134#-
135# Retrieve the path of the directory
136  mk_dir=$(cd ${j};/bin/pwd;)
137  W_XX='MAKE_DIR ='
138# Update the value
139  sed -e "s!^${W_XX}.*!${W_XX} ${mk_dir}!" mk2.$$ > mk1.$$
140  unset mk_dir;
141#-
142# Choice of mpi library for the coupling
143  W_XX='LIB_MPI ='; W_XX_BIS='LIB_MPI_BIS =';
144  case ${x_m} in
145   ( mpi1 | MPI1 )
146    lib_mpi='MPI1'; lib_mpi_bis='MPI1';
147    sed -e "s!^${W_XX}.*!${W_XX} ${lib_mpi}!" \
148        -e "s!^${W_XX_BIS}.*!${W_XX_BIS} ${lib_mpi_bis}!" \
149      mk1.$$ > ${j}/Makefile;;
150   ( mpi2 | MPI2 )
151    lib_mpi='MPI2'; lib_mpi_bis='';
152    sed -e "s!^${W_XX}.*!${W_XX} ${lib_mpi}!" \
153        -e "s!^${W_XX_BIS}.*!${W_XX_BIS} ${lib_mpi_bis}!" \
154      mk1.$$ > ${j}/Makefile;;
155   (??) 
156    cp mk1.$$ ${j}/Makefile;;
157   (*) ;;
158  esac
159  unset lib_mpi lib_mpi_bis;
160done
161#-
162echo "";
163unset W_XX W_XX_BIS; rm -f mk1.$$ mk2.$$;
164#-
165exit 0;
Note: See TracBrowser for help on using the repository browser.