source: modipsl/trunk/util/ins_make @ 2

Last change on this file since 2 was 2, checked in by rblod, 16 years ago

First import of modipsl utilities

  • Property svn:executable set to *
File size: 4.9 KB
Line 
1#!/bin/ksh
2# $Id: ins_make,v 2.19 2006/01/18 05:59:17 adm Exp $
3#---------------------------------------------------------------------
4#- Installation of Makefiles according to an environment
5#---------------------------------------------------------------------
6b_n=$(basename $0)
7d_n=$(dirname $0)
8#- Retrieving and validation of the options
9x_v='silencious';
10x_d='normal';
11x_p="";
12x_t="";
13x_m='??';
14while getopts :hvdp:m:t: V
15  do
16    case $V in
17      (h)  echo "Usage    : "${b_n} \
18                " [-h] [-v] [-d] [-p r] [-t h] ";
19           echo " -h      : help";
20           echo " -v      : verbose mode";
21           echo " -t h    : target host_name";
22           echo " -d      : debug mode";
23           echo " -p p    : int and real precision I4R4/I4R8/I8R8/4/8";
24           echo " -m m    : mpi context choosen for the coupling MPI1/MPI2";
25           echo "";
26           echo "Example for remote host compilation ";
27           echo "ins_make -t sxnec";
28           echo "";
29           echo "Defaults : -t local_host";
30           echo "";
31           exit 0;;
32      (v)  x_v='verbose';;
33      (d)  x_d='debug';;
34      (p)  x_p=${OPTARG};;
35      (t)  x_t=${OPTARG};;
36      (m)  x_m=${OPTARG};;
37      (:)  echo ${b_n}" : -"${OPTARG}" option : missing value" 1>&2;
38           exit 2;;
39      (\?) echo ${b_n}" : -"${OPTARG}" option : not supported" 1>&2;
40           exit 2;;
41    esac
42  done
43shift $(($OPTIND-1));
44#-
45# Treatment of the options
46#-
47# Default INTEGER and REAL precision
48case ${x_p} in
49  ( I4R4 | I4R8 | I8R8 ) ;;
50  ( 4 ) x_p='I4R4';;
51  ( 8 ) x_p='I8R8';;
52  ("")  x_p='??';;
53  (*)
54    echo 'Invalid precision ' 1>&2;
55    echo ${x_p}' (must be I4R4, I4R8, I8R8, 4 or 8)' 1>&2;
56    exit 1;;
57esac
58#-
59# Target_Host Name
60if [ '\?'${x_t} = '\?' ]; then
61  x_t=`${d_n}/w_i_h`;
62  if [ $? -ne 0 ]; then
63    echo "Bad installation : w_i_h/uname unreachable" 1>&2;
64    exit 1;
65  elif [ "$x_t" = "Unknown" ]; then
66    echo "Local_Host not supported" 1>&2;
67    exit 1;
68  fi;
69fi;
70case ${x_t} in
71 (aix | ax_mono | cray | Darwin | fjvpp | g95 | eshpux |  \
72  linux | lxiv7 | lxiv8 | osf1 | osxxlf | sgi6 | \
73  solaris | sxdkrz | sxnec | sx6nec | t3e | tx7 | unix) ;;
74 (*)
75   echo "Target_Host "${x_t}" not supported" 1>&2;
76   exit 1;;
77esac
78#-
79case ${x_m} in
80 ( mpi1 | mpi2 | MPI1 | MPI2 | ??) ;;
81 (*)
82   echo "MPI context  "${x_m}" not supported" 1>&2;
83   exit 1;;
84esac
85#-
86if [ ${x_v} = 'verbose' ]; then
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};
92fi;
93#-
94l_rep=$(find ${d_n}/.. -name AA_make -print)
95#-
96W_OS=${x_t};
97echo " ";
98echo "Installation of makefiles for $W_OS";
99echo " ";
100#-
101MKTG=${d_n}'/AA_make.gdef'
102if [ ! -f "$MKTG" ]; then
103  echo "$MKTG unreachable ..."
104  exit 3;
105fi;
106#-
107for i in $l_rep
108do
109  j=${i%/AA_make}
110  echo "Installation in ${j} ...";
111  MKTL="${j}"'/AA_make.ldef'
112  if [ ! -f "$MKTL" ]; then
113    echo "$MKTL unreachable ..."
114    exit 3;
115  fi;
116  MKTR="${j}"'/AA_make'
117  cat ${MKTL} ${MKTG} ${MKTR} > mk1.$$
118  W_XX='#-Q- '$W_OS
119  sed -e "s/^$W_XX *//" mk1.$$ | grep -v '^#-Q- ' > mk2.$$
120#-
121# Default INTEGER and REAL precision
122  if   [ ${x_p} = 'I4R4' ]; then
123    W_XX='#-P- I4R4'
124  elif [ ${x_p} = 'I4R8' ]; then
125    W_XX='#-P- I4R8'
126  elif [ ${x_p} = 'I8R8' ]; then
127    W_XX='#-P- I8R8'
128  else
129    W_XX='#-P- ??'
130  fi
131  sed -e "s/^$W_XX *//" mk2.$$ | grep -v '^#-P- ' > mk1.$$
132#-
133# Remove the module "defprec.f90"
134# if the default precision has (eventually) been modified
135  if [ '!!'${j##*/modeles} = '!!/IOIPSL/src' ]; then
136    dp_n=${d_n}'/../modeles/IOIPSL/src/defprec.f90';
137    if [ -f ${dp_n} ]; then
138      W_NEW=$(grep 'D_P =' mk1.$$ | tail -1 | sed "s/D_P = //")
139      if [ -f ${j}/Makefile ]; then
140        W_OLD=$(grep 'D_P =' ${j}/Makefile | tail -1 | sed "s/D_P = //")
141      else
142        W_OLD='!??!'
143      fi
144      if [ ${W_OLD} != ${W_NEW} ]; then
145        echo 'Remove '${dp_n};
146        rm -f ${dp_n};
147      fi
148      unset W_NEW W_OLD;
149    fi
150    unset dp_n;
151  fi
152#-
153# Debug
154  if   [ ${x_d} = 'debug' ]; then
155    W_XX='#-D- MD'
156  else
157    W_XX='#-D- MN'
158  fi
159  sed -e "s/^$W_XX *//" mk1.$$ | grep -v '^#-D- ' > mk2.$$
160#-
161# Retrieve the path of the directory
162  cd ${j} > /dev/null; mk_dir=$(pwd); cd - > /dev/null;
163  W_XX='MAKE_DIR ='
164# Update the value
165  sed -e "s!^${W_XX}.*!${W_XX} ${mk_dir}!" mk2.$$ > mk1.$$
166  unset mk_dir;
167#-
168# Choice of mpi library for the coupling
169  W_XX='LIB_MPI ='
170  W_XX_BIS='LIB_MPI_BIS ='
171#-
172case ${x_m} in
173 ( mpi1 | MPI1 )
174    lib_mpi='MPI1'
175    lib_mpi_bis='MPI1'
176    sed -e "s!^${W_XX}.*!${W_XX} ${lib_mpi}!" \
177      -e "s!^${W_XX_BIS}.*!${W_XX_BIS} ${lib_mpi_bis}!" mk1.$$ > ${j}/Makefile ;;
178 ( mpi2 | MPI2 )
179    lib_mpi='MPI2'
180    lib_mpi_bis=''
181    sed -e "s!^${W_XX}.*!${W_XX} ${lib_mpi}!" \
182      -e "s!^${W_XX_BIS}.*!${W_XX_BIS} ${lib_mpi_bis}!" mk1.$$ > ${j}/Makefile ;;
183 (??) 
184    cp mk1.$$ ${j}/Makefile ;;
185 (*) ;;
186esac
187  unset lib_mpi;
188  unset lib_mpi_bis;
189#-
190done
191#-
192rm -f mk1.$$ mk2.$$
193#-
194exit 0;
195
196
197
198
199
200
201
Note: See TracBrowser for help on using the repository browser.