source: modipsl/trunk/util/ins_make @ 767

Last change on this file since 767 was 728, checked in by bellier, 15 years ago

New version with environmental management

  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 5.3 KB
RevLine 
[728]1#!/bin/bash
[12]2# $Id$
[2]3#---------------------------------------------------------------------
4#- Installation of Makefiles according to an environment
5#---------------------------------------------------------------------
[728]6shopt -s extglob
7#-
[12]8function ins_make_Usage
9{
[728]10typeset v0 v1 v2 v3 v4 v5 v6 v7 h_n;
11echo -e "
[12]12ins_make install the Makefile in the directories
13
14Usage :
15  ${b_n} [-h] [-v] [-d] [-p r] [-t h] [-m m]
16
17Options :
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
25Defaults :
26   -t local_host -p I4R8
27
28Example for remote host compilation :
29  ins_make -t sx8brodie
30"
[728]31echo -e "Supported targets :\n"
32[[ ! -f "${MKTG}" ]] && { echo -e "? (${MKTG} unreachable)\n"; exit 3; }
[294]33while read v1 v2 v3 v4 v5 v6 v7
34  do
35    [[ -n "${v1}" && "${v1}${v3}" = '#-Q-#-'                       && \
36       -n "${v4}" && "${v4}${v5}${v6}" = 'Globaldefinitionsfor' ]] && \
[728]37     { h_n=${v2}'           '; echo -e "${h_n:0:13} : ${v7}"; }
[294]38  done <${MKTG}
[728]39echo -e "
40For other targets, look in ${MKTG}.
[294]41"
[12]42}
[293]43#-    dirname     and      basename
44d_n=$(dirname ${0}); b_n=$(basename ${0});
[294]45#- File containing global definitions
46MKTG=${d_n}'/AA_make.gdef'
[728]47
[2]48#- Retrieving and validation of the options
[12]49x_v='silencious'; x_d='normal'; x_p="??"; x_t="??"; x_m='??';
[2]50while getopts :hvdp:m:t: V
51  do
[12]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
[2]64  done
65shift $(($OPTIND-1));
66#-
67# Treatment of the options
68#-
69# Default INTEGER and REAL precision
70case ${x_p} in
[12]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';;
[2]74 (*)
[12]75   echo 'Invalid precision ' 1>&2;
76   echo ${x_p}' (must be I4R4, I4R8, I8R8, 4 or 8)' 1>&2;
[2]77   exit 1;;
78esac
79#-
[12]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#-
[728]89# Get editing header
90x_h=$(${d_n}/w_i_p ${x_t});
91#-
[12]92[[ ! -f "${MKTG}" ]] && { echo "${MKTG} unreachable ..."; exit 3; }
93#-
[728]94W_X1=$(sed -n -e "s/^#-Q-  *\(${x_h}\)[\t ].*$/\1/p" ${MKTG} | sort -u);
95[[ '\?'"${W_X1}" != '\?'"${x_h}" ]] && \
[12]96  { echo "Target_Host  "${x_t}"  not supported" 1>&2; exit 1; }
97#-
[2]98case ${x_m} in
[12]99 ( mpi1 | mpi2 | MPI1 | MPI2 | ?? );;
100 (*) echo "MPI context "${x_m}" not supported" 1>&2; exit 1;;
[2]101esac
102#-
[12]103[[ ${x_v} = 'verbose' ]] && \
104 { echo "";
105   echo '--- Mode         : '${x_v};
106   echo '--- Compilation  : '${x_d};
107   echo '--- Precision    : '${x_p};
108   echo '--- Target       : '${x_t};
109   echo '--- MPI context  : '${x_m}; }
[2]110#-
[728]111echo "";
112echo "Installation of makefiles, scripts and data for ${x_t}";
113echo "";
[12]114#-
[728]115w_t='AA_make';
116l_rep=$(cd ${d_n};find .. -name ${w_t} -print)
[12]117for i in ${l_rep}
[2]118do
[728]119  k=${i%/${w_t}}; k=${k#./}; j=${d_n}'/'${k}; j=${j#./};
[12]120  echo "Installation in ${j}";
121  MKTL="${j}"'/AA_make.ldef';
122  [[ ! -f "${MKTL}" ]] && { echo "${MKTL} unreachable ..."; exit 3; }
123  MKTR="${j}"'/AA_make';
124  cat ${MKTL} ${MKTG} ${MKTR} > mk1.$$;
[728]125  W_PR='#-Q-  *'; W_X1=${W_PR}${x_h};
126  sed -e "/^${W_X1}[\t ]/ s/^${W_X1} *//" -e "/^${W_PR}/d" mk1.$$ > mk2.$$;
[2]127#-
128# Default INTEGER and REAL precision
[728]129  W_PR='#-P- '; W_X1=${W_PR}${x_p};
130  sed -e "/^${W_X1} */ s///" -e "/^${W_PR}/d" mk2.$$ > mk1.$$;
[2]131#-
[12]132# Handle the precision module "defprec.f90" in "IOIPSL/src"
133  [[ '!!'${j##*/modeles} = '!!/IOIPSL/src' ]] && \
[728]134   { [[ ${x_v} = 'verbose' ]] && W_X1='-v' || W_X1="";
135     ${d_n}/ins_m_prec ${W_X1} -i ${w_ip} -r ${w_rp}; r_c=${?};
[12]136     unset w_ip w_rp;
137     [[ ${r_c} != 0 ]] && exit ${r_c}; }
[2]138#-
139# Debug
[12]140  W_PR='#-D- ';
[728]141  [[ ${x_d} = 'debug' ]] && W_X1=${W_PR}'MD' || W_X1=${W_PR}'MN';
142  sed -e "/^${W_X1} */ s///" -e "/^${W_PR}/d" mk1.$$ > mk2.$$;
[2]143#-
[728]144# Retrieve the path of the Makefile directory
145# and the path from the directory to modipsl/util
146  mk_dir=$(cd ${j};/bin/pwd;);
147  ut_dir=''; for ww in ${k//\//' '}; do ut_dir=${ut_dir}'../'; done
148  ut_dir=${ut_dir%'../'}'util';
149  echo "Path from Makefile to modipsl/util : ${ut_dir}";
150# Update the values
151  W_X1='UTIL_DIR ='; W_X2='MAKE_DIR =';
152  sed -e "s!^${W_X1}.*!${W_X1} ${ut_dir}!" \
153      -e "s!^${W_X2}.*!${W_X2} ${mk_dir}!" \
154      mk2.$$ > mk1.$$
155  unset mk_dir ut_dir;
[2]156#-
157# Choice of mpi library for the coupling
[728]158  W_X1='LIB_MPI ='; W_X2='LIB_MPI_BIS =';
[12]159  case ${x_m} in
160   ( mpi1 | MPI1 )
161    lib_mpi='MPI1'; lib_mpi_bis='MPI1';
[728]162    sed -e "s!^${W_X1}.*!${W_X1} ${lib_mpi}!" \
163        -e "s!^${W_X2}.*!${W_X2} ${lib_mpi_bis}!" \
[12]164      mk1.$$ > ${j}/Makefile;;
165   ( mpi2 | MPI2 )
166    lib_mpi='MPI2'; lib_mpi_bis='';
[728]167    sed -e "s!^${W_X1}.*!${W_X1} ${lib_mpi}!" \
168        -e "s!^${W_X2}.*!${W_X2} ${lib_mpi_bis}!" \
[12]169      mk1.$$ > ${j}/Makefile;;
170   (??) 
171    cp mk1.$$ ${j}/Makefile;;
172   (*) ;;
173  esac
174  unset lib_mpi lib_mpi_bis;
[728]175#-
[2]176done
177#-
[728]178# Creating environment file
179echo ${x_t} > ${d_n}/.host_target
180#-
[12]181echo "";
[728]182unset W_X1 W_X2 w_t; rm -f mk1.$$ mk2.$$;
[2]183#-
184exit 0;
Note: See TracBrowser for help on using the repository browser.