1 | #!/bin/bash |
---|
2 | #set -x |
---|
3 | set -o posix |
---|
4 | #set -u |
---|
5 | #set -e |
---|
6 | #+ |
---|
7 | # |
---|
8 | # =============== |
---|
9 | # maketools |
---|
10 | # =============== |
---|
11 | # |
---|
12 | # -------------------------- |
---|
13 | # Compile NEMO |
---|
14 | # -------------------------- |
---|
15 | # |
---|
16 | # SYNOPSIS |
---|
17 | # ======== |
---|
18 | # |
---|
19 | # :: |
---|
20 | # |
---|
21 | # $ maketools |
---|
22 | # |
---|
23 | # |
---|
24 | # DESCRIPTION |
---|
25 | # =========== |
---|
26 | # |
---|
27 | # |
---|
28 | # This script aims : |
---|
29 | # |
---|
30 | # - to choose a tool to compile |
---|
31 | # - to choose compiler options |
---|
32 | # - to compile this tool |
---|
33 | # |
---|
34 | # Variables used : |
---|
35 | # |
---|
36 | # From user input |
---|
37 | # |
---|
38 | # - NEW_CONF : configuration to be created |
---|
39 | # - CMP_NAM : compiler name |
---|
40 | # - NBR_PRC : number of processes used to compile |
---|
41 | # |
---|
42 | # Locally defined : |
---|
43 | # |
---|
44 | # - MAIN_DIR : self explaining |
---|
45 | # - MODELES_DIR : " " " |
---|
46 | # - TOOLS_DIR : " " " |
---|
47 | # - NEMO_DIR : " " " |
---|
48 | # |
---|
49 | # EXAMPLES |
---|
50 | # ======== |
---|
51 | # |
---|
52 | # :: |
---|
53 | # |
---|
54 | # $ ./maketools -t ifort_osx - j3 -n NESTING |
---|
55 | # |
---|
56 | # |
---|
57 | # TODO |
---|
58 | # ==== |
---|
59 | # |
---|
60 | # option debug |
---|
61 | # |
---|
62 | # |
---|
63 | # EVOLUTIONS |
---|
64 | # ========== |
---|
65 | # |
---|
66 | # $Id$ |
---|
67 | # |
---|
68 | # |
---|
69 | # |
---|
70 | # * creation |
---|
71 | # |
---|
72 | #- |
---|
73 | |
---|
74 | #- Local variables --- |
---|
75 | b_n=$(basename ${0}) |
---|
76 | export MAIN_DIR=${PWD%/TOOLS*} |
---|
77 | export TOOLS_DIR=${MAIN_DIR}/TOOLS |
---|
78 | export COMPIL_DIR=${MAIN_DIR}/TOOLS/COMPILE |
---|
79 | export NEMO_DIR=${MAIN_DIR}/NEMO |
---|
80 | #- |
---|
81 | #- FCM and functions location --- |
---|
82 | export PATH=${MAIN_DIR}/EXTERNAL/fcm/bin:$PATH |
---|
83 | |
---|
84 | #- |
---|
85 | #- Choice of the options --- |
---|
86 | x_h=""; |
---|
87 | x_n=""; |
---|
88 | x_m=""; |
---|
89 | x_t=""; |
---|
90 | x_c=""; |
---|
91 | x_j=1; |
---|
92 | while getopts :hm:n:r:j:t: V |
---|
93 | do |
---|
94 | case $V in |
---|
95 | (h) x_h=${OPTARG}; |
---|
96 | echo "Usage : "${b_n} \ |
---|
97 | " [-h] [-n name] [-m arch] [-j No] [-t tmpdir]"; |
---|
98 | echo " -h : help"; |
---|
99 | echo " -h institute : specific help for consortium members"; |
---|
100 | echo " -n name : tool name, [-n help] to list existing tools"; |
---|
101 | echo " -m arch : choose compiler, [-m help] to list exiting compilers"; |
---|
102 | echo " -j No : number of processes used to compile (0=nocompilation)"; |
---|
103 | echo " -t dir : remporary directory for compilation" |
---|
104 | echo ""; |
---|
105 | echo "Example to compile Agrif Nesting tools"; |
---|
106 | echo "maketools -n NESTING" ; |
---|
107 | echo ""; |
---|
108 | printf "%s\n" "Available tools :" `ls ${TOOLS_DIR}|grep -v COMPILE | grep -v maketools`; |
---|
109 | echo ""; |
---|
110 | . ${COMPIL_DIR}/Flist_archfile.sh ${x_h}; |
---|
111 | echo ""; |
---|
112 | echo "Default : previous tool and compiler"; |
---|
113 | exit 0;; |
---|
114 | (n) x_n=${OPTARG};; |
---|
115 | (m) x_m=${OPTARG};; |
---|
116 | (j) x_j=${OPTARG};; |
---|
117 | (t) x_t=${OPTARG};; |
---|
118 | (:) echo ${b_n}" : -"${OPTARG}" option : missing value" 1>&2; |
---|
119 | exit 2;; |
---|
120 | (\?) echo ${b_n}" : -"${OPTARG}" option : not supported" 1>&2; |
---|
121 | exit 2;; |
---|
122 | esac |
---|
123 | done |
---|
124 | shift $(($OPTIND-1)); |
---|
125 | |
---|
126 | #- |
---|
127 | #- Get the clean option |
---|
128 | [[ "${#@}" -ne 0 && "${@}" != clean ]] && echo "Invalid option "$@" " && exit |
---|
129 | [ "${#@}" -ne 0 ] && x_c="--$@" |
---|
130 | |
---|
131 | #- |
---|
132 | #- Go to NEMOGCM/TOOLS directory --- |
---|
133 | cd ${TOOLS_DIR} |
---|
134 | |
---|
135 | #- |
---|
136 | #- Initialisation from input --- |
---|
137 | export NEW_CONF=${x_n} |
---|
138 | NBR_PRC=${x_j} |
---|
139 | CMP_NAM=${x_m} |
---|
140 | NEMO_TDIR=${x_t:-$NEMO_TDIR} |
---|
141 | export NEMO_TDIR=${NEMO_TDIR:-$TOOLS_DIR} |
---|
142 | |
---|
143 | #- Check if the tool or the compiler exist or list it |
---|
144 | [ "${NEW_CONF}" == help ] && printf "%s\n" "Available tools :" `ls ${TOOLS_DIR}|grep -v COMPILE | grep -v maketools` && exit |
---|
145 | [ "${CMP_NAM}" == help ] && . ${COMPIL_DIR}/Flist_archfile.sh all && exit |
---|
146 | |
---|
147 | #- When used for the first time, choose a compiler --- |
---|
148 | . ${COMPIL_DIR}/Fcheck_archfile.sh arch_tools.fcm nocpp ${CMP_NAM} || exit |
---|
149 | |
---|
150 | #- Choose a default tool if needed --- |
---|
151 | #- REBUILD or last one used --- |
---|
152 | . ${COMPIL_DIR}/Fcheck_config.sh tools.txt ${NEW_CONF} || exit |
---|
153 | |
---|
154 | #- Save new configuration --- |
---|
155 | echo "${NEW_CONF} " > ${COMPIL_DIR}/tools.txt |
---|
156 | |
---|
157 | #- Make the building directory |
---|
158 | . ${COMPIL_DIR}/Fmake_bld.sh ${TOOLS_DIR} ${NEW_CONF} ${NEMO_TDIR} || exit |
---|
159 | |
---|
160 | #- |
---|
161 | #_ END OF CONFIGURATION PHASE |
---|
162 | #_ |
---|
163 | |
---|
164 | #- |
---|
165 | #- Compile --- |
---|
166 | |
---|
167 | if [ "${NBR_PRC}" -gt 0 ]; then |
---|
168 | cd ${NEMO_TDIR}/${NEW_CONF} || cd - |
---|
169 | |
---|
170 | fcm build ${x_c} --ignore-lock -v 1 -j ${NBR_PRC} ${COMPIL_DIR}/bld_tools.cfg || cd - |
---|
171 | if [ -n "$(ls ${NEMO_TDIR}/${NEW_CONF}/BLD/bin/*.exe)" ]; then |
---|
172 | for i in `ls ${NEMO_TDIR}/${NEW_CONF}/BLD/bin/*.exe` |
---|
173 | do |
---|
174 | ln -sf ${i} ${TOOLS_DIR}/${NEW_CONF}/. |
---|
175 | done |
---|
176 | fi |
---|
177 | fi |
---|
178 | #- |
---|
179 | #- Come back to original directory --- |
---|
180 | cd - |
---|
181 | |
---|
182 | #- |
---|
183 | #- Unset variables |
---|
184 | ${COMPIL_DIR}/Fclean_var.sh |
---|
185 | |
---|
186 | exit 0; |
---|