Index: LMDZ5/branches/testing/create_make_gcm
===================================================================
--- LMDZ5/branches/testing/create_make_gcm	(revision 1707)
+++ LMDZ5/branches/testing/create_make_gcm	(revision 1750)
@@ -4,4 +4,7 @@
 #
 #set -xv
+
+rm -f create_make_gcm.log
+
 machine=`hostname`
 os=`uname`
@@ -122,36 +125,30 @@
 echo
 cd $libf >/dev/null 2>&1
-for diri in ` ls `
-do
+
+for diri in ` ls ` ; do
+
    if [ -d $diri ] ; then
-   if [ "`ls $diri/*.F`" != "" ] || [ "`ls $diri/*.F90`" != "" ]  ; then 
-      cd $diri >/dev/null 2>&1
+   if [ "`ls $diri/*.F $diri/*/*.F`" != "" ] || [ "`ls $diri/*.F90 $diri/*/*.F90`" != "" ]  ; then 
+#      cd $diri >/dev/null 2>&1
       echo
       listlib=""
-      for i in `ls *.F`
-      do
-         fili=`basename $i .F`
-         test=` (  head $i | grep '      PROGRAM' ) `
-         if [ "$test" = "" ] ; then 
-            listlib=$listlib" "$fili
-         fi
-      done
-      for i in `ls *.F90`
-      do
-         fili=`basename $i .F90`
-         test=` (  head $i | grep '      PROGRAM' ) `
-         if [ "$test" = "" ] ; then
-            listlib=$listlib" "$fili
-         fi 
-      done
-#
-      echo
-      echo
-      echo "#======================================================================="
+# Liste des fichiers .F et .F90 n'etant pas des programmes principaux
+      for fili in `ls $diri/*.F $diri/*/*.F` ; do
+         test=` (  head $fili | grep '      PROGRAM' ) `
+         if [ "$test" = "" ] ; then listlib=$listlib" "$fili ; fi
+      done
+      for fili in `ls $diri/*.F90 $diri/*/*.F90` ; do
+         test=` (  head $fili | grep 'PROGRAM' ) `
+         if [ "$test" = "" ] ; then listlib=$listlib" "$fili ; fi 
+      done
+      echo
+      echo $listlib >> create_makeg_gcm.log
+      echo
+      echo "#=================================================================="
       echo "# Contenu de la bibliotheque correspondant au Directory "$diri
-      echo "#======================================================================="
-      echo
-      for fili in $listlib
-      do
+      echo "#=================================================================="
+      echo
+      for trufile in $listlib ; do
+         fili=`echo $trufile | awk -F/ ' { print $NF } ' | cut -d. -f1`
          echo '$(LIBO)/lib'$diri".a : " '$(LIBO)/lib'$diri".a("$fili".o)"
          echo
@@ -162,47 +159,46 @@
       echo "# Compilation des membres de la bibliotheque lib"$diri".a"
       echo
-      for fili in $listlib
-      do
-         if [ -f $fili.F90 ] ; then
-           trufile=$fili.F90
-         else
-           trufile=$fili.F
-         fi
+      for trufile in $listlib ; do
+         fili=`echo $trufile | awk -F/ ' { print $NF } ' | cut -d. -f1`
          F90=0 ; egrep -i '^ *use ' $trufile > /dev/null 2>&1 && F90=1
                  egrep -i '^ *module ' $trufile > /dev/null 2>&1 && F90=1
                  egrep -i '#include*.inc ' $trufile > /dev/null 2>&1 && F90=1
-         str1='$(LIBO)/lib'$diri'.a('$fili'.o) : $(LIBF)/'$diri/$trufile
-         [ "$fili" = "chem.subs" ] && str1=$str1' $(LIBF)/'$diri/chem.mods.F
-         for stri in ` ( sed -n "/\#include/s/\#include//p" $trufile | sed 's/\"//g' ; egrep -i '^ *use ' $trufile | sed -e 's/,/ /' | awk ' { print $2 } ' ) `
-         do
-
-
+         str1='$(LIBO)/lib'$diri'.a('$fili'.o) : $(LIBF)/'$trufile
+         [ "$fili" = "$diri/chem.subs" ] && str1=$str1' $(LIBF)/'$diri/chem.mods.F
+
+##########################################################################
+# TRAITEMENT DES DEPENDANCES
 # Differents cas de dependance correspondant a des include ou des
 # use module.
 # soit dans le repertoire local soit dans un autre.
-
-            stri=`echo $stri | tr [A-Z] [a-z]`
-            if [ -f $stri ] ; then
+# Pour dyn3d, il faudrait remplacer la chaine de caractere par $DYN
+# ou quelque chose du genre.
+##########################################################################
+
+         for stri in ` ( sed -e '/^[cC\!]/d' $trufile | sed -n "/\#include/s/\#include//p" | sed 's/\"//g' ; sed -e '/^[cC\!]/d' $trufile | egrep -i '^ *use ' | sed -e 's/,/ /' | awk ' { print $2 } ' ) ` ; do
+            echo $trufile $fili $stri >> create_make_gcm.log
+            strj=`echo $stri | tr [A-Z] [a-z]`
+            str2=""
+            for dirinc in filtrez bibio grid dyn3d $diri $diri/*/ ; do
+# Recherche dans l'ordre hierarchique inverse car seule la derniere
+# ligne est conservee
+               if [ -f $dirinc/$stri ] ; then
+                  str2='$(LIBF)/'$dirinc/$stri
+               elif [ -f $dirinc/$strj ] ; then
+                  str2='$(LIBF)/'$dirinc/$stri
+               elif [ -f $dirinc/$strj.F90 ]  || [ -f $dirinc/$strj.F ]  ; then 
+                  strlib=`echo $dirinc | awk -F/ ' { print $1 } '`
+                  str2='$(LIBO)/lib'$strlib'.a('$strj'.o)'
+               fi
+            done
+            if [ "$str2" = "" ] ; then
+               echo Warn: Include $diri $trufile $fili $stri pas trouve >> $gcm/create_make_gcm.log
+            elif [ "$str2" = "$str1" ] ; then
+               echo Warn: Include $diri $trufile $fili $stri $str1 trouve 2x >> $gcm/create_make_gcm.log
+            else
                echo $str1 \\
-               str1='$(LIBF)/'$diri'/'$stri
-            else
-               if [ -f $stri.F ] || [ -f $stri.F90 ] ; then
-                  echo $str1 \\
-                  str1='$(LIBO)/lib'$diri'.a('$stri'.o)'
-               else
-                  for dirinc in dyn3d grid bibio filtrez
-                  do
-                     if [ -f ../$dirinc/$stri ] ; then
-                        echo $str1 \\
-                        str1='$(LIBF)/'`cd .. ; ls */$stri | head -1`
-                     fi
-                     if [ -f ../$dirinc/$stri.F90 ] ; then
-                        echo $str1 \\
-                        str1='$(LIBO)/lib'$dirinc'.a('$stri'.o)'
-                     fi
-                  done
-               fi
+               str1=$str2
             fi
-         done
+         done # Fin de la boucle sur les dependances et ecriture de la derniere
          echo $str1
          # Compile in LIBO directory; and before compiling, remove
@@ -212,12 +208,12 @@
 	 if [ "$F90" -eq '0' ] ; then
          ## Fixed Form Fortran 77
-	   echo '	$(COMPILE) $(LIBF)/'$diri'/'$trufile' ; \'
+	   echo '	$(COMPILE) $(LIBF)/'$trufile' ; \'
 	 else
          ## Fortran 90
-           if [ -f $fili.F90 ] ; then
+           if [ `echo $trufile | cut -d. -f2` = F90 ] ; then
 	      ## Free Form
-              echo '	$(COMPTRU90) $(LIBF)/'$diri'/'$trufile' ; \'
+              echo '	$(COMPTRU90) $(LIBF)/'$trufile' ; \'
            else
-	      echo '	$(COMPILE90) $(LIBF)/'$diri'/'$trufile' ; \'
+	      echo '	$(COMPILE90) $(LIBF)/'$trufile' ; \'
            fi
 	 fi
