[1972] | 1 | #!/bin/bash |
---|
| 2 | #set -x |
---|
| 3 | set -o posix |
---|
| 4 | #set -u |
---|
| 5 | #set -e |
---|
| 6 | #+ |
---|
| 7 | # |
---|
| 8 | # ================== |
---|
| 9 | # Fcheck_archfile.sh |
---|
| 10 | # ================== |
---|
| 11 | # |
---|
| 12 | # -------------------------- |
---|
| 13 | # Check the compilation file |
---|
| 14 | # -------------------------- |
---|
| 15 | # |
---|
| 16 | # SYNOPSIS |
---|
| 17 | # ======== |
---|
| 18 | # |
---|
| 19 | # :: |
---|
| 20 | # |
---|
| 21 | # $ Fcheck_archfile.sh |
---|
| 22 | # |
---|
| 23 | # |
---|
| 24 | # DESCRIPTION |
---|
| 25 | # =========== |
---|
| 26 | # |
---|
| 27 | # |
---|
| 28 | # Check the choice of the compiler. |
---|
| 29 | # Three cases : |
---|
[2520] | 30 | # |
---|
[1972] | 31 | # - There was a previous choice |
---|
[2520] | 32 | # - A new one has be specified, we use this one |
---|
| 33 | # - No information, exit |
---|
[1972] | 34 | # |
---|
[2520] | 35 | # We use TOOLS/COMPILE/arch.fcm to see if something was chosen. |
---|
| 36 | # |
---|
[1972] | 37 | # EXAMPLES |
---|
| 38 | # ======== |
---|
| 39 | # |
---|
| 40 | # :: |
---|
| 41 | # |
---|
[4162] | 42 | # $ ./Fcheck_archfile.sh ARCHFILE CPPFILE COMPILER |
---|
[1972] | 43 | # |
---|
| 44 | # |
---|
| 45 | # TODO |
---|
| 46 | # ==== |
---|
| 47 | # |
---|
| 48 | # option debug |
---|
| 49 | # |
---|
| 50 | # |
---|
| 51 | # EVOLUTIONS |
---|
| 52 | # ========== |
---|
| 53 | # |
---|
| 54 | # $Id$ |
---|
| 55 | # |
---|
| 56 | # |
---|
| 57 | # |
---|
| 58 | # * creation |
---|
| 59 | # |
---|
| 60 | #- |
---|
[4148] | 61 | cpeval () |
---|
| 62 | { |
---|
| 63 | cat > $2 << EOF |
---|
[1972] | 64 | |
---|
[4148] | 65 | #========================================================== |
---|
| 66 | # Automatically generated by Fcheck_archfile.sh from |
---|
| 67 | # $1 |
---|
| 68 | #========================================================== |
---|
| 69 | |
---|
| 70 | EOF |
---|
| 71 | while read line |
---|
| 72 | do |
---|
| 73 | eval "echo \"$line\" >> $2" |
---|
| 74 | done < $1 |
---|
| 75 | } |
---|
| 76 | # cleaning related to the old version |
---|
| 77 | rm -f $( find ${COMPIL_DIR} -type l -name $1 -print ) |
---|
| 78 | # |
---|
| 79 | if [ ${#3} -eq 0 ]; then # arch not specified |
---|
| 80 | if [ ! -f ${COMPIL_DIR}/arch.history ]; then |
---|
| 81 | echo "Warning !!!" |
---|
| 82 | echo "NO compiler chosen" |
---|
| 83 | echo "Try makenemo -h for help" |
---|
| 84 | echo "EXITING..." |
---|
| 85 | exit 1 |
---|
| 86 | else # use the arch file defined in arch.history |
---|
| 87 | myarch=$( cat ${COMPIL_DIR}/arch.history ) |
---|
| 88 | if [ ! -f $myarch ]; then |
---|
| 89 | echo "Warning !!!" |
---|
| 90 | echo "previously used arch file no more found:" |
---|
| 91 | echo $myarch |
---|
| 92 | echo "EXITING..." |
---|
| 93 | exit 1 |
---|
| 94 | else |
---|
| 95 | if [ -f ${COMPIL_DIR}/$1 ]; then |
---|
[4162] | 96 | if [ "$2" != "nocpp" ] |
---|
| 97 | then |
---|
| 98 | # has the cpp keys file been changed since we copied the arch file in ${COMPIL_DIR}? |
---|
| 99 | mycpp=$( ls -l ${COMPIL_DIR}/$2 | sed -e "s/.* -> //" ) |
---|
| 100 | if [ "$mycpp" != "$( cat ${COMPIL_DIR}/cpp.history )" ]; then |
---|
| 101 | echo $mycpp > ${COMPIL_DIR}/cpp.history |
---|
| 102 | cpeval ${myarch} ${COMPIL_DIR}/$1 |
---|
| 103 | fi |
---|
| 104 | # has the cpp keys file been updated since we copied the arch file in ${COMPIL_DIR}? |
---|
| 105 | mycpp=$( find -L ${COMPIL_DIR} -cnewer ${COMPIL_DIR}/$1 -name $2 -print ) |
---|
| 106 | [ ${#mycpp} -ne 0 ] && cpeval ${myarch} ${COMPIL_DIR}/$1 |
---|
[4148] | 107 | fi |
---|
| 108 | # has myarch file been updated since we copied it in ${COMPIL_DIR}? |
---|
| 109 | myarchdir=$( dirname ${myarch} ) |
---|
| 110 | myarchname=$( basename ${myarch} ) |
---|
| 111 | myarch=$( find -L $myarchdir -cnewer ${COMPIL_DIR}/$1 -name $myarchname -print ) |
---|
| 112 | [ ${#myarch} -ne 0 ] && cpeval ${myarch} ${COMPIL_DIR}/$1 |
---|
| 113 | else |
---|
| 114 | cpeval ${myarch} ${COMPIL_DIR}/$1 |
---|
| 115 | fi |
---|
| 116 | fi |
---|
| 117 | fi |
---|
| 118 | else |
---|
[9598] | 119 | nb=$( find ${MAIN_DIR}/arch -name arch-${3}.fcm -print | wc -l ) |
---|
[4148] | 120 | if [ $nb -eq 0 ]; then # no arch file found |
---|
| 121 | echo "Warning !!!" |
---|
| 122 | echo "Compiler not existing" |
---|
| 123 | echo "Try makenemo -h for help" |
---|
| 124 | echo "EXITING..." |
---|
| 125 | exit 1 |
---|
| 126 | fi |
---|
| 127 | if [ $nb -gt 1 ]; then # more than 1 arch file found |
---|
| 128 | echo "Warning !!!" |
---|
| 129 | echo "more than 1 arch file for the same compiler have been found" |
---|
[9598] | 130 | find ${MAIN_DIR}/arch -name arch-${3}.fcm -print |
---|
[4148] | 131 | echo "keep only 1" |
---|
| 132 | echo "EXITING..." |
---|
| 133 | exit 1 |
---|
| 134 | fi |
---|
[9598] | 135 | myarch=$( find ${MAIN_DIR}/arch -name arch-${3}.fcm -print ) |
---|
[4148] | 136 | # we were already using this arch file ? |
---|
| 137 | if [ "$myarch" == "$( cat ${COMPIL_DIR}/arch.history )" ]; then |
---|
| 138 | if [ -f ${COMPIL_DIR}/$1 ]; then |
---|
[4162] | 139 | if [ "$2" != "nocpp" ] |
---|
| 140 | then |
---|
| 141 | # has the cpp keys file been changed since we copied the arch file in ${COMPIL_DIR}? |
---|
| 142 | mycpp=$( ls -l ${COMPIL_DIR}/$2 | sed -e "s/.* -> //" ) |
---|
| 143 | if [ "$mycpp" != "$( cat ${COMPIL_DIR}/cpp.history )" ]; then |
---|
| 144 | echo $mycpp > ${COMPIL_DIR}/cpp.history |
---|
| 145 | cpeval ${myarch} ${COMPIL_DIR}/$1 |
---|
| 146 | fi |
---|
| 147 | # has the cpp keys file been updated since we copied the arch file in ${COMPIL_DIR}? |
---|
| 148 | mycpp=$( find -L ${COMPIL_DIR} -cnewer ${COMPIL_DIR}/$1 -name $2 -print ) |
---|
| 149 | [ ${#mycpp} -ne 0 ] && cpeval ${myarch} ${COMPIL_DIR}/$1 |
---|
[4148] | 150 | fi |
---|
| 151 | # has myarch file been updated since we copied it in ${COMPIL_DIR}? |
---|
[9598] | 152 | myarch=$( find -L ${MAIN_DIR}/arch -cnewer ${COMPIL_DIR}/$1 -name arch-${3}.fcm -print ) |
---|
[4148] | 153 | [ ${#myarch} -ne 0 ] && cpeval ${myarch} ${COMPIL_DIR}/$1 |
---|
| 154 | else |
---|
| 155 | cpeval ${myarch} ${COMPIL_DIR}/$1 |
---|
| 156 | fi |
---|
| 157 | else |
---|
[4162] | 158 | if [ "$2" != "nocpp" ] |
---|
| 159 | then |
---|
| 160 | ls -l ${COMPIL_DIR}/$2 | sed -e "s/.* -> //" > ${COMPIL_DIR}/cpp.history |
---|
| 161 | fi |
---|
[4148] | 162 | echo ${myarch} > ${COMPIL_DIR}/arch.history |
---|
| 163 | cpeval ${myarch} ${COMPIL_DIR}/$1 |
---|
| 164 | fi |
---|
[2136] | 165 | fi |
---|
[4148] | 166 | |
---|
| 167 | #- do we need xios library? |
---|
[7646] | 168 | #- 2 cases: |
---|
| 169 | #- in CONFIG directory looking for key_iomput |
---|
| 170 | if [ "$1" == "arch_nemo.fcm" ] |
---|
[4162] | 171 | then |
---|
[7646] | 172 | if [ "$2" != "nocpp" ] |
---|
| 173 | then |
---|
| 174 | use_iom=$( sed -e "s/#.*$//" ${COMPIL_DIR}/$2 | grep -c key_iomput ) |
---|
| 175 | else |
---|
| 176 | use_iom=0 |
---|
| 177 | fi |
---|
| 178 | have_lxios=$( sed -e "s/#.*$//" ${COMPIL_DIR}/$1 | grep -c "\-lxios" ) |
---|
| 179 | if [[ ( $use_iom -eq 0 ) && ( $have_lxios -ge 1 ) ]] |
---|
| 180 | then |
---|
| 181 | sed -e "s/-lxios//g" ${COMPIL_DIR}/$1 > ${COMPIL_DIR}/tmp$$ |
---|
| 182 | mv -f ${COMPIL_DIR}/tmp$$ ${COMPIL_DIR}/$1 |
---|
| 183 | fi |
---|
| 184 | #- in TOOLS directory looking for USE xios |
---|
[4162] | 185 | else |
---|
[7646] | 186 | use_iom=$( egrep --exclude-dir=.svn -r USE ${NEW_CONF}/src/* | grep -c xios ) |
---|
| 187 | have_lxios=$( sed -e "s/#.*$//" ${COMPIL_DIR}/$1 | grep -c "\-lxios" ) |
---|
| 188 | if [[ ( $use_iom -eq 0 ) || ( $have_lxios != 1 ) ]] |
---|
| 189 | then |
---|
| 190 | sed -e "s/-lxios//g" ${COMPIL_DIR}/$1 > ${COMPIL_DIR}/tmp$$ |
---|
| 191 | mv -f ${COMPIL_DIR}/tmp$$ ${COMPIL_DIR}/$1 |
---|
| 192 | fi |
---|
[4162] | 193 | fi |
---|
[4148] | 194 | |
---|
| 195 | #- do we need oasis libraries? |
---|
[4162] | 196 | if [ "$2" != "nocpp" ] |
---|
| 197 | then |
---|
| 198 | use_oasis=$( sed -e "s/#.*$//" ${COMPIL_DIR}/$2 | grep -c key_oasis3 ) |
---|
| 199 | else |
---|
| 200 | use_oasis=0 |
---|
| 201 | fi |
---|
[10449] | 202 | #ignore use_oasis if XIOS_OASIS is set (doesn't matter to what value) |
---|
| 203 | if [[ ! -z "$XIOS_OASIS" ]]; then |
---|
| 204 | use_oasis=1 |
---|
| 205 | fi |
---|
[4148] | 206 | for liboa in psmile.MPI1 mct mpeu scrip mpp_io |
---|
| 207 | do |
---|
| 208 | have_liboa=$( sed -e "s/#.*$//" ${COMPIL_DIR}/$1 | grep -c "\-l${liboa}" ) |
---|
| 209 | if [[ ( $use_oasis -eq 0 ) && ( $have_liboa -ge 1 ) ]] |
---|
| 210 | then |
---|
| 211 | sed -e "s/-l${liboa}//g" ${COMPIL_DIR}/$1 > ${COMPIL_DIR}/tmp$$ |
---|
| 212 | mv -f ${COMPIL_DIR}/tmp$$ ${COMPIL_DIR}/$1 |
---|
| 213 | fi |
---|
| 214 | done |
---|
| 215 | |
---|