Index: CMT/HEAD/source/cmt_use.cxx
===================================================================
--- CMT/HEAD/source/cmt_use.cxx	(revision 280)
+++ CMT/HEAD/source/cmt_use.cxx	(revision 290)
@@ -35,6 +35,7 @@
 
 static bool add_request (const cmt_string& path,
-			 const cmt_string& package_name,
-			 const cmt_string& version)
+			             const cmt_string& package_name,
+			             const cmt_string& version,
+			             const cmt_string& native_version)
 {
   static cmt_map <cmt_string, bool> requests;
@@ -44,4 +45,6 @@
   request += version;
   request += " ";
+  request += native_version;
+  request += " ";  
   request += path;
   static bool b = true;
@@ -108,5 +111,5 @@
 {
 public:
-  Use* operate (Use* ref_use, Use* new_use);
+  Use* operate (Use* ref_use, Use* new_use, const cmt_string& native_version);
 };
 
@@ -134,4 +137,5 @@
 static CompareStatus compare_versions (const cmt_string& ref_version, const cmt_string& new_version)
 {
+  
   CompareStatus result = IdenticalIds;
 
@@ -147,4 +151,8 @@
 
   CmtSystem::is_version_directory (new_version, new_v, new_r, new_p);
+	  cout << "#1 Required version " << new_version <<
+	    " incompatible with selected version " << ref_version <<
+	    endl;
+
 
   if ((new_v != -1) && (old_v != -1) && (new_v != old_v))
@@ -746,6 +754,6 @@
           {
             cout << "about to add " << package << endl;
-	    show_packages ();
-	  }
+	        show_packages ();
+	      }
 
         /// Now do create or retreive the Use object.
@@ -1424,7 +1432,7 @@
 
 //----------------------------------------------------------
-int Use::reach_package (const cmt_string& from_path)
-{
-  if (Cmt::get_debug ())
+int Use::reach_package (const cmt_string& from_path, const cmt_string& n_version)
+{
+    if (Cmt::get_debug ())
     {
       cout << "Use::reach_package> (" << get_package_name () << " " 
@@ -1583,6 +1591,5 @@
       // There are alternate possibilities when it contains wild cards
       //
-      if ((version == "") ||
-          (version.find ("*") != cmt_string::npos))
+      if ((version == "") || (version.find ("*") != cmt_string::npos))
         {
           static CmtSystem::cmt_string_vector versions;
@@ -1594,5 +1601,43 @@
           else name += version;
 
-          CmtSystem::scan_dir (name, versions);
+          CmtSystem::scan_dir (name, versions);     
+          if (n_version != "")
+          {
+              static CmtSystem::cmt_string_vector native_versions;           
+              for (int i = 0; i < versions.size (); i++)
+              {
+                  cmt_string path;
+                  if (CmtSystem::test_directory (versions[i]))
+                  {
+                      path  = versions[i];
+                      path += CmtSystem::file_separator ();
+                      path += "cmt";
+                  }
+                  else
+                  {
+                      path = "cmt";
+                  }
+                  path += CmtSystem::file_separator ();
+                  path += "native_version.cmt";        
+                                  
+                  if (CmtSystem::test_file (path))
+	              {
+	                  cmt_string nv;
+	                  nv.read (path);
+	                  int pos;
+	                  pos = nv.find ('\n');
+	                  if (pos != cmt_string::npos) nv.erase (pos);
+	                  pos = nv.find ('\r');
+	                  if (pos != cmt_string::npos) nv.erase (pos);
+	              
+	                  if (nv == n_version)
+	                  {
+	                       cmt_string& name_entry = native_versions.add ();
+	                       name_entry += versions[i];
+	                  }
+	              }                   
+              }
+              versions = native_versions;
+          }
           
           int i;
@@ -1616,4 +1661,5 @@
               if (CmtSystem::is_version_directory (name, v, r, p))
                 {
+           
                   /*
                     This check is not sufficient !! We need to check in addition
@@ -1623,5 +1669,4 @@
 
                   cmt_string req;
-
                   req = name;
                   req += CmtSystem::file_separator ();
@@ -1711,6 +1756,7 @@
 {
 public:
-  UseProjectAction (Use* use) : m_use (use), m_found (false)
+  UseProjectAction (Use* use, const cmt_string& n_version="") : m_use (use), m_found (false)
   {
+      m_n_version = n_version;
   }
 
@@ -1727,5 +1773,5 @@
     m_use->alternate_paths.clear ();
 
-    if (m_use->reach_package (path))
+    if (m_use->reach_package (path, m_n_version))
       {
 	if (Cmt::get_debug ())
@@ -1760,9 +1806,10 @@
 private:
   Use* m_use;
+  cmt_string m_n_version;
   bool m_found;
 };
 
 //----------------------------------------------------------
-bool Use::move_to ()
+bool Use::move_to (const cmt_string& native_version)
 {
   if (m_located)
@@ -1778,5 +1825,5 @@
         }
 
-      reach_package (real_path);
+      reach_package (real_path, native_version);
 
       return (true);
@@ -1790,5 +1837,5 @@
   if (expanded_path == "")
     {
-      if (reach_package (""))
+      if (reach_package ("", native_version))
         {
           if (Cmt::get_debug ())
@@ -1821,5 +1868,5 @@
   if (CmtSystem::absolute_path (expanded_path))
     {
-      if (reach_package (expanded_path))
+      if (reach_package (expanded_path, native_version))
         {
           if (Cmt::get_debug ())
@@ -1849,6 +1896,5 @@
   // Second try is among the CMTPATHs
   //
-      
-  UseProjectAction pa (this);
+  UseProjectAction pa (this, native_version);
 
   Project::broadcast (pa);
@@ -1929,5 +1975,5 @@
         {
           version = alternate_versions[selected_index];
-          if (reach_package (alternate_paths[selected_index]))
+          if (reach_package (alternate_paths[selected_index], native_version))
             {
                 /*
@@ -1958,8 +2004,9 @@
                     const cmt_string& package,
                     const cmt_string& version,
+                    const cmt_string& native_version,                    
                     Use** old_use,
-		    Use* context_use)
-{
-  bool new_request = add_request (path, package, version);
+     		        Use* context_use)
+{
+  bool new_request = add_request (path, package, version, native_version);
 
   Use& current_use = Use::current ();
@@ -1976,11 +2023,10 @@
     }
 
-  Package* p = Package::add (package);
-
+  Package* p         = Package::add (package);
   UsePtrVector& uses = p->get_uses ();
 
   bool do_need_new = true;
-  Use* found = 0;
-  Use* registered = 0;
+  Use* found       = 0;
+  Use* registered  = 0;
 
   int req_v = -1;
@@ -2061,5 +2107,4 @@
 		       << endl;
 		}
-
 	      // The registered use loses against the request
 	    }
@@ -2100,4 +2145,6 @@
 	    }
 	}
+
+	  
 
       if (Cmt::get_debug ())
@@ -2156,6 +2203,5 @@
 		  cout << "  ... requested wildcarded loses against existing explicit" << endl;
 		}
-	      
-	      do_need_new = false; // We don't need a new one
+	   	      do_need_new = false; // We don't need a new one
 	    }
 	  else
@@ -2163,6 +2209,5 @@
 	      // here either !has_wild_card or use_has_wild_card
 	  
-	      if ((version == use.specified_version) &&
-		  (path == use.specified_path))
+	      if ((version == use.specified_version) && (path == use.specified_path))
 		{
 		  if (Cmt::get_debug ())
@@ -2320,6 +2365,6 @@
   Use* use = 0;
 
-  do_need_new = need_new (path, package_name, version, &old_use, context_use);
-  // cout <<"native_version: "<<native_version<<" "<<version<<endl;
+  do_need_new = need_new (path, package_name, version, native_version, &old_use, context_use);
+  //cout <<"native_version: "<<native_version<<" "<<version<<" "<<do_need_new<<endl;
     
 
@@ -2338,4 +2383,5 @@
     {
       use = create (path, package_name, version, version_alias, path_alias);
+      //cout <<"need_new native_version: "<<native_version<<" "<<version<<" "<<do_need_new<<endl;
     }
   else
@@ -2412,5 +2458,6 @@
    *         we have created a new Use (which has to be validated)
    */
-  bool found = use->move_to ();
+  bool found = use->move_to (native_version);
+
 
   if (Cmt::get_debug ())
@@ -2480,5 +2527,5 @@
           if (use != 0) use->discard ();
           use = old_use;
-          found = use->move_to ();
+          found = use->move_to (native_version);
         }
       else
@@ -2488,6 +2535,6 @@
             // thus we have to choose
             //
-	  static BestFitSelector selector;
-          Use* selected_use = selector.operate (old_use, use);
+	      static BestFitSelector selector;
+          Use* selected_use = selector.operate (old_use, use, native_version);
 
 	  if (Cmt::get_debug ())
@@ -2505,5 +2552,5 @@
           if (use != selected_use) 
             {
-	      use = use->set_selected_version (selected_use);
+	             use = use->set_selected_version (selected_use);
             }
           
@@ -2511,6 +2558,7 @@
           /*
            *   current directory is moved to the selected one
-           */
-          found = use->move_to ();
+           */        
+          found = use->move_to (native_version);
+
         }
     }
@@ -3868,6 +3916,7 @@
 //
 //----------------------------------------------------------
-Use* BestFitSelector::operate (Use* ref_use, Use* new_use)
-{
+Use* BestFitSelector::operate (Use* ref_use, Use* new_use, const cmt_string& native_version)
+{
+    
   Use* selected = ref_use;
 
