Fcheck_archfile.sh 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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 :
  30. #
  31. # - There was a previous choice
  32. # - A new one has be specified, we use this one
  33. # - No information, exit
  34. #
  35. # We use TOOLS/COMPILE/arch.fcm to see if something was chosen.
  36. #
  37. # EXAMPLES
  38. # ========
  39. #
  40. # ::
  41. #
  42. # $ ./Fcheck_archfile.sh ARCHFILE CPPFILE COMPILER
  43. #
  44. #
  45. # TODO
  46. # ====
  47. #
  48. # option debug
  49. #
  50. #
  51. # EVOLUTIONS
  52. # ==========
  53. #
  54. # $Id: Fcheck_archfile.sh 4162 2013-11-07 10:19:49Z cetlod $
  55. #
  56. #
  57. #
  58. # * creation
  59. #
  60. #-
  61. cpeval ()
  62. {
  63. cat > $2 << EOF
  64. #==========================================================
  65. # Automatically generated by Fcheck_archfile.sh from
  66. # $1
  67. #==========================================================
  68. EOF
  69. while read line
  70. do
  71. eval "echo \"$line\" >> $2"
  72. done < $1
  73. }
  74. # cleaning related to the old version
  75. rm -f $( find ${COMPIL_DIR} -type l -name $1 -print )
  76. #
  77. if [ ${#3} -eq 0 ]; then # arch not specified
  78. if [ ! -f ${COMPIL_DIR}/arch.history ]; then
  79. echo "Warning !!!"
  80. echo "NO compiler chosen"
  81. echo "Try makenemo -h for help"
  82. echo "EXITING..."
  83. exit 1
  84. else # use the arch file defined in arch.history
  85. myarch=$( cat ${COMPIL_DIR}/arch.history )
  86. if [ ! -f $myarch ]; then
  87. echo "Warning !!!"
  88. echo "previously used arch file no more found:"
  89. echo $myarch
  90. echo "EXITING..."
  91. exit 1
  92. else
  93. if [ -f ${COMPIL_DIR}/$1 ]; then
  94. if [ "$2" != "nocpp" ]
  95. then
  96. # has the cpp keys file been changed since we copied the arch file in ${COMPIL_DIR}?
  97. mycpp=$( ls -l ${COMPIL_DIR}/$2 | sed -e "s/.* -> //" )
  98. if [ "$mycpp" != "$( cat ${COMPIL_DIR}/cpp.history )" ]; then
  99. echo $mycpp > ${COMPIL_DIR}/cpp.history
  100. cp ${myarch} ${COMPIL_DIR}/$1
  101. fi
  102. # has the cpp keys file been updated since we copied the arch file in ${COMPIL_DIR}?
  103. mycpp=$( find -L ${COMPIL_DIR} -cnewer ${COMPIL_DIR}/$1 -name $2 -print )
  104. [ ${#mycpp} -ne 0 ] && cp ${myarch} ${COMPIL_DIR}/$1
  105. fi
  106. # has myarch file been updated since we copied it in ${COMPIL_DIR}?
  107. myarchdir=$( dirname ${myarch} )
  108. myarchname=$( basename ${myarch} )
  109. myarch=$( find -L $myarchdir -cnewer ${COMPIL_DIR}/$1 -name $myarchname -print )
  110. [ ${#myarch} -ne 0 ] && cp ${myarch} ${COMPIL_DIR}/$1
  111. else
  112. cp ${myarch} ${COMPIL_DIR}/$1
  113. fi
  114. fi
  115. fi
  116. else
  117. nb=$( find ${MAIN_DIR}/ARCH -name arch-${3}.fcm -print | wc -l )
  118. if [ $nb -eq 0 ]; then # no arch file found
  119. echo "Warning !!!"
  120. echo "Compiler not existing"
  121. echo "Try makenemo -h for help"
  122. echo "EXITING..."
  123. exit 1
  124. fi
  125. if [ $nb -gt 1 ]; then # more than 1 arch file found
  126. echo "Warning !!!"
  127. echo "more than 1 arch file for the same compiler have been found"
  128. find ${MAIN_DIR}/ARCH -name arch-${3}.fcm -print
  129. echo "keep only 1"
  130. echo "EXITING..."
  131. exit 1
  132. fi
  133. myarch=$( find ${MAIN_DIR}/ARCH -name arch-${3}.fcm -print )
  134. # we were already using this arch file ?
  135. if [ "$myarch" == "$( cat ${COMPIL_DIR}/arch.history )" ]; then
  136. if [ -f ${COMPIL_DIR}/$1 ]; then
  137. if [ "$2" != "nocpp" ]
  138. then
  139. # has the cpp keys file been changed since we copied the arch file in ${COMPIL_DIR}?
  140. mycpp=$( ls -l ${COMPIL_DIR}/$2 | sed -e "s/.* -> //" )
  141. if [ "$mycpp" != "$( cat ${COMPIL_DIR}/cpp.history )" ]; then
  142. echo $mycpp > ${COMPIL_DIR}/cpp.history
  143. cp ${myarch} ${COMPIL_DIR}/$1
  144. fi
  145. # has the cpp keys file been updated since we copied the arch file in ${COMPIL_DIR}?
  146. mycpp=$( find -L ${COMPIL_DIR} -cnewer ${COMPIL_DIR}/$1 -name $2 -print )
  147. [ ${#mycpp} -ne 0 ] && cp ${myarch} ${COMPIL_DIR}/$1
  148. fi
  149. # has myarch file been updated since we copied it in ${COMPIL_DIR}?
  150. myarch=$( find -L ${MAIN_DIR}/ARCH -cnewer ${COMPIL_DIR}/$1 -name arch-${3}.fcm -print )
  151. [ ${#myarch} -ne 0 ] && cp ${myarch} ${COMPIL_DIR}/$1
  152. else
  153. cp ${myarch} ${COMPIL_DIR}/$1
  154. fi
  155. else
  156. if [ "$2" != "nocpp" ]
  157. then
  158. ls -l ${COMPIL_DIR}/$2 | sed -e "s/.* -> //" > ${COMPIL_DIR}/cpp.history
  159. fi
  160. echo ${myarch} > ${COMPIL_DIR}/arch.history
  161. cp ${myarch} ${COMPIL_DIR}/$1
  162. fi
  163. fi
  164. #- do we need xios library?
  165. if [ "$2" != "nocpp" ]
  166. then
  167. use_iom=$( sed -e "s/#.*$//" ${COMPIL_DIR}/$2 | grep -c key_iomput )
  168. else
  169. use_iom=0
  170. fi
  171. have_lxios=$( sed -e "s/#.*$//" ${COMPIL_DIR}/$1 | grep -c "\-lxios" )
  172. if [[ ( $use_iom -eq 0 ) && ( $have_lxios -ge 1 ) ]]
  173. then
  174. sed -e "s/-lxios//g" ${COMPIL_DIR}/$1 > ${COMPIL_DIR}/tmp$$
  175. mv -f ${COMPIL_DIR}/tmp$$ ${COMPIL_DIR}/$1
  176. fi
  177. # #- do we need oasis libraries?
  178. # if [ "$2" != "nocpp" ]
  179. # then
  180. # use_oasis=$( sed -e "s/#.*$//" ${COMPIL_DIR}/$2 | grep -c key_oasis3 )
  181. # else
  182. # use_oasis=0
  183. # fi
  184. # for liboa in psmile.MPI1 mct mpeu scrip mpp_io
  185. # do
  186. # have_liboa=$( sed -e "s/#.*$//" ${COMPIL_DIR}/$1 | grep -c "\-l${liboa}" )
  187. # if [[ ( $use_oasis -eq 0 ) && ( $have_liboa -ge 1 ) ]]
  188. # then
  189. # sed -e "s/-l${liboa}//g" ${COMPIL_DIR}/$1 > ${COMPIL_DIR}/tmp$$
  190. # mv -f ${COMPIL_DIR}/tmp$$ ${COMPIL_DIR}/$1
  191. # fi
  192. # done