source: modipsl/trunk/util/ins_make @ 108

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

JB: pwd -> bin/pwd

  • 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-  *\([^ ]*\).*$/\1/p" ${MKTG} | \
76       sort -u | sed -e "/${x_t}/!d");
77[[ '\?'"${W_XX}" != '\?'${x_t} ]] && \
78  { echo "Target_Host  "${x_t}"  not supported" 1>&2; exit 1; }
79#-
80case ${x_m} in
81 ( mpi1 | mpi2 | MPI1 | MPI2 | ?? );;
82 (*) echo "MPI context "${x_m}" not supported" 1>&2; exit 1;;
83esac
84#-
85[[ ${x_v} = 'verbose' ]] && \
86 { echo "";
87   echo '--- Mode         : '${x_v};
88   echo '--- Compilation  : '${x_d};
89   echo '--- Precision    : '${x_p};
90   echo '--- Target       : '${x_t};
91   echo '--- MPI context  : '${x_m}; }
92#-
93echo ""; echo "Installation of makefiles for ${x_t}"; echo "";
94#-
95l_rep=$(find ${d_n}/.. -name AA_make -print)
96for i in ${l_rep}
97do
98  j=${i%/AA_make};
99  echo "Installation in ${j}";
100  MKTL="${j}"'/AA_make.ldef';
101  [[ ! -f "${MKTL}" ]] && { echo "${MKTL} unreachable ..."; exit 3; }
102  MKTR="${j}"'/AA_make';
103  cat ${MKTL} ${MKTG} ${MKTR} > mk1.$$;
104  W_PR='#-Q- '; W_XX=${W_PR}${x_t};
105  sed -e "/^${W_XX} */ s///" -e "/^${W_PR}/d" mk1.$$ > mk2.$$;
106#-
107# Default INTEGER and REAL precision
108  W_PR='#-P- '; W_XX=${W_PR}${x_p};
109  sed -e "/^${W_XX} */ s///" -e "/^${W_PR}/d" mk2.$$ > mk1.$$;
110#-
111# Handle the precision module "defprec.f90" in "IOIPSL/src"
112  [[ '!!'${j##*/modeles} = '!!/IOIPSL/src' ]] && \
113   { [[ ${x_v} = 'verbose' ]] && W_XX='-v' || W_XX="";
114     ${d_n}/ins_m_prec ${W_XX} -i ${w_ip} -r ${w_rp}; r_c=${?};
115     unset w_ip w_rp;
116     [[ ${r_c} != 0 ]] && exit ${r_c}; }
117#-
118# Debug
119  W_PR='#-D- ';
120  [[ ${x_d} = 'debug' ]] && W_XX=${W_PR}'MD' || W_XX=${W_PR}'MN';
121  sed -e "/^${W_XX} */ s///" -e "/^${W_PR}/d" mk1.$$ > mk2.$$;
122#-
123# Retrieve the path of the directory
124  mk_dir=$(cd ${j};/bin/pwd;)
125  W_XX='MAKE_DIR ='
126# Update the value
127  sed -e "s!^${W_XX}.*!${W_XX} ${mk_dir}!" mk2.$$ > mk1.$$
128  unset mk_dir;
129#-
130# Choice of mpi library for the coupling
131  W_XX='LIB_MPI ='; W_XX_BIS='LIB_MPI_BIS =';
132  case ${x_m} in
133   ( mpi1 | MPI1 )
134    lib_mpi='MPI1'; lib_mpi_bis='MPI1';
135    sed -e "s!^${W_XX}.*!${W_XX} ${lib_mpi}!" \
136        -e "s!^${W_XX_BIS}.*!${W_XX_BIS} ${lib_mpi_bis}!" \
137      mk1.$$ > ${j}/Makefile;;
138   ( mpi2 | MPI2 )
139    lib_mpi='MPI2'; lib_mpi_bis='';
140    sed -e "s!^${W_XX}.*!${W_XX} ${lib_mpi}!" \
141        -e "s!^${W_XX_BIS}.*!${W_XX_BIS} ${lib_mpi_bis}!" \
142      mk1.$$ > ${j}/Makefile;;
143   (??) 
144    cp mk1.$$ ${j}/Makefile;;
145   (*) ;;
146  esac
147  unset lib_mpi lib_mpi_bis;
148done
149#-
150echo "";
151unset W_XX W_XX_BIS; rm -f mk1.$$ mk2.$$;
152#-
153exit 0;
Note: See TracBrowser for help on using the repository browser.