Index: /CMT/HEAD/ChangeLog
===================================================================
--- /CMT/HEAD/ChangeLog	(revision 426)
+++ /CMT/HEAD/ChangeLog	(revision 427)
@@ -1,2 +1,10 @@
+2007-09-01    <rybkin@lal.in2p3.fr> 333
+
+	* source/cmt_deps_builder.h: idem
+	* source/cmt_deps_builder.cxx: idem
+	* source/cmt_generators.h: idem
+	* source/cmt_generators.cxx: Implement a header file filter mechanism to replace
+        header files matching a pattern with a stamp file when calculating files dependencies
+
 2007-07-09    <rybkin@lal.in2p3.fr> 332
 
Index: /CMT/HEAD/mgr/cmt_dependencies.make
===================================================================
--- /CMT/HEAD/mgr/cmt_dependencies.make	(revision 426)
+++ /CMT/HEAD/mgr/cmt_dependencies.make	(revision 427)
@@ -2,8 +2,8 @@
 cmt_awk_cxx_dependencies =  ../source/cmt_awk.cxx   ../source/cmt_std.h   ../source/cmt_string.h   ../source/cmt_regexp.h   ../source/cmt_awk.h   ../source/cmt_vector.h   ../source/cmt_system.h 
 cmt_branch_cxx_dependencies =  ../source/cmt_branch.cxx   ../source/cmt_std.h   ../source/cmt_string.h   ../source/cmt_vector.h   ../source/cmt_regexp.h   ../source/cmt_system.h   ../source/cmt.h   ../source/cmt_parser.h   ../source/cmt_branch.h   ../source/cmt_fragment.h   ../source/cmt_group.h   ../source/cmt_constituent.h   ../source/cmt_language.h   ../source/cmt_map.h   ../source/cmt_pattern.h   ../source/cmt_include.h   ../source/cmt_script.h   ../source/cmt_scope_section.h   ../source/cmt_use.h   ../source/cmt_tag.h   ../source/cmt_symbol.h   ../source/cmt_awk.h   ../source/cmt_project.h   ../source/cmt_cmtpath_pattern.h   ../source/cmt_database.h 
-cmt_constituent_cxx_dependencies =  ../source/cmt_constituent.cxx   ../source/cmt_std.h   ../source/cmt_string.h   ../source/cmt_vector.h   ../source/cmt_regexp.h   ../source/cmt_system.h   ../source/cmt.h   ../source/cmt_parser.h   ../source/cmt_fragment.h   ../source/cmt_group.h   ../source/cmt_constituent.h   ../source/cmt_language.h   ../source/cmt_awk.h   ../source/cmt_deps_builder.h   ../source/cmt_generator.h   ../source/cmt_branch.h   ../source/cmt_map.h   ../source/cmt_pattern.h   ../source/cmt_include.h   ../source/cmt_script.h   ../source/cmt_scope_section.h   ../source/cmt_use.h   ../source/cmt_tag.h   ../source/cmt_symbol.h   ../source/cmt_project.h   ../source/cmt_cmtpath_pattern.h   ../source/cmt_database.h 
-cmt_deps_builder_cxx_dependencies =  ../source/cmt_deps_builder.cxx   ../source/cmt_std.h   ../source/cmt_string.h   ../source/cmt_vector.h   ../source/cmt_parser.h   ../source/cmt_regexp.h   ../source/cmt_system.h   ../source/cmt.h   ../source/cmt_deps_builder.h   ../source/cmt_map.h   ../source/cmt_include.h   ../source/cmt_script.h   ../source/cmt_pattern.h   ../source/cmt_scope_section.h   ../source/cmt_use.h   ../source/cmt_tag.h   ../source/cmt_symbol.h   ../source/cmt_log.h 
+cmt_constituent_cxx_dependencies =  ../source/cmt_constituent.cxx   ../source/cmt_std.h   ../source/cmt_string.h   ../source/cmt_vector.h   ../source/cmt_regexp.h   ../source/cmt_system.h   ../source/cmt.h   ../source/cmt_parser.h   ../source/cmt_fragment.h   ../source/cmt_group.h   ../source/cmt_constituent.h   ../source/cmt_language.h   ../source/cmt_awk.h   ../source/cmt_map.h   ../source/cmt_include.h   ../source/cmt_script.h   ../source/cmt_pattern.h   ../source/cmt_scope_section.h   ../source/cmt_use.h   ../source/cmt_deps_builder.h   ../source/cmt_generator.h   ../source/cmt_branch.h   ../source/cmt_tag.h   ../source/cmt_symbol.h   ../source/cmt_project.h   ../source/cmt_cmtpath_pattern.h   ../source/cmt_database.h 
+cmt_deps_builder_cxx_dependencies =  ../source/cmt_deps_builder.cxx   ../source/cmt_std.h   ../source/cmt_string.h   ../source/cmt_vector.h   ../source/cmt_parser.h   ../source/cmt_regexp.h   ../source/cmt_system.h   ../source/cmt.h   ../source/cmt_map.h   ../source/cmt_include.h   ../source/cmt_script.h   ../source/cmt_pattern.h   ../source/cmt_scope_section.h   ../source/cmt_use.h   ../source/cmt_deps_builder.h   ../source/cmt_tag.h   ../source/cmt_symbol.h   ../source/cmt_log.h 
 cmt_fragment_cxx_dependencies =  ../source/cmt_fragment.cxx   ../source/cmt_std.h   ../source/cmt_string.h   ../source/cmt_vector.h   ../source/cmt_regexp.h   ../source/cmt_system.h   ../source/cmt.h   ../source/cmt_parser.h   ../source/cmt_fragment.h   ../source/cmt_map.h   ../source/cmt_include.h   ../source/cmt_script.h   ../source/cmt_pattern.h   ../source/cmt_scope_section.h   ../source/cmt_use.h   ../source/cmt_tag.h   ../source/cmt_symbol.h   ../source/cmt_branch.h   ../source/cmt_group.h   ../source/cmt_constituent.h   ../source/cmt_language.h   ../source/cmt_awk.h   ../source/cmt_project.h   ../source/cmt_cmtpath_pattern.h   ../source/cmt_database.h 
-cmt_generator_cxx_dependencies =  ../source/cmt_generator.cxx   ../source/cmt_std.h   ../source/cmt_string.h   ../source/cmt_vector.h   ../source/cmt_regexp.h   ../source/cmt_system.h   ../source/cmt.h   ../source/cmt_parser.h   ../source/cmt_fragment.h   ../source/cmt_group.h   ../source/cmt_constituent.h   ../source/cmt_language.h   ../source/cmt_awk.h   ../source/cmt_deps_builder.h   ../source/cmt_generator.h   ../source/cmt_map.h   ../source/cmt_include.h   ../source/cmt_script.h   ../source/cmt_pattern.h   ../source/cmt_scope_section.h   ../source/cmt_use.h   ../source/cmt_tag.h   ../source/cmt_symbol.h   ../source/cmt_generators.h 
+cmt_generator_cxx_dependencies =  ../source/cmt_generator.cxx   ../source/cmt_std.h   ../source/cmt_string.h   ../source/cmt_vector.h   ../source/cmt_regexp.h   ../source/cmt_system.h   ../source/cmt.h   ../source/cmt_parser.h   ../source/cmt_fragment.h   ../source/cmt_group.h   ../source/cmt_constituent.h   ../source/cmt_language.h   ../source/cmt_awk.h   ../source/cmt_map.h   ../source/cmt_include.h   ../source/cmt_script.h   ../source/cmt_pattern.h   ../source/cmt_scope_section.h   ../source/cmt_use.h   ../source/cmt_deps_builder.h   ../source/cmt_generator.h   ../source/cmt_tag.h   ../source/cmt_symbol.h   ../source/cmt_generators.h 
 cmt_include_cxx_dependencies =  ../source/cmt_include.cxx   ../source/cmt_std.h   ../source/cmt_string.h   ../source/cmt_vector.h   ../source/cmt_regexp.h   ../source/cmt_system.h   ../source/cmt.h   ../source/cmt_parser.h   ../source/cmt_include.h   ../source/cmt_map.h   ../source/cmt_script.h   ../source/cmt_pattern.h   ../source/cmt_scope_section.h   ../source/cmt_use.h   ../source/cmt_tag.h   ../source/cmt_symbol.h   ../source/cmt_log.h 
 cmt_parser_cxx_dependencies =  ../source/cmt_parser.cxx   ../source/cmt_std.h   ../source/cmt_string.h   ../source/cmt_vector.h   ../source/cmt_regexp.h   ../source/cmt_system.h   ../source/cmt.h   ../source/cmt_parser.h   ../source/cmt_version.h   ../source/cmt_branch.h   ../source/cmt_fragment.h   ../source/cmt_group.h   ../source/cmt_constituent.h   ../source/cmt_language.h   ../source/cmt_map.h   ../source/cmt_pattern.h   ../source/cmt_include.h   ../source/cmt_script.h   ../source/cmt_scope_section.h   ../source/cmt_use.h   ../source/cmt_tag.h   ../source/cmt_symbol.h   ../source/cmt_awk.h   ../source/cmt_project.h   ../source/cmt_cmtpath_pattern.h   ../source/cmt_database.h   ../source/cmt_deps_builder.h   ../source/cmt_generator.h   ../source/cmt_error.h   ../source/cmt_cvs.h   ../source/cmt_lock.h   ../source/cmt_triggers.h   ../source/cmt_model.h   ../source/cmt_syntax.h   ../source/cmt_install_area.h   ../source/cmt_sequence.h   ../source/cmt_log.h   ../source/cmt_commands.h 
@@ -29,5 +29,5 @@
 cmt_cmtpath_pattern_cxx_dependencies =  ../source/cmt_cmtpath_pattern.cxx   ../source/cmt_vector.h   ../source/cmt_std.h   ../source/cmt_string.h   ../source/cmt_regexp.h   ../source/cmt_system.h   ../source/cmt.h   ../source/cmt_parser.h   ../source/cmt_branch.h   ../source/cmt_fragment.h   ../source/cmt_group.h   ../source/cmt_constituent.h   ../source/cmt_language.h   ../source/cmt_map.h   ../source/cmt_pattern.h   ../source/cmt_include.h   ../source/cmt_script.h   ../source/cmt_scope_section.h   ../source/cmt_use.h   ../source/cmt_tag.h   ../source/cmt_symbol.h   ../source/cmt_awk.h   ../source/cmt_project.h   ../source/cmt_cmtpath_pattern.h   ../source/cmt_database.h   ../source/cmt_syntax.h 
 cmt_sequence_cxx_dependencies =  ../source/cmt_sequence.cxx   ../source/cmt_std.h   ../source/cmt_string.h   ../source/cmt_regexp.h   ../source/cmt_awk.h   ../source/cmt_sequence.h   ../source/cmt_vector.h   ../source/cmt_system.h 
-cmt_generators_cxx_dependencies =  ../source/cmt_generators.cxx   ../source/cmt_std.h   ../source/cmt_string.h   ../source/cmt_vector.h   ../source/cmt_regexp.h   ../source/cmt_system.h   ../source/cmt.h   ../source/cmt_parser.h   ../source/cmt_fragment.h   ../source/cmt_group.h   ../source/cmt_constituent.h   ../source/cmt_language.h   ../source/cmt_awk.h   ../source/cmt_deps_builder.h   ../source/cmt_generator.h   ../source/cmt_generators.h   ../source/cmt_map.h   ../source/cmt_include.h   ../source/cmt_script.h   ../source/cmt_pattern.h   ../source/cmt_scope_section.h   ../source/cmt_use.h   ../source/cmt_tag.h   ../source/cmt_symbol.h   ../source/cmt_log.h 
+cmt_generators_cxx_dependencies =  ../source/cmt_generators.cxx   ../source/cmt_std.h   ../source/cmt_string.h   ../source/cmt_vector.h   ../source/cmt_regexp.h   ../source/cmt_system.h   ../source/cmt.h   ../source/cmt_parser.h   ../source/cmt_fragment.h   ../source/cmt_group.h   ../source/cmt_constituent.h   ../source/cmt_language.h   ../source/cmt_awk.h   ../source/cmt_map.h   ../source/cmt_include.h   ../source/cmt_script.h   ../source/cmt_pattern.h   ../source/cmt_scope_section.h   ../source/cmt_use.h   ../source/cmt_deps_builder.h   ../source/cmt_generator.h   ../source/cmt_generators.h   ../source/cmt_tag.h   ../source/cmt_symbol.h   ../source/cmt_log.h 
 cmt_scope_section_cxx_dependencies =  ../source/cmt_scope_section.cxx   ../source/cmt_std.h   ../source/cmt_string.h   ../source/cmt_vector.h   ../source/cmt_regexp.h   ../source/cmt_system.h   ../source/cmt.h   ../source/cmt_parser.h   ../source/cmt_scope_section.h 
 cmt_log_cxx_dependencies =  ../source/cmt_log.cxx   ../source/cmt_std.h   ../source/cmt_string.h   ../source/cmt_log.h   ../source/cmt_vector.h   ../source/cmt_parser.h   ../source/cmt_regexp.h   ../source/cmt_system.h   ../source/cmt.h 
Index: /CMT/HEAD/source/cmt_deps_builder.cxx
===================================================================
--- /CMT/HEAD/source/cmt_deps_builder.cxx	(revision 426)
+++ /CMT/HEAD/source/cmt_deps_builder.cxx	(revision 427)
@@ -30,12 +30,19 @@
 
 //--------------------------------------------------
-static int build_deps (const cmt_string& name,
-                       const cmt_string& dir_name,
-                       int current_path_index,
-                       const CmtSystem::cmt_string_vector& include_paths,
-                       const CmtSystem::cmt_string_vector& substitutions,
-                       CmtSystem::cmt_string_vector& all_deps,
-                       CmtSystem::cmt_string_vector& deps);
-
+static int locate (const cmt_string& name,
+                   const cmt_string& dir_name,
+                   const CmtSystem::cmt_string_vector& include_paths,
+                   const CmtSystem::cmt_string_vector& substitutions,
+                   cmt_string& full_name);
+
+//--------------------------------------------------
+static void build_deps_text (char* text,
+			     const cmt_string& dir_name,
+			     int current_path_index,
+			     const CmtSystem::cmt_string_vector& include_paths,
+			     const CmtSystem::cmt_string_vector& substitutions,
+                             const DepsBuilder::HeaderFilters& header_filters,
+			     CmtSystem::cmt_string_vector& all_deps,
+			     CmtSystem::cmt_string_vector& deps);
 
 //--------------------------------------------------
@@ -45,4 +52,5 @@
                                 const CmtSystem::cmt_string_vector& include_paths,
                                 const CmtSystem::cmt_string_vector& substitutions,
+                                const DepsBuilder::HeaderFilters& header_filters,
                                 CmtSystem::cmt_string_vector& all_deps,
                                 CmtSystem::cmt_string_vector& deps)
@@ -50,6 +58,4 @@
   Log;
 
-  bool found = false;
-
   for (int i = 0; i < all_deps.size (); i++)
     {
@@ -58,51 +64,96 @@
       log << "CMT> check old header file name=" << n << " against " << header_file << log_endl;
 
-      if (n == header_file)
-        {
-          found = true;
-          break;
-        }
-    }
-  
-  if (!found)
-    {
-      log << "CMT> parsing new header file name=" << header_file << log_endl;
-
-      all_deps.push_back (header_file);
+      if (n == header_file) return;
+    }
+
+  all_deps.push_back (header_file);
+
+  cmt_string header_file_path;
+  int path_index = locate (header_file,
+                           dir_name,
+                           include_paths,
+                           substitutions,
+                           header_file_path);
+
+  if (path_index < 0) return;
+
+  static int header_filters_size = header_filters.size ();
+  if (header_filters_size > 0)
+    {
+      // check the filter macros from
+      // find all macros named <package>_header_file_filter
+      // for all those macros, get the regexp and check the matches against the header file name
+      // if any match, select the stamp file instead of the header file
+      // the stamp file might be either a conventional name
+      //         <package>/cmt/cmt_all_headers.stamp
+      // or given in a macro eg <package>_header_stamp_file_name
+      //
+      for (int i = header_filters_size - 1; i >= 0; i--)
+        {
+          cmt_string stamp_file;
+          if (header_filters[i].use_stamp (header_file_path, stamp_file))
+            {
+              bool included = false;
+              for (int i = deps.size () - 1; i >= 0; i--)
+                {
+                  if (deps[i] == stamp_file)
+                    {
+                      included = true;
+                      break;
+                    }
+                }
+              if (!included) deps.push_back (stamp_file);
+              return;
+            }
+        }
+    }
+
+  log << "CMT> parsing new header file name=" << header_file << log_endl;
+
+///////////////////////////////////////////////////////////////////////////////////////////////////////
+  cmt_string text;
+  text.read (header_file_path);
+  char* ptr = &text[0];
+  cmt_string new_dir;
+  CmtSystem::dirname (header_file_path, new_dir);
+
+  if (path_index == 0 || path_index == 1)
+    build_deps_text (ptr, new_dir,
+                     current_path_index,
+                     include_paths, substitutions,
+                     header_filters,
+                     all_deps, deps);
+  else
+    build_deps_text (ptr, new_dir,
+                     path_index,
+                     include_paths, substitutions,
+                     header_filters,
+                     all_deps, deps);
+///////////////////////////////////////////////////////////////////////////////////////////////////////
       
-      int path_index = build_deps (header_file,
-                                   dir_name,
-                                   current_path_index,
-                                   include_paths,
-                                   substitutions,
-                                   all_deps,
-                                   deps);
-      
-      if (path_index >= 0)
-        {
-          cmt_string full_name;
-          
-          if (path_index == 1)
-            {
-              full_name = dir_name;
-              full_name += CmtSystem::file_separator ();
-              
-              if (current_path_index >= 2)
-                {
-                  full_name.replace (include_paths[current_path_index - 2],
-                                     substitutions[current_path_index - 2]);
-                }
-            }
-          else if (path_index > 1)
-            {
-              full_name  = substitutions[path_index - 2];
-              full_name += CmtSystem::file_separator ();
-            }
-          
-          full_name += header_file;
-          
-          deps.push_back (full_name);
-        }
-    }
+//path_index >= 0
+
+  cmt_string full_name;
+
+  if (path_index == 1)
+    {
+      full_name = dir_name;
+      full_name += CmtSystem::file_separator ();
+
+      if (current_path_index >= 2)
+        {
+          full_name.replace (include_paths[current_path_index - 2],
+                             substitutions[current_path_index - 2]);
+        }
+    }
+  else if (path_index > 1)
+    {
+      full_name  = substitutions[path_index - 2];
+      full_name += CmtSystem::file_separator ();
+    }
+
+  full_name += header_file;
+
+  deps.push_back (full_name);
 }
 
@@ -115,4 +166,5 @@
                               const CmtSystem::cmt_string_vector& include_paths,
                               const CmtSystem::cmt_string_vector& substitutions,
+                              const DepsBuilder::HeaderFilters& header_filters,
                               CmtSystem::cmt_string_vector& all_deps,
                               CmtSystem::cmt_string_vector& deps)
@@ -229,4 +281,5 @@
                       include_paths,
                       substitutions,
+                      header_filters,
                       all_deps,
                       deps);
@@ -470,4 +523,5 @@
 			     const CmtSystem::cmt_string_vector& include_paths,
 			     const CmtSystem::cmt_string_vector& substitutions,
+                             const DepsBuilder::HeaderFilters& header_filters,
 			     CmtSystem::cmt_string_vector& all_deps,
 			     CmtSystem::cmt_string_vector& deps)
@@ -481,5 +535,4 @@
   log << "CMT> build_deps_text dir_name="
       << dir_name << log_endl;
-
 
   // erase of continuation character
@@ -487,35 +540,38 @@
   max_pos = strlen (text);
   char* current = text;
+
   char* last = text + max_pos;
   while (current < last)
     {
    
-      char* crnl = strstr (current, "\\\r\n");
-      char* nl   = strstr (current, "\\\n");
+      //  bscrnl -> BackSlash Carriage Return New Line
+      //  bsnl -> BackSlash New Line
+      char* bscrnl = strstr (current, "\\\r\n");
+      char* bsnl   = strstr (current, "\\\n");
       
-      if ( (crnl==0) && (nl ==0)) break;
+      if ( (bscrnl==0) && (bsnl ==0)) break;
       
       int length = 0;
             
       char * ptr = 0;
-      if (nl==0)  //crnl > 0
+      if (bsnl==0)  //bscrnl > 0
 	{
 	  length = 3;
-	  ptr    = crnl; 
+	  ptr    = bscrnl; 
 	}      
-      else if (crnl==0) //nl > 0
+      else if (bscrnl==0) //bsnl > 0
 	{
 	  length = 2;                        
-	  ptr    = nl; 
+	  ptr    = bsnl; 
 	}     
-      else if (crnl < nl)
+      else if (bscrnl < bsnl)
 	{
 	  length = 3;
-	  ptr    = crnl;                 
+	  ptr    = bscrnl;                 
 	}
-      else // (crnl > nl)
+      else // (bscrnl > bsnl)
 	{
 	  length = 2;                        
-	  ptr    = nl;         
+	  ptr    = bsnl;         
 	}
       strcpy (ptr, ptr+length);
@@ -538,4 +594,6 @@
       char* marker_pos = 0;
 
+      //  crnl -> Carriage Return New Line
+      //  nl -> New Line
       char* crnl = strstr (current, "\r\n");
       char* nl = strchr (current, '\n');
@@ -598,4 +656,5 @@
 				     include_paths,
 				     substitutions,
+                                     header_filters,
 				     all_deps,
 				     deps);
@@ -647,4 +706,5 @@
                        const CmtSystem::cmt_string_vector& include_paths,
                        const CmtSystem::cmt_string_vector& substitutions,
+                       const DepsBuilder::HeaderFilters& header_filters,
                        CmtSystem::cmt_string_vector& all_deps,
                        CmtSystem::cmt_string_vector& deps)
@@ -652,8 +712,52 @@
   Log;
 
-  int result = -1;
-  cmt_string new_dir;
-
   log << "CMT> build_deps name=" << name << " dir_name=" 
+      << dir_name << log_endl;
+
+  cmt_string full_name;
+  int path_index = locate (name,
+                           dir_name,
+                           include_paths,
+                           substitutions,
+                           full_name);
+
+  if (path_index >= 0)
+    {
+      cmt_string text;
+      text.read (full_name);
+      char* ptr = &text[0];
+      cmt_string new_dir;
+      CmtSystem::dirname (full_name, new_dir);
+
+      if (path_index == 0 || path_index == 1)
+        build_deps_text (ptr, new_dir,
+                         current_path_index,
+                         include_paths, substitutions,
+                         header_filters,
+                         all_deps, deps);
+      else
+        build_deps_text (ptr, new_dir,
+                         path_index,
+                         include_paths, substitutions,
+                         header_filters,
+                         all_deps, deps);
+    }
+  if (path_index < 0)
+    {
+      log << "CMT> build_deps3" << log_endl;
+    }
+  return path_index;
+}
+
+//--------------------------------------------------
+static int locate (const cmt_string& name,
+                   const cmt_string& dir_name,
+                   const CmtSystem::cmt_string_vector& include_paths,
+                   const CmtSystem::cmt_string_vector& substitutions,
+                   cmt_string& full_name)
+{
+  Log;
+
+  log << "CMT> locate name=" << name << " dir_name=" 
       << dir_name << log_endl;
 
@@ -663,22 +767,9 @@
   if (CmtSystem::test_file (name))
     {
-      cmt_string text;
-
-      text.read (name);
-
-      char* ptr = &text[0];
-      CmtSystem::dirname (name, new_dir);
-
-      build_deps_text (ptr, new_dir, current_path_index,
-		       include_paths, substitutions,
-		       all_deps, deps);
+      full_name = name;
       return (0);
     }
 
-  cmt_string full_name;
-
-  full_name = dir_name;
-  full_name += CmtSystem::file_separator ();
-  full_name += name;
+  cmt_string p;
 
   //
@@ -686,20 +777,12 @@
   // upper level source file
   //
-  if (CmtSystem::test_file (full_name))
-    {
-      cmt_string text;
-
-      text.read (full_name);
-
-      char* ptr = &text[0];
-      CmtSystem::dirname (full_name, new_dir);
-
-      build_deps_text (ptr, new_dir, current_path_index,
-		       include_paths, substitutions,
-		       all_deps, deps);
+  p = dir_name;
+  p += CmtSystem::file_separator ();
+  p += name;
+  if (CmtSystem::test_file (p))
+    {
+      full_name = p;
       return (1);
     }
-
-  int path_index = -1;
 
   //
@@ -707,36 +790,20 @@
   // the include_paths
   //
-  for (path_index = 0; path_index < include_paths.size (); path_index++)
-    {
-      full_name  = include_paths[path_index];
-      full_name += CmtSystem::file_separator ();
-      full_name += name;
-
-      log << "CMT> build_deps2 full_name=" << full_name << log_endl;
-
-      if (CmtSystem::test_file (full_name))
-        {
-	  cmt_string text;
-
-	  text.read (full_name);
-
-	  char* ptr = &text[0];
-	  CmtSystem::dirname (full_name, new_dir);
-
-	  log << "CMT> build_deps3 new_dir=" << new_dir << log_endl;
-
-	  build_deps_text (ptr,
-			   new_dir,
-			   path_index + 2,
-			   include_paths,
-			   substitutions,
-			   all_deps,
-			   deps);
-
+  for (int path_index = 0; path_index < include_paths.size (); path_index++)
+    {
+      p  = include_paths[path_index];
+      p += CmtSystem::file_separator ();
+      p += name;
+
+      log << "CMT> locate2 full_name=" << p << log_endl;
+
+      if (CmtSystem::test_file (p))
+        {
+          full_name = p;
 	  return (path_index + 2);
         }
     }
 
-  log << "CMT> build_deps3" << log_endl;
+  log << "CMT> locate3" << log_endl;
 
   return (-1);
@@ -748,4 +815,9 @@
   m_include_paths.clear ();
   m_substitutions.clear ();
+  for (int i = m_header_filters.size () - 1; i >= 0; i--)
+    {
+      m_header_filters[i].clear ();
+    }
+  m_header_filters.clear ();
 }
 
@@ -753,4 +825,8 @@
 void DepsBuilder::add (const cmt_string& path, const cmt_string& substitution)
 {
+  if (path.size () == 0)
+    {
+      return;
+    }
   if (path[path.size () - 1] == CmtSystem::file_separator ())
     {
@@ -849,5 +925,4 @@
   log << "Starting deps builder on " << file_name << log_endl;
 
-
   m_deps.clear ();
   m_all_deps.clear ();
@@ -875,4 +950,5 @@
                   m_include_paths,
                   m_substitutions,
+                  m_header_filters,
                   m_all_deps,
                   m_deps);
@@ -964,2 +1040,13 @@
 }
 
+//--------------------------------------------------------------------------
+void DepsBuilder::add_header_filter (const Use* use, const cmt_regexp* filter, const cmt_string& stamp)
+{
+  add_header_filter (HeaderFilter (use, filter, stamp));
+}
+
+//--------------------------------------------------------------------------
+void DepsBuilder::add_header_filter (const HeaderFilter& hf)
+{
+  m_header_filters.push_back (hf);
+}
Index: /CMT/HEAD/source/cmt_deps_builder.h
===================================================================
--- /CMT/HEAD/source/cmt_deps_builder.h	(revision 426)
+++ /CMT/HEAD/source/cmt_deps_builder.h	(revision 427)
@@ -10,4 +10,5 @@
 #include "cmt.h"
 #include "cmt_system.h"
+#include "cmt_use.h"
 
 class DepsBuilder
@@ -15,13 +16,58 @@
 public:
 
+  class HeaderFilter
+  {
+  public:
+
+    HeaderFilter ()
+      : m_use (0), m_filter (0) { }
+
+    HeaderFilter (const Use* use, const cmt_regexp* filter, const cmt_string& stamp)
+      : m_use (use), m_filter (filter), m_stamp (stamp) { }
+
+    ~HeaderFilter ()
+      { }
+
+    inline const Use* use () const
+      { return m_use; }
+
+    inline bool use_stamp (const cmt_string& header, cmt_string& stamp) const
+      { return m_filter->match (header) ? stamp = m_stamp, true : false ; }
+
+    void clear ()
+      {
+        m_use = 0;
+        if (m_filter) delete m_filter;
+        m_filter = 0;
+        m_stamp = cmt_string (); 
+      }
+
+  private:
+
+    const Use* m_use;
+    const cmt_regexp* m_filter;
+    cmt_string m_stamp;
+  };
+
+  typedef cmt_vector<HeaderFilter> HeaderFilters;
+
   void clear ();
   void add (const cmt_string& path, const cmt_string& substitution);
   void add_includes (const Use& use);
+  void add_header_filter (const Use* use, const cmt_regexp* filter, const cmt_string& stamp);
+  void add_header_filter (const HeaderFilter& hf);
   CmtSystem::cmt_string_vector& run (const cmt_string& file_name);
+
+  DepsBuilder ()
+    { }
 
 private:
 
+  DepsBuilder (const DepsBuilder&)
+    { }
+
   CmtSystem::cmt_string_vector m_include_paths;
   CmtSystem::cmt_string_vector m_substitutions;
+  HeaderFilters m_header_filters;
 
   CmtSystem::cmt_string_vector m_deps;
Index: /CMT/HEAD/source/cmt_generators.cxx
===================================================================
--- /CMT/HEAD/source/cmt_generators.cxx	(revision 426)
+++ /CMT/HEAD/source/cmt_generators.cxx	(revision 427)
@@ -2619,9 +2619,10 @@
 };
 
-
 void DependencyGenerator::build (const CmtSystem::cmt_string_vector& arguments)
 {
   reset ();
   prepare_use_context ();
+
+  prepare_header_file_filters ();
 
   m_stamps = true;
@@ -2841,4 +2842,6 @@
       fclose (f);
     }
+
+//  m_deps_builder.clear ();
 }
 
@@ -2998,2 +3001,45 @@
 }
 
+//--------------------------------------------------
+void DependencyGenerator::prepare_header_file_filters ()
+{
+  Use::UsePtrVector& uses = Use::get_ordered_uses ();
+  uses.push_back (&Use::current ());
+  for (int i = uses.size () - 1; i >= 0; i--)
+    {
+      Use* use = uses[i];
+      if (use->discarded) continue;
+      if (use->m_hidden) continue;
+      if (!use->located ()) continue;
+
+      cmt_string package_name = use->get_package_name ();
+      if (package_name == "CMT") continue;
+
+      Symbol* filter_macro = Symbol::find (package_name + "_header_file_filter");
+      if (filter_macro == 0) continue;
+
+      Symbol* stamp_macro = Symbol::find (package_name + "_header_file_stamp");
+      cmt_string stamp;
+      if (stamp_macro != 0)
+        {
+          stamp = stamp_macro->resolve_macro_value ();
+        }
+      else
+        {
+          use->get_full_path (stamp);
+          stamp += CmtSystem::file_separator ();
+          if (use->style == mgr_style) stamp += "mgr";
+          else stamp += "cmt";
+          stamp += CmtSystem::file_separator ();
+          stamp += "cmt_header_file.stamp";
+          //stamp += "cmt_all_headers.stamp";
+          //<package>/cmt/cmt_all_headers.stamp
+        }
+      if (!CmtSystem::test_file (stamp)) continue;
+
+      cmt_regexp* filter = new cmt_regexp (filter_macro->resolve_macro_value ());
+      assert (filter != 0);
+
+      m_deps_builder.add_header_filter (use, filter, stamp);
+    }
+}
Index: /CMT/HEAD/source/cmt_generators.h
===================================================================
--- /CMT/HEAD/source/cmt_generators.h	(revision 426)
+++ /CMT/HEAD/source/cmt_generators.h	(revision 427)
@@ -213,5 +213,6 @@
 public:
   void build (const CmtSystem::cmt_string_vector& arguments);
-
+  void prepare_header_file_filters ();
+ 
 private:
   void add_line_to_text (const cmt_string& line, cmt_string& text);
