Index: /LMDZ5/trunk/create_make_gcm
===================================================================
--- /LMDZ5/trunk/create_make_gcm	(revision 2237)
+++ /LMDZ5/trunk/create_make_gcm	(revision 2238)
@@ -5,4 +5,6 @@
 #set -xv
 
+# arguments given to create_make_gcm are the directories to scan
+src_dirs=$*
 
 machine=`hostname`
@@ -121,18 +123,24 @@
 cd $libf >/dev/null 2>&1
 
-for diri in ` ls ` ; do
+for diri in $src_dirs ; do
 
    if [ -d $diri ] ; then
-   if [ "`ls $diri/*.F $diri/*/*.F`" != "" ] || [ "`ls $diri/*.[fF]90 $diri/*/*.[fF]90`" != "" ]  ; then 
+   if [ "`ls $diri/*.F`" != "" ] || [ "`ls $diri/*.[fF]90`" != "" ]  ; then 
 #      cd $diri >/dev/null 2>&1
       echo
       listlib=""
 # Liste des fichiers .F et .F90 n'etant pas des programmes principaux
-      for fili in `ls $diri/*.[fF] $diri/*/*.[fF]` ; do
-         test=` (  head $fili | grep '      PROGRAM' ) `
+      for fili in `ls $diri/*.[fF]` ; do
+         # Check if file is a routine or main program
+         # i.e: look for the "program" keword preceeded by leading spaces
+         test=` (  head $fili | grep -i '^ *program' ) `
+         # if it is not a main program, add it to the list
          if [ "$test" = "" ] ; then listlib=$listlib" "$fili ; fi
       done
-      for fili in `ls $diri/*.[fF]90 $diri/*/*.[fF]90` ; do
-         test=` (  head $fili | grep 'PROGRAM' ) `
+      for fili in `ls $diri/*.[fF]90` ; do
+         # Check if file is a routine or main program
+         # i.e. look for "program" keyword (with possibly some leading spaces)
+         test=` (  head $fili | grep -i '^ \{0,\}program' ) `
+         # if it is not a main program, add it to the list
          if [ "$test" = "" ] ; then listlib=$listlib" "$fili ; fi 
       done
@@ -140,4 +148,6 @@
       echo $listlib >> $logfile
       echo
+      # topdiri contains main dir name (without trailing "/blabla" for subdirs)
+      topdiri=${diri%/*}
       echo "#=================================================================="
       echo "# Contenu de la bibliotheque correspondant au Directory "$diri
@@ -146,11 +156,11 @@
       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 '$(LIBO)/lib'$topdiri".a : " '$(LIBO)/lib'$topdiri".a("$fili".o)"
          echo
       done
-      echo '.PRECIOUS	: $(LIBO)/lib'$diri'.a'
-      echo
-      echo
-      echo "# Compilation des membres de la bibliotheque lib"$diri".a"
+      echo '.PRECIOUS	: $(LIBO)/lib'$topdiri'.a'
+      echo
+      echo
+      echo "# Compilation of elements in $diri of library lib"$topdiri".a"
       echo
       for trufile in $listlib ; do
@@ -159,5 +169,5 @@
                  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)/'$trufile
+         str1='$(LIBO)/lib'$topdiri'.a('$fili'.o) : $(LIBF)/'$trufile
          [ "$fili" = "$diri/chem.subs" ] && str1=$str1' $(LIBF)/'$diri/chem.mods.F
 
@@ -175,14 +185,14 @@
             strj=`echo $stri | tr [A-Z] [a-z]`
             str2=""
-            for dirinc in filtrez bibio dyn3d_common grid dyn3d phydev $diri $diri/*/ ; do
+            for dirinc in $src_dirs ; do
 # Recherche dans l'ordre hierarchique inverse car seule la derniere
 # ligne est conservee
-               if [ $dirinc = phydev ] ; then
-                   dirstr='$(PHYS)'
-                   libstr='phy$(PHYS)'
-               else
+#               if [ $dirinc = phydev ] ; then
+#                   dirstr='$(PHYS)'
+#                   libstr='phy$(PHYS)'
+#               else
                    dirstr=$dirinc
                    libstr=$dirinc
-               fi
+#               fi
                echo dirinc $dirinc >> $logfile
                if [ -f $dirinc/$stri ] ; then
@@ -214,5 +224,5 @@
          # object from library
          echo '	cd $(LIBO); \'
-         echo '	$(AR) d $(LIBO)/lib'$diri'.a '$fili'.o ; \'
+         echo '	$(AR) d $(LIBO)/lib'$topdiri'.a '$fili'.o ; \'
 	 if [ "$F90" -eq '0' ] ; then
          ## Fixed Form Fortran 77
@@ -228,5 +238,5 @@
 	 fi
          # Put generated object in library
-         echo '	$(AR) r $(LIBO)/lib'$diri'.a '$fili'.o ; $(RM) '$fili'.o ; \'
+         echo '	$(AR) r $(LIBO)/lib'$topdiri'.a '$fili'.o ; $(RM) '$fili'.o ; \'
 	 echo
       done
Index: /LMDZ5/trunk/makelmdz
===================================================================
--- /LMDZ5/trunk/makelmdz	(revision 2237)
+++ /LMDZ5/trunk/makelmdz	(revision 2238)
@@ -84,5 +84,6 @@
 PARA_LD=""
 EXT_SRC=""
-
+#src_dirs: directories containing source files 
+src_dirs="grid bibio" 
 ########################################################################
 # lecture des options
@@ -106,4 +107,7 @@
           true        : (obsolete; for backward compatibility) use ORCHIDEE tag 1.9-1.9.6
 [-chimie INCA/false]       : with INCA chemistry model or without (default: false)
+[-cosp true/false]    : compile with/without cosp package (default: false)
+[-sisvat true/false]  : compile with/without sisvat package (default: false)
+[-rrtm true/false]    : compile with/without rrtm package (default: false)
 [-parallel none/mpi/omp/mpi_omp] : parallelism (default: none) : mpi, openmp or mixted mpi_openmp
 [-g GRI]                   : grid configuration in dyn3d/GRI_xy.h  (default: reg, inclues a zoom)
@@ -186,5 +190,5 @@
 
       "-ext_src")
-	  EXT_SRC=$2 ; shift ; shift ;;
+	  EXT_SRC=$2 ; src_dirs="$src_dirs $EXT_SRC" ; shift ; shift ;;
 
       "-arch")
@@ -283,4 +287,5 @@
 then
    #We'll use some physics
+   src_dirs="$src_dirs phy$physique"
    CPP_KEY="$CPP_KEY CPP_PHYS"
    if [[ "${physique:0:3}" == "lmd" ]]
@@ -316,5 +321,5 @@
       echo "You should use option \"-mem\"."
       exit 1
-  fi     
+  fi
 fi
 
@@ -413,4 +418,5 @@
    CPP_KEY="$CPP_KEY CPP_COSP"
    COSP_PATH="$LIBFGCM/cosp"
+   src_dirs="$src_dirs cosp"
 #   LIB="${LIB} -l${LIBPREFIX}cosp"
    opt_dep="$opt_dep cosp"
@@ -422,4 +428,5 @@
 then
    CPP_KEY="$CPP_KEY CPP_SISVAT"
+   src_dirs="$src_dirs phy${physique}/sisvat"
 fi
 
@@ -427,4 +434,5 @@
 then
    CPP_KEY="$CPP_KEY CPP_RRTM"
+   src_dirs="$src_dirs phy${physique}/rrtm"
 fi
 
@@ -489,4 +497,5 @@
 
 if (( $dimc == 3 )) ; then
+   src_dirs="$src_dirs $filtre dyn3d_common dyn3d${FLAG_PARA}"
    cd $LIBFGCM/grid
    \rm fxyprim.h
@@ -498,4 +507,5 @@
    INCLUDE="$INCLUDE "'-I$(LIBF)/dyn2d'
 elif (( $dimc == 1 )) ; then
+   src_dirs="$src_dirs dyn3d dyn3d_common filtrez"
    CPP_KEY="$CPP_KEY CPP_1D"
    filtre="L_DYN= DYN= FILTRE= L_FILTRE= DIRMAIN=phy$physique "
@@ -539,9 +549,23 @@
 cd $LMDGCM
 
-find libf -name '*.[Fh]' -print > tmp77
-find libf -name '*.[Fh]' -exec egrep -i " *use *ioipsl" {} \; -print > tmp90
-find libf -name '*.F90' -print >> tmp90
-
-if [[ ! ( -r makefile ) || ! ( -r liste_des_sources_f90 ) || ! ( -r liste_des_sources_f77 ) || ` diff tmp77 liste_des_sources_f77 | wc -w ` -ne 0 || ` diff tmp90 liste_des_sources_f90 | wc -w ` -ne 0 ]]
+find libf -name '*.[Fh]' -print | sort > tmp77
+#find libf -name '*.[Fh]' -exec egrep -i " *use *ioipsl" {} \; -print > tmp90
+find libf -name '*.F90' -print | sort > tmp90
+
+if [[ -r .makelmdz ]]
+then
+old_lmdz_configuration=$(cat .makelmdz )
+else
+old_lmdz_configuration=""
+fi
+lmdz_configuration="$src_dirs"
+if [[ "$lmdz_configuration" != "$old_lmdz_configuration" ]]
+then
+  configuration_change="true"
+else
+  configuration_change="false"
+fi
+
+if [[ $configuration_change == "true" || ! ( -r makefile ) || ! ( -r liste_des_sources_f90 ) || ! ( -r liste_des_sources_f77 ) || ` diff tmp77 liste_des_sources_f77 | wc -w ` -ne 0 || ` diff tmp90 liste_des_sources_f90 | wc -w ` -ne 0 ]]
 then
   echo "les fichiers suivants ont ete crees ou detruits"
@@ -551,9 +575,13 @@
   \cp -f tmp77 liste_des_sources_f77
   \cp -f tmp90 liste_des_sources_f90
-  echo "on recree le makefile"
-  ./create_make_gcm > tmp 
+  echo "Recreating the makefile"
+  echo "src_dirs: $src_dirs"
+  ./create_make_gcm $src_dirs > tmp 
   \mv -f tmp makefile
-  echo "Nouveau makefile cree"
-fi
+  echo "New makefile created"
+fi
+
+#Create a .makelmdz file containing main compilation option for later comparisons
+echo "$lmdz_configuration" > .makelmdz
 
 #################################################################
Index: /LMDZ5/trunk/makelmdz_fcm
===================================================================
--- /LMDZ5/trunk/makelmdz_fcm	(revision 2237)
+++ /LMDZ5/trunk/makelmdz_fcm	(revision 2238)
@@ -78,4 +78,7 @@
           true        : (obsolete; for backward compatibility) use ORCHIDEE tag 1.9-1.9.6
 [-chimie INCA/false]       : with INCA chemistry model or without (default: false)
+[-cosp true/false]    : compile with/without cosp package (default: false)
+[-sisvat true/false]  : compile with/without sisvat package (default: false)
+[-rrtm true/false]    : compile with/without rrtm package (default: false)
 [-parallel none/mpi/omp/mpi_omp] : parallelism (default: none) : mpi, openmp or mixted mpi_openmp
 [-g GRI]                   : grid configuration in dyn3d/GRI_xy.h  (default: reg, inclues a zoom)
