[728] | 1 | #!/bin/bash |
---|
| 2 | # $Id$ |
---|
| 3 | #--------------------------------------------------------------------- |
---|
| 4 | #- Loading an environment and optionally running Makefile |
---|
| 5 | #--------------------------------------------------------------------- |
---|
| 6 | shopt -s extglob |
---|
| 7 | #- |
---|
| 8 | function env_make_Usage |
---|
| 9 | { |
---|
| 10 | echo -e " |
---|
| 11 | ${b_n} Loads an environment and runs a Makefile |
---|
| 12 | |
---|
| 13 | Usage : |
---|
| 14 | ${b_n} [-h] [-v] [-m] [target_for_Makefile] |
---|
| 15 | |
---|
| 16 | Options : |
---|
| 17 | -h : help |
---|
| 18 | -v : verbose mode |
---|
| 19 | -m : dont'runs the Makefile |
---|
| 20 | |
---|
| 21 | Defaults : |
---|
| 22 | runs the Makefile |
---|
| 23 | |
---|
| 24 | Example 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 | #- |
---|
| 35 | x_v='silencious'; x_m='run'; |
---|
| 36 | while 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 |
---|
| 46 | shift $(($OPTIND-1)); |
---|
| 47 | #- |
---|
| 48 | # Retrieve the target |
---|
| 49 | #- |
---|
| 50 | [[ ${#} -gt 1 ]] && \ |
---|
| 51 | { echo 'Only one target can be specified' 1>&2; exit 3; } |
---|
| 52 | x_t=""; |
---|
| 53 | [[ ${#} -eq 1 ]] && { x_t="${1}"; } |
---|
| 54 | #- |
---|
| 55 | # Test availability of the definition file |
---|
| 56 | #- |
---|
| 57 | tgt_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 | #- |
---|
| 63 | read tgt_n < ${tgt_f} |
---|
| 64 | [[ -z "${tgt_n}" ]] && \ |
---|
| 65 | { echo -e "\\n${b_n} : invalid host name\\n"; exit 3; } |
---|
| 66 | mkf_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 | #- |
---|
| 80 | case ${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 | ;; |
---|
| 91 | esac |
---|
| 92 | #- |
---|
| 93 | # [eventually] run the Makefile |
---|
| 94 | #- |
---|
| 95 | [[ "${x_m}" = 'run' ]] && { gmake -f ${mkf_n} ${x_t}; }; |
---|
| 96 | #- |
---|
| 97 | exit 0; |
---|