source: modipsl/trunk/util/env_make @ 2296

Last change on this file since 2296 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: 1.9 KB
Line 
1#!/bin/bash
2# $Id$
3#---------------------------------------------------------------------
4#- Loading an environment and optionally running Makefile
5#---------------------------------------------------------------------
6shopt -s extglob
7#-
8function env_make_Usage
9{
10echo -e "
11${b_n} Loads an environment and runs a Makefile
12
13Usage :
14  ${b_n} [-h] [-v] [-m] [target_for_Makefile]
15
16Options :
17  -h : help
18  -v : verbose mode
19  -m : dont'runs the Makefile
20
21Defaults :
22   runs the Makefile
23
24Example for run a Makefile with target t_1 :
25  ${b_n} t_1
26"
27}
28#-
29#  dirname  and  basename
30#-
31   d_n=${0%/*}b_n=${0##*/};
32#-
33# Retrieving and validation of the options
34#-
35x_v='silencious'; x_m='run';
36while getopts :hvm V
37  do
38   case ${V} in
39    (h) env_make_Usage; exit 0;;
40    (v) x_v='verbose';;
41    (m) x_m='no_run';;
42   (\?) echo ${b_n}" : -"${OPTARG}" option : not supported" 1>&2;
43         exit 2;;
44   esac
45  done
46shift $(($OPTIND-1));
47#-
48# Retrieve the target
49#-
50[[ ${#} -gt 1 ]] && \
51  { echo 'Only one target can be specified' 1>&2; exit 3; }
52x_t="";
53[[ ${#} -eq 1 ]] && { x_t="${1}"; }
54#-
55# Test availability of the definition file
56#-
57tgt_f="${d_n}/.host_target"
58[[ ! -f "${tgt_f}" ]] && \
59 { echo -e "\\n${b_n} : file ${tgt_f} unreachable\\n"; exit 3; }
60#-
61# Extract the host name and update the Makefile name
62#-
63read tgt_n < ${tgt_f}
64[[ -z "${tgt_n}" ]] && \
65 { echo -e "\\n${b_n} : invalid host name\\n"; exit 3; }
66mkf_n='Makefile'
67#-
68# Verbose mode
69#-
70[ ${x_v} = 'verbose' ] && \
71 { echo -e "---";
72   echo -e "Host     : ${tgt_n}";
73   echo -e "Mode     : ${x_m}";
74   echo -e "Makefile : ${mkf_n}";
75   echo -e "Target   : ${x_t}";
76   echo -e "---"; }
77#-
78# Loads the environment
79#-
80case ${tgt_n} in
81 ("sx8mercure") \
82  module load SX8
83  module load netcdf_sx8
84  ;;
85 ("sx9mercure") \
86  module load SX9
87  module load netcdf_sx9
88  ;;
89 (*) \
90  ;;
91esac
92#-
93# [eventually] run the Makefile
94#-
95[[ "${x_m}" = 'run' ]] && { gmake -f ${mkf_n} ${x_t}; };
96#-
97exit 0;
Note: See TracBrowser for help on using the repository browser.