source: modipsl/trunk/util/ins_make @ 276

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

JB: return to previous validated version

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