Index: CMT/HEAD/ChangeLog
===================================================================
--- CMT/HEAD/ChangeLog	(revision 560)
+++ CMT/HEAD/ChangeLog	(revision 561)
@@ -1,2 +1,66 @@
+2011-03-07    <rybkin@lal.in2p3.fr> 444
+
+	* source/cmt_system.cxx: In class CmtSystem, introduce function quote
+	* source/cmt_system.h: idem
+	* source/cmt_fragment.cxx: In class fragment_action_iterator, function
+	add_word, ensure that header, trailer fragments are overridden, if declared
+	again, introduce, parse and set for current use fragment m_path. In class
+	Fragment, in function add, introduce argument path, in function print
+	introduce PrintMode, ostream arguments and add implementation for
+	Requirements mode, in function locate, optimise fragment search, add
+	warning, if not found. In class FragmentHandle, in functions copy do not
+	print info message about not found fragment, in function setup make such
+	message warning
+	* source/cmt_fragment.h: idem
+	* source/cmt_constituent.cxx: In class Constituent, in function show
+	introduce argument ostream, make use of class CmtSystem function quote
+	* source/cmt_constituent.h: idem
+	* source/cmt_language.cxx: In class Language, introduce members m_use,
+	m_dependencies_options_expanded, function dependencies_options_expanded, in
+	function show, introduce PrintMode, ostream arguments and add
+	implementation for Requirements mode, in function action, introduce
+	argument Use*
+	* source/cmt_language.h: idem
+	* source/cmt_syntax.cxx: Make use of modified class Language function action
+	* source/cmt_symbol.cxx: Remove helper function quote
+	* source/cmt.h: In class CmtContext, introduce member m_use_cmt, in class
+	Cmt, function use_extra_file
+	* source/cmt_generators.h: In class ConstituentsMakefileGenerator function
+	build use package, and file arguments only
+	* source/cmt_generators.cxx: In class LibraryGenerator, in function,
+	java_file_action do not test for output file existence, in function build,
+	do not invoke function prepare_use_context. In class DocumentGenerator, in
+	function build, do not invoke function filter_path, prepare_use_context,
+	get_all_files for second time, do not check for existence of source file or
+	issue warning (done in function analyze_file), in function analyze_file, do
+	not define variable output_dir. In class ConstituentsMakefileGenerator
+	function build, use file argument rather than parse string vector
+	* source/cmt_generator.h: Introduce class InGenerator, in class Generator
+	function build_constituents_makefile, use file argument rather than string
+	vector, introduce function build_constituent_infile
+	* source/cmt_generator.cxx: Implement introduced class and function in
+	order to generate input constituent requirements file
+	* source/cmt_commands.h: Introduce global options -with_cmt, -without_cmt
+	* source/cmt_commands.cxx: Implement options -with_cmt, -without_cmt,
+	global and for commands "build constituent makefile", "build constituents
+	config", enhance options parsing for commands "build constituent(s)
+	makefile/config", improve error handling, diagnostic and help messages
+	* source/cmt_parser.cxx: Enhance options parsing and error handling in Cmt
+	class functions	do_build_constituent(s)_makefile,
+	do_build_constituent(s)_config, generate input requirements file for
+	constituent(s) without associated tag in function
+	do_build_constituents_config. In function parser, handle help requests
+	immediately after parse_arguments, do not use CMT if requested, use extra
+	file instead of requirements, if specified, via implemented function
+	use_extra_file
+	* mgr/fragments/constituent: Generate constituent Makefile from input
+	requirements file (with -f, -without_cmt options) for constituent without
+	associated tag
+	* mgr/fragments/constituent_lock: idem
+	* mgr/cmt_make_shlib_common.sh: Improve error handling, unset CMTDEBUG if
+	set in order to avoid debug output interference with script
+	* mgr/cmt_install_action.sh: idem
+	* mgr/requirements: Do not declare readme_doc fragment (not provided)
+	
 2010-09-07    <rybkin@lal.in2p3.fr> 443
 
Index: CMT/HEAD/mgr/cmt_install_action.sh
===================================================================
--- CMT/HEAD/mgr/cmt_install_action.sh	(revision 560)
+++ CMT/HEAD/mgr/cmt_install_action.sh	(revision 561)
@@ -110,6 +110,10 @@
     
   if test "${cmtpath}" = ""; then
-    package=`cmt show macro_value package`
-    cmtpath=`cmt show macro_value ${package}_cmtpath`
+    if [ "${CMTDEBUG:-}" ]; then
+      unset CMTDEBUG
+      set -x
+    fi
+    package=`cmt show macro_value package` || exit
+    cmtpath=`cmt show macro_value ${package}_cmtpath` || exit
   fi
 
Index: CMT/HEAD/mgr/cmt_make_shlib_common.sh
===================================================================
--- CMT/HEAD/mgr/cmt_make_shlib_common.sh	(revision 560)
+++ CMT/HEAD/mgr/cmt_make_shlib_common.sh	(revision 561)
@@ -29,9 +29,14 @@
 extra=$*
 
-ld=`${CMTROOT}/mgr/cmt show macro_value shlibbuilder -tag=${tag}`
-ldflags=`${CMTROOT}/mgr/cmt show macro_value shlibflags -tag=${tag}`
-suffix=`${CMTROOT}/mgr/cmt show macro_value shlibsuffix -tag=${tag}`
-libprefix=`${CMTROOT}/mgr/cmt show macro_value library_prefix -tag=${tag}`
-libsuffix=`${CMTROOT}/mgr/cmt show macro_value library_suffix -tag=${tag}`
+if [ "${CMTDEBUG:-}" ]; then
+unset CMTDEBUG
+set -x
+fi
+
+ld=`${CMTROOT}/mgr/cmt show macro_value shlibbuilder -tag=${tag}` || exit
+ldflags=`${CMTROOT}/mgr/cmt show macro_value shlibflags -tag=${tag}` || exit
+suffix=`${CMTROOT}/mgr/cmt show macro_value shlibsuffix -tag=${tag}` || exit
+libprefix=`${CMTROOT}/mgr/cmt show macro_value library_prefix -tag=${tag}` || exit
+libsuffix=`${CMTROOT}/mgr/cmt show macro_value library_suffix -tag=${tag}` || exit
 
 libname=${libprefix}${lib}${libsuffix}
@@ -42,11 +47,11 @@
 
 if test "${bin}" = "" ; then
-  bin=`${CMTROOT}/mgr/cmt show macro_value bin -tag=${tag}`
+  bin=`${CMTROOT}/mgr/cmt show macro_value bin -tag=${tag}` || exit
 fi
 
 here=`/bin/pwd`
-cd ${bin}
+cd ${bin} || exit
 
-/bin/rm -f ${libname}.${suffix}
+/bin/rm -f ${libname}.${suffix} || exit
 
 result=0
@@ -61,4 +66,10 @@
 
   (cd ${temp_shlib}; ar x ../${libname}.a)
+  result=$?
+  if [ ${result} -ne 0 ]; then
+      \rm -rf ${temp_shlib}
+      cd ${here}
+      exit ${result}
+  fi
 
   #
Index: CMT/HEAD/mgr/fragments/constituent
===================================================================
--- CMT/HEAD/mgr/fragments/constituent	(revision 560)
+++ CMT/HEAD/mgr/fragments/constituent	(revision 561)
@@ -66,14 +66,12 @@
 #endif
 
-makefiles : $(cmt_local_${CONSTITUENT}_makefile)
+ifdef cmt_${CONSTITUENT}_has_target_tag
 
 ifndef QUICK
 $(cmt_local_${CONSTITUENT}_makefile) : $(${CONSTITUENT}_dependencies) build_library_links
-#$(cmt_local_${CONSTITUENT}_makefile) : $(${CONSTITUENT}_dependencies) $(cmt_local_tagfile_${CONSTITUENT}) build_library_links
 	$(echo) "(constituents.make) Building ${CONSTITUENT}.make"; \
 	  $(cmtexe) -tag=$(tags) $(${CONSTITUENT}_extratags) build constituent_config -out=$(cmt_local_${CONSTITUENT}_makefile) ${CONSTITUENT}
 else
 $(cmt_local_${CONSTITUENT}_makefile) : $(${CONSTITUENT}_dependencies)
-#$(cmt_local_${CONSTITUENT}_makefile) : $(cmt_local_tagfile_${CONSTITUENT})
 	if [ ! -f $@ ] || [ ! -f $(cmt_local_tagfile_${CONSTITUENT}) ] || \
 	  [ ! -f $(cmt_final_setup_${CONSTITUENT}) ]; then \
@@ -82,4 +80,22 @@
 	  $(cmtexe) -tag=$(tags) $(${CONSTITUENT}_extratags) build constituent_config -out=$(cmt_local_${CONSTITUENT}_makefile) ${CONSTITUENT}; \
 	  fi
+endif
+
+else
+
+ifndef QUICK
+$(cmt_local_${CONSTITUENT}_makefile) : $(${CONSTITUENT}_dependencies) build_library_links
+	$(echo) "(constituents.make) Building ${CONSTITUENT}.make"; \
+	  $(cmtexe) -f=$(bin)${CONSTITUENT}.in -tag=$(tags) $(${CONSTITUENT}_extratags) build constituent_makefile -without_cmt -out=$(cmt_local_${CONSTITUENT}_makefile) ${CONSTITUENT}
+else
+$(cmt_local_${CONSTITUENT}_makefile) : $(${CONSTITUENT}_dependencies)
+	if [ ! -f $@ ] || [ ! -f $(cmt_local_tagfile_${CONSTITUENT}) ] || \
+	  [ ! -f $(cmt_final_setup_${CONSTITUENT}) ]; then \
+	  test -z "$(cmtmsg)" || \
+	  echo "$(CMTMSGPREFIX)" "(constituents.make) Building ${CONSTITUENT}.make"; \
+	  $(cmtexe) -f=$(bin)${CONSTITUENT}.in -tag=$(tags) $(${CONSTITUENT}_extratags) build constituent_makefile -without_cmt -out=$(cmt_local_${CONSTITUENT}_makefile) ${CONSTITUENT}; \
+	  fi
+endif
+
 endif
 
Index: CMT/HEAD/mgr/fragments/constituent_lock
===================================================================
--- CMT/HEAD/mgr/fragments/constituent_lock	(revision 560)
+++ CMT/HEAD/mgr/fragments/constituent_lock	(revision 561)
@@ -66,14 +66,12 @@
 #endif
 
-makefiles : $(cmt_local_${CONSTITUENT}_makefile)
+ifdef cmt_${CONSTITUENT}_has_target_tag
 
 ifndef QUICK
 $(cmt_local_${CONSTITUENT}_makefile) : $(${CONSTITUENT}_dependencies) build_library_links
-#$(cmt_local_${CONSTITUENT}_makefile) : $(${CONSTITUENT}_dependencies) $(cmt_local_tagfile_${CONSTITUENT}) build_library_links
 	$(echo) "(constituents.make) Building ${CONSTITUENT}.make"; \
 	  $(cmtexe) -tag=$(tags) $(${CONSTITUENT}_extratags) build constituent_config -out=$(cmt_local_${CONSTITUENT}_makefile) ${CONSTITUENT}
 else
 $(cmt_local_${CONSTITUENT}_makefile) : $(${CONSTITUENT}_dependencies)
-#$(cmt_local_${CONSTITUENT}_makefile) : $(cmt_local_tagfile_${CONSTITUENT})
 	if [ ! -f $@ ] || [ ! -f $(cmt_local_tagfile_${CONSTITUENT}) ] || \
 	  [ ! -f $(cmt_final_setup_${CONSTITUENT}) ]; then \
@@ -82,4 +80,22 @@
 	  $(cmtexe) -tag=$(tags) $(${CONSTITUENT}_extratags) build constituent_config -out=$(cmt_local_${CONSTITUENT}_makefile) ${CONSTITUENT}; \
 	  fi
+endif
+
+else
+
+ifndef QUICK
+$(cmt_local_${CONSTITUENT}_makefile) : $(${CONSTITUENT}_dependencies) build_library_links
+	$(echo) "(constituents.make) Building ${CONSTITUENT}.make"; \
+	  $(cmtexe) -f=$(bin)${CONSTITUENT}.in -tag=$(tags) $(${CONSTITUENT}_extratags) build constituent_makefile -without_cmt -out=$(cmt_local_${CONSTITUENT}_makefile) ${CONSTITUENT}
+else
+$(cmt_local_${CONSTITUENT}_makefile) : $(${CONSTITUENT}_dependencies)
+	if [ ! -f $@ ] || [ ! -f $(cmt_local_tagfile_${CONSTITUENT}) ] || \
+	  [ ! -f $(cmt_final_setup_${CONSTITUENT}) ]; then \
+	  test -z "$(cmtmsg)" || \
+	  echo "$(CMTMSGPREFIX)" "(constituents.make) Building ${CONSTITUENT}.make"; \
+	  $(cmtexe) -f=$(bin)${CONSTITUENT}.in -tag=$(tags) $(${CONSTITUENT}_extratags) build constituent_makefile -without_cmt -out=$(cmt_local_${CONSTITUENT}_makefile) ${CONSTITUENT}; \
+	  fi
+endif
+
 endif
 
Index: CMT/HEAD/mgr/requirements
===================================================================
--- CMT/HEAD/mgr/requirements	(revision 560)
+++ CMT/HEAD/mgr/requirements	(revision 561)
@@ -593,5 +593,5 @@
 make_fragment readme_header
 make_fragment readme
-make_fragment readme_doc
+#make_fragment readme_doc
 make_fragment readme_use
 make_fragment readme_trailer
Index: CMT/HEAD/source/cmt.h
===================================================================
--- CMT/HEAD/source/cmt.h	(revision 560)
+++ CMT/HEAD/source/cmt.h	(revision 561)
@@ -33,4 +33,5 @@
   cmt_string m_cmt_site;
   cmt_string m_cmt_version;
+  bool m_use_cmt;
   
   cmt_string m_current_dir;
@@ -263,4 +264,5 @@
   static void print_xml_prolog (const cmt_string& root = "cmt", ostream& out = cout);
   static int reach_current_package ();
+  static int use_extra_file (const cmt_string& file);
   static void restore_all_tags (Use* use);
   static void set_current_access (AccessMode mode);
Index: CMT/HEAD/source/cmt_commands.cxx
===================================================================
--- CMT/HEAD/source/cmt_commands.cxx	(revision 560)
+++ CMT/HEAD/source/cmt_commands.cxx	(revision 561)
@@ -337,4 +337,14 @@
   pv.push_back (&ArgParser::option_version); i++;
 
+  parsers.add ("-with_c", i);
+  parsers.add ("-with_cm", i);
+  parsers.add ("-with_cmt", i);
+  pv.push_back (&ArgParser::option_with_cmt); i++;
+
+  parsers.add ("-without_c", i);
+  parsers.add ("-without_cm", i);
+  parsers.add ("-without_cmt", i);
+  pv.push_back (&ArgParser::option_without_cmt); i++;
+
   parsers.add ("-warn", i);
   parsers.add ("-warni", i);
@@ -520,5 +530,6 @@
 	  // We have unexpected arguments (not handled by the command handler). This may sign 
 	  // an unprotected handler implementation.
-	  CmtMessage::warning ("unexpected parameter " + reduced_arg);
+	  if (help_action != action_help)
+	    CmtMessage::warning ("unexpected parameter " + reduced_arg);
 	  //	  if (!cmt.m_quiet) cerr << "#CMT> warning : unexpected parameter " << reduced_arg << endl;
 	}
@@ -577,63 +588,109 @@
       if (arg == "constituent_makefile")
 	{
-	  //	  if (argc > 0)
-	  if (argc == 1 || (argc == 2 && cmt_string (argv[0]).substr (0, 5) == "-out="))
-	    {
-	      //fill_one_argument ();
-	      fill_arguments ();
-	      cmt.m_action = action_build_constituent_makefile;
-	    }
-	  else if (argc > 0)
-	    {
-	      CmtMessage::error ("syntax: wrong arguments");
-//	      if (!cmt.m_quiet) cerr << "#CMT> syntax error : wrong arguments" << endl;
-	      cmt.m_action = action_build_constituent_makefile;
+	  cmt.m_action = action_build_constituent_makefile;
+	  bool need_name (true);
+	  while (argc > 0)
+	    {
+	      cmt_string arg(argv[0]);
+	      if (arg.substr (0, 5) == "-out=")
+		{
+		  fill_one_argument ();
+		}
+	      else if (arg == "-with_cmt")
+		{
+		  shift ();
+		  cmt.m_use_cmt = true;
+		}
+	      else if (arg == "-without_cmt")
+		{
+		  shift ();
+		  cmt.m_use_cmt = false;
+		}
+	      else if (need_name && arg != "")
+		{
+		  need_name = false;
+		  fill_one_argument ();
+		}
+	      else
+		{
+		  help_action = action_help;
+		  CmtError::set (CmtError::syntax_error, arg + ": wrong argument");
+		  break;
+		}
+	    }
+	  if (need_name)
+	    {
 	      help_action = action_help;
-	    }
-	  else
-	    {
-	      CmtMessage::error ("syntax: constituent name missing");
-	      //	      if (!cmt.m_quiet) cerr << "#CMT> syntax error : constituent name missing" << endl;
-	      cmt.m_action = action_build_constituent_makefile;
+	      if (!CmtError::has_pending_error ())
+		CmtError::set (CmtError::syntax_error, "argument(s) missing");
+	    }
+	}
+      else if (arg == "constituent_config")
+	{
+	  cmt.m_action = action_build_constituent_config;
+	  bool need_name (true);
+	  while (argc > 0)
+	    {
+	      cmt_string arg(argv[0]);
+	      if (arg.substr (0, 5) == "-out=")
+		{
+		  fill_one_argument ();
+		}
+	      else if (need_name && arg != "")
+		{
+		  need_name = false;
+		  fill_one_argument ();
+		}
+	      else
+		{
+		  help_action = action_help;
+		  CmtError::set (CmtError::syntax_error, arg + ": wrong argument");
+		  break;
+		}
+	    }
+	  if (need_name)
+	    {
 	      help_action = action_help;
-	    }
-	}
-      else if (arg == "constituent_config")
-	{
-	  //	  if (argc > 0)
-	  if (argc == 1 ||
-	      argc == 2 &&
-	      (cmt_string (argv[0]).substr (0, 5) == "-out=" ||
-	       cmt_string (argv[1]).substr (0, 5) == "-out=")
-	      )
-	    {
-	      //fill_one_argument ();
-	      fill_arguments ();
-	      cmt.m_action = action_build_constituent_config;
-	    }
-	  else if (argc > 0)
-	    {
-	      CmtMessage::error ("syntax: wrong arguments");
-//	      if (!cmt.m_quiet) cerr << "#CMT> syntax error : wrong arguments" << endl;
-	      cmt.m_action = action_build_constituent_config;
-	      help_action = action_help;
-	    }
-	  else
-	    {
-	      CmtMessage::error ("syntax: constituent name missing");
-	      //	      if (!cmt.m_quiet) cerr << "#CMT> syntax error : constituent name missing" << endl;
-	      cmt.m_action = action_build_constituent_config;
-	      help_action = action_help;
+	      if (!CmtError::has_pending_error ())
+		CmtError::set (CmtError::syntax_error, "argument(s) missing");
 	    }
 	}
       else if (arg == "constituents_makefile")
 	{
-	  fill_arguments ();
 	  cmt.m_action = action_build_constituents_makefile;
+	  while (argc > 0)
+	    {
+	      cmt_string arg(argv[0]);
+	      if (arg.substr (0, 5) == "-out=")
+		{
+		  fill_one_argument ();
+		}
+	      else
+		{
+		  help_action = action_help;
+		  CmtError::set (CmtError::syntax_error, arg + ": wrong argument");
+		  break;
+		}
+	    }
 	}
       else if (arg == "constituents_config")
 	{
-	  fill_arguments ();
 	  cmt.m_action = action_build_constituents_config;
+	  while (argc > 0)
+	    {
+	      cmt_string arg(argv[0]);
+	      if (arg.substr (0, 5) == "-out=" ||
+		  arg == "-with_cmt" ||
+		  arg == "-without_cmt")
+		{
+		  fill_one_argument ();
+		}
+	      else
+		{
+		  help_action = action_help;
+		  CmtError::set (CmtError::syntax_error, arg + ": wrong argument");
+		  break;
+		}
+	    }
 	}
       else if (arg == "dependencies")
@@ -759,5 +816,6 @@
       else
 	{
-	  CmtMessage::error ("syntax: wrong build argument");
+	  CmtError::set (CmtError::syntax_error, "wrong argument: " + arg);
+	  //CmtMessage::error ("syntax: wrong build argument: " + arg);
 	  //	  if (!cmt.m_quiet) cerr << "#CMT> syntax error : wrong build argument" << endl;
 	  help_action = action_help;
@@ -767,8 +825,12 @@
   else
     {
-      CmtMessage::error ("syntax: don't know what to build");
+      cmt.m_action = action_build;
+      if (help_action != action_help)
+	{
+	  help_action = action_help;
+	  CmtError::set (CmtError::syntax_error, "argument(s) missing");
+	  //CmtMessage::error ("syntax: don't know what to build");
       //      if (!cmt.m_quiet) cerr << "#CMT> syntax error : don't know what to build" << endl;
-      help_action = action_help;
-      cmt.m_action = action_build;
+	}
     }
 }
@@ -2129,4 +2191,14 @@
 }
 
+void ArgParser::option_with_cmt ()
+{
+  cmt.m_use_cmt = true;
+}
+
+void ArgParser::option_without_cmt ()
+{
+  cmt.m_use_cmt = false;
+}
+
 void ArgParser::option_with_version_directory ()
 {
@@ -2219,5 +2291,5 @@
   cerr << "#   -version=<version>      : set version" << endl;
   cerr << "#   -path=<path>            : set root path" << endl;
-  cerr << "#   -f=<requirement-file>   : set input file" << endl;
+  cerr << "#   -f=<requirements-file>  : set input file" << endl;
   cerr << "#   -e=<statement>          : add a one line statement" << endl;
   cerr << "#   -tag=<tag-list>         : select a new tag-set" << endl;
@@ -2240,4 +2312,6 @@
   if (action == action_build)
     {
+      const cmt_string& s = get_help_text (action);
+      cerr << "# " << s << endl;
       int i;
 
@@ -2248,5 +2322,5 @@
 	}
     }
-  if (action == action_check)
+  else if (action == action_check)
     {
       int i;
@@ -2271,5 +2345,5 @@
     {
       const cmt_string& s = get_help_text (action);
-      cerr << "#" << s << endl;
+      cerr << "# " << s << endl;
     }
 }
@@ -2292,9 +2366,10 @@
   help_texts.add () =  "awk";
   help_texts.add () =  "broadcast [-select=list] [-exclude=list] [-local] [-global] [-begin=pattern] [-depth=n] <command> : apply a command to [some of] the used packages";
-  help_texts.add () =  "build <option>          : build actions. (Try cmt help build)";
-  help_texts.add () =  "build constituent_makefile <constituent>  : generate constituent Makefile fragment";
-  help_texts.add () =  "build constituent_config <constituent>  : generate constituent Makefile fragment, also tag specific Makefile, and setup definitions file, if constituent has associated tag (via -target_tag option, or is action)";
-  help_texts.add () =  "build constituents_makefile : generate constituents.make";
-  help_texts.add () =  "build constituents_config : generate constituents.make, tag specific Makefile, and setup definitions file";
+  help_texts.add () =  "build <argument>          : build actions. Try 'cmt help build'";
+  //  help_texts.add () =  "build <option>          : build actions. (Try cmt help build)";
+  help_texts.add () =  "build constituent_makefile [-out=<path>] [-with_cmt] [-without_cmt] <constituent> : generate constituent Makefile fragment";
+  help_texts.add () =  "build constituent_config [-out=<path>] <constituent> : generate constituent Makefile fragment, also tag specific Makefile, and setup definitions file for constituent with associated tag (via -target_tag option, or action)";
+  help_texts.add () =  "build constituents_makefile [-out=<path>] : generate constituents Makefile";
+  help_texts.add () =  "build constituents_config [-out=<path>] [-with_cmt] [-without_cmt] : generate constituents Makefile, tag specific Makefile, and setup definitions file, also input requirements file for constituent(s) without associated tag";
   help_texts.add () =  "build dependencies      : generate dependencies";
   help_texts.add () =  "build library_links     : build symbolic links towards all imported libraries";
Index: CMT/HEAD/source/cmt_commands.h
===================================================================
--- CMT/HEAD/source/cmt_commands.h	(revision 560)
+++ CMT/HEAD/source/cmt_commands.h	(revision 561)
@@ -81,4 +81,6 @@
   void option_tag_remove ();
   void option_user_context ();
+  void option_with_cmt ();
+  void option_without_cmt ();
   void option_with_version_directory ();
   void option_without_version_directory ();
Index: CMT/HEAD/source/cmt_constituent.cxx
===================================================================
--- CMT/HEAD/source/cmt_constituent.cxx	(revision 560)
+++ CMT/HEAD/source/cmt_constituent.cxx	(revision 561)
@@ -573,5 +573,6 @@
 
 //----------------------------------------------------------
-void Constituent::show () const
+void Constituent::show (ostream& out) const
+//void Constituent::show () const
 {
   int i;
@@ -580,49 +581,49 @@
     {
     case Library:
-      cout << "library";
+      out << "library";
       break;
     case Application:
-      cout << "application";
+      out << "application";
       break;
     case Document:
-      cout << "document " << generator;
+      out << "document " << generator;
       break;
     }
   
-  cout << " " << name;
+  out << " " << name;
   
   if (group != 0)
     {
-      cout << " -group=" << group->name ();
+      out << " -group=" << group->name ();
     }
   
   if (suffix != 0)
     {
-      cout << " -suffix=" << suffix;
+      out << " -suffix=" << suffix;
     }
   
   if ((type == Application) && need_check)
     {
-      cout << " -check";
+      out << " -check";
     }
   
   if ((type == Library) && no_share)
     {
-      cout << " -no_share";
+      out << " -no_share";
     }
   
   if ((type == Library) && no_static)
     {
-      cout << " -no_static";
+      out << " -no_static";
     }
   
   if ((type == Library) && build_triggers)
     {
-      cout << " -triggers";
+      out << " -triggers";
     }
   
   if (has_target_tag)
     {
-      cout << " -target_tag";
+      out << " -target_tag";
     }
   
@@ -631,5 +632,5 @@
       const cmt_string& import_name = imports[i];
       
-      cout << " -import=" << import_name;
+      out << " -import=" << import_name;
     }
   
@@ -638,5 +639,5 @@
       const cmt_string& exclude = excludes[i];
       
-      cout << " -x=" << exclude;
+      out << " -x=" << exclude;
     }
   
@@ -645,5 +646,5 @@
       const cmt_string& select = selects[i];
       
-      cout << " -k=" << select;
+      out << " -k=" << select;
     }
   
@@ -652,5 +653,5 @@
       const cmt_string& module_name = modules[i];
       
-      cout << " " << module_name;
+      out << " " << module_name;
     }
   
@@ -659,7 +660,14 @@
       const Variable& v = variables[i];
       
-      cout << " " << v.name << "=" << v.value;
-    }
-  
-  cout << endl;
-}
+      //      out << " " << v.name << "=" << v.value;
+      // quote (up to) 2 times as split is applied 2 times
+      // - before action
+      // - in parse
+      cmt_string qvalue (CmtSystem::quote (v.value, " \t"));
+      out << " " << v.name << "="
+	  << (qvalue == v.value ? v.value : CmtSystem::quote (qvalue, " \t"));
+      //	  << CmtSystem::quote (CmtSystem::quote (v.value, " \t"), " \t");
+    }
+  
+  out << endl;
+}
Index: CMT/HEAD/source/cmt_constituent.h
===================================================================
--- CMT/HEAD/source/cmt_constituent.h	(revision 560)
+++ CMT/HEAD/source/cmt_constituent.h	(revision 561)
@@ -43,5 +43,6 @@
   virtual void build_msdev_file (bool simulation) const;
   virtual void build_vsnet_file (bool simulation) const;
-  virtual void show () const;
+  virtual void show (ostream& out = cout) const;
+  //  virtual void show () const;
 
   cmt_string name;
Index: CMT/HEAD/source/cmt_fragment.cxx
===================================================================
--- CMT/HEAD/source/cmt_fragment.cxx	(revision 560)
+++ CMT/HEAD/source/cmt_fragment.cxx	(revision 561)
@@ -200,8 +200,8 @@
 	    m_header.replace ("-header=", "");
 
-	    if (Fragment::find (m_header) == 0)
-	      {
-		Fragment::add (m_header, "", "", "", false, m_use);
-	      }
+// 	    if (Fragment::find (m_header) == 0)
+// 	      {
+	    Fragment::add (m_header, "", "", "", false, m_use, "");
+// 	      }
 	  }
 	else if (w.find ("-trailer=") != cmt_string::npos)
@@ -210,8 +210,12 @@
 	    m_trailer.replace ("-trailer=", "");
 	    
-	    if (Fragment::find (m_trailer) == 0)
-	      {
-		Fragment::add (m_trailer, "", "", "", false, m_use);
-	      }
+// 	    if (Fragment::find (m_trailer) == 0)
+// 	      {
+	    Fragment::add (m_trailer, "", "", "", false, m_use, "");
+// 	      }
+	  }
+	else if (0 == m_use || &Use::current () == m_use)
+	  {
+	    m_path = w;
 	  }
 	break;
@@ -221,5 +225,5 @@
   void commit ()
   {
-    Fragment::add (m_name, m_suffix, m_header, m_trailer, m_need_dependencies, m_use);
+    Fragment::add (m_name, m_suffix, m_header, m_trailer, m_need_dependencies, m_use, m_path);
   }
 
@@ -238,4 +242,5 @@
   bool m_need_dependencies;
   Use* m_use;
+  cmt_string m_path;
 };
 
@@ -309,5 +314,7 @@
                     const cmt_string& trailer,
                     bool need_dependencies,
-                    Use* use)
+                    Use* use,
+		    const cmt_string& path)
+//                    Use* use)
 {
   static FragmentVector& Fragments = fragments ();
@@ -339,4 +346,8 @@
 
         fragment->use = use;
+        if (path != "")
+          {
+	    fragment->path = path;
+	  }
         return;
       }
@@ -351,4 +362,5 @@
   fragment.need_dependencies = need_dependencies;
   fragment.use               = use;
+  fragment.path              = path;
 }
 
@@ -409,5 +421,6 @@
 
 /*----------------------------------------------------------*/
-int Fragment::print ()
+int Fragment::print (PrintMode mode, ostream& out)
+//int Fragment::print ()
 {
   int result = 1;
@@ -423,17 +436,46 @@
     }
   
+  switch (mode)
+    {
+    case Requirements :
+      out << "make_fragment " << name
+	  << (suffix != "" ? " -suffix=" + suffix : "")
+	  << (header != "" ? " -header=" + header : "")
+	  << (trailer != "" ? " -trailer=" + trailer : "")
+	  << (need_dependencies ? " -dependencies" : "")
+	;
+      break;
+    default:
+      break;
+    }
+
   cmt_string the_path = path;
 
-  use->reduce_path (the_path);
-
-  cout << the_path;
-
-  if (suffix != "")
-    {
-      cout << "->" << suffix;
-    }
-
-  cout << endl;
-
+  switch (mode)
+    {
+    case Requirements :
+      the_path = " " + the_path;
+      break;
+    default:
+      use->reduce_path (the_path);
+      break;
+    }
+  
+  out << the_path;
+
+  switch (mode)
+    {
+    case Requirements :
+      break;
+    default:
+      if (suffix != "")
+	{
+	  out << "->" << suffix;
+	}
+      break;
+    }
+
+  out << endl;
+  
   return (result);
 }
@@ -442,5 +484,5 @@
 bool Fragment::locate ()
 {
-  cmt_string root_path;
+  if (path != "") return (true);
 
   if (use == 0)
@@ -450,41 +492,26 @@
     }
 
+  if (Cmt::get_debug ())
+    {
+      cout << "Fragment::locate> " << name
+	   << " in " << use->get_package_name () << endl;
+    }
+  cmt_string root_path;
+
+  // First try <root>/cmt/fragments/<name> for Unix 
+  //       or <root>/cmt/fragments/nmake/<name> for Win
+
   use->get_full_path (root_path);
 
-  if (path != "") return (true);
-
-  // First try <root>/fragments/<name> or <root>/fragments/nmake/<name>
-
-  path = root_path;
-  path += CmtSystem::file_separator ();
-  path += "fragments";
-  path += CmtSystem::file_separator ();
-  
-  if (Cmt::build_nmake ())
-    {
-      path += "nmake";
-      path += CmtSystem::file_separator ();
-    }
-  
-  path += name;
-
-  if (CmtSystem::test_file (path)) return (true);
-
-  // Then try <root>/fragments/<name> for both Win and Unix
-
-  path = root_path;
-  path += CmtSystem::file_separator ();
-  path += "fragments";
-  path += CmtSystem::file_separator ();
-  path += name;
-
-  if (CmtSystem::test_file (path)) return (true);
-
-  // Then try <root>/cmt/fragments/<name> or <root>/cmt/fragments/nmake/<name>
-
-  root_path += CmtSystem::file_separator ();
-
-  if (use->style == mgr_style) root_path += "mgr";
-  else root_path += "cmt";
+  if (use->style == cmt_style)
+    {
+      root_path += CmtSystem::file_separator ();
+      root_path += "cmt";
+    }
+  else if (use->style == mgr_style)
+    {
+      root_path += CmtSystem::file_separator ();
+      root_path += "mgr";
+    }
   
   root_path += CmtSystem::file_separator ();
@@ -501,15 +528,52 @@
   
   path += name;
-  
+  //cerr << "test_file: " << path << endl;  
   if (CmtSystem::test_file (path)) return (true);
 
-  // Then try <root>/cmt/fragments/<name> for both Win and Unix
+  // Then try <root>/cmt/fragments/<name> for Win
+
+  if (Cmt::build_nmake ())
+    {
+      path = root_path;
+      path += name;
+      
+      if (CmtSystem::test_file (path)) return (true);
+    }
+
+  // Then try <root>/fragments/<name> for Unix
+  //      or <root>/fragments/nmake/<name> for Win
+
+  use->get_full_path (root_path);
+
+  root_path += CmtSystem::file_separator ();
+  root_path += "fragments";
+  root_path += CmtSystem::file_separator ();
 
   path = root_path;
   
+  if (Cmt::build_nmake ())
+    {
+      path += "nmake";
+      path += CmtSystem::file_separator ();
+    }
+  
   path += name;
 
+  //cerr << "test_file: " << path << endl;  
   if (CmtSystem::test_file (path)) return (true);
 
+  // Then try <root>/fragments/<name> for Win
+
+  if (Cmt::build_nmake ())
+    {
+      path = root_path;
+      path += name;
+
+      if (CmtSystem::test_file (path)) return (true);
+    }
+
+  CmtMessage::warning
+    (CmtError::get_error_name (CmtError::fragment_not_found)
+     + ": " + name);
   return (false);
 }
@@ -1116,4 +1180,46 @@
   if (!result)
     {
+      //      CmtMessage::info ("Fragment " + _name + " not found");
+      //      cerr << "#CMT> Fragment " << _name << " not found" << endl;
+      _fragment = 0;
+    }
+
+  return (result);
+}
+
+//--------------------------------------------------
+bool FragmentHandle::copy (cmt_string& out, int variables, ...)
+{
+  if (!setup ()) return (false);
+
+  va_list ids;
+
+  va_start (ids, variables);
+  bool result = _fragment->copy (out, variables, ids);
+  va_end (ids);
+
+  if (!result)
+    {
+      //      CmtMessage::info ("Fragment " + _name + " not found");
+      //      cerr << "#CMT> Fragment " << _name << " not found" << endl;
+      _fragment = 0;
+    }
+
+  return (result);
+}
+
+//--------------------------------------------------
+bool FragmentHandle::wincopy (FILE* out, int variables, ...)
+{
+  if (!setup ()) return (false);
+
+  va_list ids;
+
+  va_start (ids, variables);
+  bool result = _fragment->wincopy (out, variables, ids);
+  va_end (ids);
+
+  if (!result)
+    {
       CmtMessage::info ("Fragment " + _name + " not found");
       //      cerr << "#CMT> Fragment " << _name << " not found" << endl;
@@ -1125,5 +1231,5 @@
 
 //--------------------------------------------------
-bool FragmentHandle::copy (cmt_string& out, int variables, ...)
+bool FragmentHandle::wincopy (cmt_string& out, int variables, ...)
 {
   if (!setup ()) return (false);
@@ -1132,5 +1238,5 @@
 
   va_start (ids, variables);
-  bool result = _fragment->copy (out, variables, ids);
+  bool result = _fragment->wincopy (out, variables, ids);
   va_end (ids);
 
@@ -1145,6 +1251,9 @@
 }
 
-//--------------------------------------------------
-bool FragmentHandle::wincopy (FILE* out, int variables, ...)
+
+
+
+//--------------------------------------------------
+bool FragmentHandle::copy (FILE* out, const Variable::VariableVector& vector, int variables, ...)
 {
   if (!setup ()) return (false);
@@ -1153,5 +1262,47 @@
 
   va_start (ids, variables);
-  bool result = _fragment->wincopy (out, variables, ids);
+  bool result = _fragment->copy (out, vector, variables, ids);
+  va_end (ids);
+
+  if (!result)
+    {
+      //      CmtMessage::info ("Fragment " + _name + " not found");
+      //      cerr << "#CMT> Fragment " << _name << " not found" << endl;
+      _fragment = 0;
+    }
+
+  return (result);
+}
+
+//--------------------------------------------------
+bool FragmentHandle::copy (cmt_string& out, const Variable::VariableVector& vector, int variables, ...)
+{
+  if (!setup ()) return (false);
+
+  va_list ids;
+
+  va_start (ids, variables);
+  bool result = _fragment->copy (out, vector, variables, ids);
+  va_end (ids);
+
+  if (!result)
+    {
+      //      CmtMessage::info ("Fragment " + _name + " not found");
+      //      cerr << "#CMT> Fragment " << _name << " not found" << endl;
+      _fragment = 0;
+    }
+
+  return (result);
+}
+
+//--------------------------------------------------
+bool FragmentHandle::wincopy (FILE* out, const Variable::VariableVector& vector, int variables, ...)
+{
+  if (!setup ()) return (false);
+
+  va_list ids;
+
+  va_start (ids, variables);
+  bool result = _fragment->wincopy (out, vector, variables, ids);
   va_end (ids);
 
@@ -1167,5 +1318,7 @@
 
 //--------------------------------------------------
-bool FragmentHandle::wincopy (cmt_string& out, int variables, ...)
+bool FragmentHandle::wincopy (cmt_string& out, 
+                              const Variable::VariableVector& vector, 
+                              int variables, ...)
 {
   if (!setup ()) return (false);
@@ -1174,5 +1327,5 @@
 
   va_start (ids, variables);
-  bool result = _fragment->wincopy (out, variables, ids);
+  bool result = _fragment->wincopy (out, vector, variables, ids);
   va_end (ids);
 
@@ -1187,93 +1340,4 @@
 }
 
-
-
-
-//--------------------------------------------------
-bool FragmentHandle::copy (FILE* out, const Variable::VariableVector& vector, int variables, ...)
-{
-  if (!setup ()) return (false);
-
-  va_list ids;
-
-  va_start (ids, variables);
-  bool result = _fragment->copy (out, vector, variables, ids);
-  va_end (ids);
-
-  if (!result)
-    {
-      CmtMessage::info ("Fragment " + _name + " not found");
-      //      cerr << "#CMT> Fragment " << _name << " not found" << endl;
-      _fragment = 0;
-    }
-
-  return (result);
-}
-
-//--------------------------------------------------
-bool FragmentHandle::copy (cmt_string& out, const Variable::VariableVector& vector, int variables, ...)
-{
-  if (!setup ()) return (false);
-
-  va_list ids;
-
-  va_start (ids, variables);
-  bool result = _fragment->copy (out, vector, variables, ids);
-  va_end (ids);
-
-  if (!result)
-    {
-      CmtMessage::info ("Fragment " + _name + " not found");
-      //      cerr << "#CMT> Fragment " << _name << " not found" << endl;
-      _fragment = 0;
-    }
-
-  return (result);
-}
-
-//--------------------------------------------------
-bool FragmentHandle::wincopy (FILE* out, const Variable::VariableVector& vector, int variables, ...)
-{
-  if (!setup ()) return (false);
-
-  va_list ids;
-
-  va_start (ids, variables);
-  bool result = _fragment->wincopy (out, vector, variables, ids);
-  va_end (ids);
-
-  if (!result)
-    {
-      CmtMessage::info ("Fragment " + _name + " not found");
-      //      cerr << "#CMT> Fragment " << _name << " not found" << endl;
-      _fragment = 0;
-    }
-
-  return (result);
-}
-
-//--------------------------------------------------
-bool FragmentHandle::wincopy (cmt_string& out, 
-                              const Variable::VariableVector& vector, 
-                              int variables, ...)
-{
-  if (!setup ()) return (false);
-
-  va_list ids;
-
-  va_start (ids, variables);
-  bool result = _fragment->wincopy (out, vector, variables, ids);
-  va_end (ids);
-
-  if (!result)
-    {
-      CmtMessage::info ("Fragment " + _name + " not found");
-      //      cerr << "#CMT> Fragment " << _name << " not found" << endl;
-      _fragment = 0;
-    }
-
-  return (result);
-}
-
 //--------------------------------------------------
 bool FragmentHandle::setup ()
@@ -1286,9 +1350,11 @@
       if (_fragment == 0)
         {
-	  CmtMessage::info ("Fragment " + _name + " not found");
+	  CmtMessage::warning
+	    (CmtError::get_error_name (CmtError::fragment_not_found)
+	     + ": " + _name);
 	  //          cerr << "#CMT> Fragment " << _name << " not found" << endl;
         }
     }
-
+  
   if (_fragment == 0)
     {
Index: CMT/HEAD/source/cmt_fragment.h
===================================================================
--- CMT/HEAD/source/cmt_fragment.h	(revision 560)
+++ CMT/HEAD/source/cmt_fragment.h	(revision 561)
@@ -61,5 +61,7 @@
                    const cmt_string& trailer,
                    bool need_dependencies,
-                   Use* use);
+                   Use* use,
+                   const cmt_string& path);
+  //                   Use* use);
   static void show (const cmt_string& name);
   static void show_all ();
@@ -79,5 +81,6 @@
   ~Fragment ();
   void clear ();
-  int print ();
+  int print (PrintMode mode = Csh, ostream& out = cout); // Csh is default for ArgParser::mode
+  //  int print ();
   bool locate ();
 
Index: CMT/HEAD/source/cmt_generator.cxx
===================================================================
--- CMT/HEAD/source/cmt_generator.cxx	(revision 560)
+++ CMT/HEAD/source/cmt_generator.cxx	(revision 561)
@@ -18,4 +18,5 @@
 #include "cmt_generators.h"
 #include "cmt_log.h"
+#include "cmt_error.h"
 
 //------------------------------------------------------------------------
@@ -59,5 +60,4 @@
   m_TITLE.set ("TITLE");
   m_GROUP.set ("GROUP");
-  m_CONSTITUENT.set ("CONSTITUENT");
   m_CONSTITUENTSUFFIX.set ("CONSTITUENTSUFFIX");
   m_LIBRARYSUFFIX.set ("LIBRARYSUFFIX");
@@ -73,5 +73,4 @@
   m_SUFFIX.set ("SUFFIX");
   m_FILENAME.set ("FILENAME");
-  //  m_LINKMACRO.set ("LINKMACRO");
   m_LINE.set ("LINE");
   m_ADDINCLUDE.set ("ADDINCLUDE");
@@ -691,5 +690,5 @@
 
 //------------------------------------------------------------------------
-static ApplicationGenerator ApplicationContext;
+//static ApplicationGenerator ApplicationContext;
 static LibraryGenerator LibraryContext;
 static DocumentGenerator DocumentContext;
@@ -735,7 +734,80 @@
 //--------------------------------------------------
 void Generator::build_constituents_makefile (const cmt_string& package,
-					     const CmtSystem::cmt_string_vector& arguments)
-{
-  ConstituentsMakefileContext.build (package, arguments);
+					     const cmt_string& file)
+//					     const CmtSystem::cmt_string_vector& arguments)
+{
+  ConstituentsMakefileContext.build (package, file);
+  //  ConstituentsMakefileContext.build (package, arguments);
+}
+
+//--------------------------------------------------
+int Generator::build_constituent_infile (const Constituent& constituent,
+					 const cmt_string& outdir,
+					 bool usecmt)
+{
+  cmt_string file (constituent.name + ".in");
+  if (outdir != "")
+    {
+      if (outdir [outdir.size () - 1] != CmtSystem::file_separator ())
+	file = outdir + CmtSystem::file_separator () + file;
+      else
+	file = outdir + file;
+    }
+
+  static InGenerator InGen (usecmt);
+
+  bool gen (true);
+  ostringstream os;
+  ofstream s;
+  //  s.open (file);
+  s.open (file, ios::in);
+  if (s) // file already exists
+    {
+      InGen.build (constituent, os);
+      ostringstream osn;
+      osn << s.rdbuf ();
+      if (os.str () == osn.str ())
+	{
+	  //	  cerr << file << " up-to-date" << endl;
+	  gen = false;
+	}
+    }
+  s.clear ();
+  s.close ();
+  s.clear ();
+  if (gen)
+    {
+      s.open (file);
+      if (!s)
+	{
+	  CmtError::set (CmtError::file_access_error, file);
+	  return -1;
+	}
+      s.exceptions (ios::failbit | ios::badbit);
+      try
+	{
+	  if (os.str ().size () != 0)
+	    {
+	      //  cerr << file << " contents already generated" << endl;
+	      s << os.str ();
+	    }
+	  else
+	    {
+	      InGen.build (constituent, s);
+	    }
+	  s.close (); // ios_base::failbit
+	}
+      catch (const ios::failure& e)
+	{
+	  CmtSystem::close_ostream (NULL, file + ": " + cmt_string (e.what ()));
+	  return -1;
+	}
+    }
+
+      //  InGen.build (constituent, s);
+
+  //  s.close (); // ios_base::failbit
+
+  return 0;
 }
 
@@ -749,6 +821,6 @@
     {
     case Application:
-      ApplicationContext.build (package, constituent, file);
-      break;
+      //ApplicationContext.build (package, constituent, file);
+      //break;
     case Library:
       LibraryContext.build (package, constituent, file);
@@ -1009,2 +1081,184 @@
 }
 
+//------------------------------------------------------------------------
+InGenerator::Buffer::Buffer ()
+  : m_initialized (false), m_usecmt (true)
+{ }
+
+//------------------------------------------------------------------------
+void InGenerator::Buffer::set_names (const CmtSystem::cmt_string_vector& names)
+{
+  m_names = names;
+}
+
+//------------------------------------------------------------------------
+int InGenerator::Buffer::print (ostream& s)
+{
+  initialize ();
+  s << m_buffer.str ();
+  return 0;
+}
+
+//------------------------------------------------------------------------
+void InGenerator::Buffer::set_uses (bool usecmt)
+{
+  m_usecmt = usecmt;
+}
+
+//------------------------------------------------------------------------
+int InGenerator::Languages::initialize ()
+{
+  int errors (0);
+  if (m_initialized) return - errors;
+  m_initialized = true;
+  for (int i = 0; i < m_names.size (); i++)
+    {
+      const cmt_string& name = m_names[i];
+      Language& p (Language::find (name));
+      if (Language::null () == p) { errors += 1; continue; }
+      p.show (Requirements, m_buffer);
+      /*
+      if (!p->use->get_package ()->is_cmt ())
+	p->print (Requirements, m_buffer);
+      */
+    }
+  //  cerr << "Languages::initialize: " << m_buffer.str ();
+  return - errors;
+}
+
+//------------------------------------------------------------------------
+int InGenerator::Fragments::initialize ()
+{
+  int errors (0);
+  if (m_initialized) return - errors;
+  m_initialized = true;
+  for (int i = 0; i < m_names.size (); i++)
+    {
+      const cmt_string& name = m_names[i];
+      Fragment* fragment (Fragment::find (name));
+      if (0 == fragment) { errors += 1; continue; }
+      if (m_usecmt || !fragment->use->get_package ()->is_cmt ())
+	fragment->print (Requirements, m_buffer);
+    }
+  //  cerr << "initialize: " << m_buffer.str ();
+  return - errors;
+}
+
+//------------------------------------------------------------------------
+InGenerator::InGenerator (bool usecmt)
+  : m_usecmt (usecmt)
+{
+  CmtSystem::cmt_string_vector common;
+  common.push_back ("make_header");
+  common.push_back ("dependencies");
+  common.push_back ("cleanup_header");
+  m_common.set_names (common);
+  m_common.set_uses (usecmt);
+
+  CmtSystem::cmt_string_vector application;
+  application.push_back ("java_header");
+  application.push_back ("application_header");
+  application.push_back ("application");
+  application.push_back ("check_java");
+  application.push_back ("cleanup_application");
+  application.push_back ("cleanup_objects");
+  application.push_back ("check_application");
+
+  CmtSystem::cmt_string_vector application_library;
+  application_library.push_back ("protos_header");
+  application_library.push_back ("buildproto");
+  application_library.push_back ("dependencies_and_triggers");
+  application_library.push_back ("java");
+  application_library.push_back ("java_copy");
+  application_library.push_back ("cleanup");
+  application_library.push_back ("cleanup_java");
+  m_application_library.set_names (application_library);
+  m_application_library.set_uses (usecmt);
+
+  CmtSystem::cmt_string_vector library;
+  library.push_back ("jar_header");
+  library.push_back ("library_header");
+  library.push_back ("jar");
+  library.push_back ("library_no_share");
+  library.push_back ("library_no_static");
+  library.push_back ("library");
+  library.push_back ("cleanup_library");
+
+  CmtSystem::cmt_string_vector languages;
+  Language::LanguageVector& Languages = Language::languages ();
+  for (int n = 0; n < Languages.size (); n++)
+    {
+      Language& language = Languages[n];
+      //language.setup_fragments ();
+      application.push_back (language.fragment_name); //application.name ();
+      library.push_back (language.fragment_name + "_library"); //library.name ();
+      if (m_usecmt || !language.m_use->get_package ()->is_cmt ())
+//       if (!language.m_use->get_package ()->is_cmt ())
+ 	{
+	  languages.push_back (language.m_name);
+ 	}
+      else if (language.dependencies_options () !=
+	  language.dependencies_options_expanded ())
+	{
+	  languages.push_back (language.m_name);
+	}
+    }
+  m_languages.set_names (languages);
+  m_languages.set_uses (usecmt);
+  m_application.set_names (application);
+  m_application.set_uses (usecmt);
+  m_library.set_names (library);
+  m_library.set_uses (usecmt);
+  
+  CmtSystem::cmt_string_vector document;
+  document.push_back ("document_header");
+  m_document.set_names (document);
+  m_document.set_uses (usecmt);
+}
+
+//------------------------------------------------------------------------
+int InGenerator::build (const Constituent& constituent, ostream& s)
+{
+  constituent.show (s);
+  m_common.print (s);
+
+  switch (constituent.type)
+    {
+    case Application:
+      m_application.print (s);
+      m_application_library.print (s);
+      m_languages.print (s);
+      break;
+    case Library:
+      m_application_library.print (s);
+      m_library.print (s);
+      m_languages.print (s);
+      break;
+    case Document:
+      Fragment* fragment (Fragment::find (constituent.generator));
+      if (0 == fragment) return -1;
+      if (m_usecmt || !fragment->use->get_package ()->is_cmt ())
+	fragment->print (Requirements, s);
+      if ("" != fragment->header)
+	{
+	  Fragment* header (Fragment::find (fragment->header));
+	  if (0 == header) return -1;
+	  //	  if (header->use != fragment->use &&
+	  if (m_usecmt || !header->use->get_package ()->is_cmt ())
+	    header->print (Requirements, s);
+	}
+      if ("" != fragment->trailer)
+	{
+	  Fragment* trailer (Fragment::find (fragment->trailer));
+	  if (0 == trailer) return -1;
+	  //	  if (trailer->use != fragment->use &&
+	  if (m_usecmt || !trailer->use->get_package ()->is_cmt ())
+	    trailer->print (Requirements, s);
+	}
+      m_document.print (s);
+      break;
+    }
+
+  return 0;
+}
+//------------------------------------------------------------------------
Index: CMT/HEAD/source/cmt_generator.h
===================================================================
--- CMT/HEAD/source/cmt_generator.h	(revision 560)
+++ CMT/HEAD/source/cmt_generator.h	(revision 561)
@@ -138,4 +138,53 @@
 };
 
+class InGenerator
+{
+ public:
+  InGenerator (bool usecmt);
+  int build (const Constituent& constituent, ostream& out = cout);
+  
+ private:
+  InGenerator ();
+
+ private:
+  class Buffer
+  {
+  public:
+    Buffer ();
+    void set_names (const CmtSystem::cmt_string_vector& names);
+    int print (ostream& s);
+    void set_uses (bool usecmt);
+  private:
+    virtual int initialize () = 0;
+
+  protected:
+    CmtSystem::cmt_string_vector m_names;
+    ostringstream m_buffer;
+    bool m_initialized;
+    bool m_usecmt;
+  };
+  
+  class Languages : public Buffer
+  {
+  private:
+    int initialize ();
+  };
+  
+  class Fragments : public Buffer
+  {
+  private:
+    int initialize ();
+  };
+  
+ private:
+  Fragments m_common;
+  Fragments m_application;
+  Fragments m_application_library;
+  Fragments m_library;
+  Fragments m_document;
+  Languages m_languages;
+  bool m_usecmt;
+};
+
 /**
    Generic command interface to be used by the cmt command driver.
@@ -161,5 +210,6 @@
     // Build the constituents.make file
   static void build_constituents_makefile (const cmt_string& package,
-					   const CmtSystem::cmt_string_vector& arguments);
+					   const cmt_string& file = "");
+					   //					   const CmtSystem::cmt_string_vector& arguments);
 
     // Build the makefile fragment for one constituent
@@ -167,4 +217,7 @@
 					 const cmt_string& file = "");
   static void build_constituent_makefile (const CmtSystem::cmt_string_vector& arguments);
+  static int build_constituent_infile (const Constituent& constituent,
+				       const cmt_string& outdir = "",
+				       bool usecmt = true);
 
   static void build_default_makefile ();
Index: CMT/HEAD/source/cmt_generators.cxx
===================================================================
--- CMT/HEAD/source/cmt_generators.cxx	(revision 560)
+++ CMT/HEAD/source/cmt_generators.cxx	(revision 561)
@@ -230,6 +230,6 @@
   CmtSystem::basename (m_FULLNAME, m_FILENAME.value);
   
-  if (CmtSystem::test_file (m_FULLNAME))
-    {
+  //  if (CmtSystem::test_file (m_FULLNAME))
+  //    {
       java_fragment.copy (m_output_file, constituent.variables, 5,
                           &m_NAME,
@@ -238,4 +238,5 @@
                           &m_CONSTITUENT, 
                           &m_CONSTITUENTSUFFIX);
+      /*
     }
   else
@@ -244,4 +245,5 @@
       //      cerr << "#CMT> Warning: file " << m_FULLNAME << " not found" << endl;
     }
+      */
 }
 
@@ -514,5 +516,5 @@
   //fill_outputs ();
 
-  prepare_use_context ();
+  //prepare_use_context ();
 
   m_DATE = CmtSystem::now ();
@@ -986,5 +988,5 @@
       int count = get_all_files (full_name, excludes, selects, files);
 
-      filter_path (full_name);
+      //      filter_path (full_name);
 
       /*
@@ -1010,5 +1012,5 @@
   //  fill_outputs ();
 
-  prepare_use_context ();
+  //  prepare_use_context ();
 
   m_DATE = CmtSystem::now ();
@@ -1069,4 +1071,5 @@
   else
     {
+      /*
       for (i = 0; i < sources.size (); i++)
         {
@@ -1086,5 +1089,9 @@
             {
               const cmt_string& name = files[j];
-              
+      */              
+      for (i = 0; i < m_source_files.size (); i++)
+	{
+	  SourceFile& file = m_source_files[i];
+	  const cmt_string& name = file.name ();
               if (name != "") 
                 {
@@ -1101,5 +1108,5 @@
                            name.c_str ());
                 }
-            }
+	      //            }
         }
     }
@@ -1118,11 +1125,10 @@
       CmtSystem::basename (file_name, m_FILENAME.value);
       CmtSystem::get_dot_suffix (m_FILENAME.value, m_FILESUFFIX.value);
-
+      /*
       if (!CmtSystem::test_file (file_name) && !CmtSystem::test_directory (file_name))
         {
           CmtMessage::warning ("Source file " + file_name + " not found");
-	  //          cerr << "#CMT> Warning: Source file " << file_name << " not found" << endl;
-        }
-
+        }
+      */
       filter_path (m_FULLNAME.value);
 
@@ -1164,5 +1170,5 @@
 				      const cmt_string& output_suffix)
 {
-  static cmt_string output_dir;
+  //static cmt_string output_dir;
   static cmt_string suffix;
   static cmt_string name;
@@ -1172,11 +1178,10 @@
     {
       CmtMessage::warning ("Source file " + file + " not found");
-      //      cerr << "#CMT> Warning: Source file " << file << " not found" << endl;
-    }
-
-  CmtSystem::dirname (file, output_dir);
-  output_dir += CmtSystem::file_separator ();
-
-  filter_path (output_dir);
+    }
+
+  //CmtSystem::dirname (file, output_dir);
+  //output_dir += CmtSystem::file_separator ();
+
+  //filter_path (output_dir);
 
   CmtSystem::get_suffix (file, suffix);
@@ -2520,24 +2525,26 @@
 //--------------------------------------------------
 void ConstituentsMakefileGenerator::build (const cmt_string& package,
-					   const CmtSystem::cmt_string_vector& arguments)
+					   const cmt_string& file)
+//					   const CmtSystem::cmt_string_vector& arguments)
 {
   reset ();
 
-  cmt_string file_name, dir_name;
-
-  if (arguments.size () > 0)
-    {
-      cmt_string arg = arguments[0];
-      if (arg.substr (0, 5) == "-out=")
-	{
-	  arg.erase (0, 5);
-	  file_name = arg;
-	}
-      else if (arg.substr (0, 8) == "-outdir=")
-	{
-	  arg.erase (0, 8);
-	  dir_name = arg;
-	}
-    }
+  cmt_string file_name (file);
+    //, dir_name;
+
+//   if (arguments.size () > 0)
+//     {
+//       cmt_string arg = arguments[0];
+//       if (arg.substr (0, 5) == "-out=")
+// 	{
+// 	  arg.erase (0, 5);
+// 	  file_name = arg;
+// 	}
+//       else if (arg.substr (0, 8) == "-outdir=")
+// 	{
+// 	  arg.erase (0, 8);
+// 	  dir_name = arg;
+// 	}
+//     }
 
   if (file_name == "")
@@ -2557,10 +2564,10 @@
     }
 
-  if (dir_name != "")
-    {
-      if (dir_name [dir_name.size () - 1] != CmtSystem::file_separator ())
-	dir_name += CmtSystem::file_separator ();
-      file_name = dir_name + file_name;
-    }
+//   if (dir_name != "")
+//     {
+//       if (dir_name [dir_name.size () - 1] != CmtSystem::file_separator ())
+// 	dir_name += CmtSystem::file_separator ();
+//       file_name = dir_name + file_name;
+//     }
 
   cmt_string save_file_name = file_name;
Index: CMT/HEAD/source/cmt_generators.h
===================================================================
--- CMT/HEAD/source/cmt_generators.h	(revision 560)
+++ CMT/HEAD/source/cmt_generators.h	(revision 561)
@@ -200,5 +200,6 @@
   ConstituentsMakefileGenerator ();
   void build (const cmt_string& package,
-	      const CmtSystem::cmt_string_vector& arguments);
+	      const cmt_string& file);
+  //	      const CmtSystem::cmt_string_vector& arguments);
 
 private:
Index: CMT/HEAD/source/cmt_language.cxx
===================================================================
--- CMT/HEAD/source/cmt_language.cxx	(revision 560)
+++ CMT/HEAD/source/cmt_language.cxx	(revision 561)
@@ -145,5 +145,7 @@
 
 /*----------------------------------------------------------*/
-void Language::action (const CmtSystem::cmt_string_vector& words)
+void Language::action (const CmtSystem::cmt_string_vector& words,
+                       Use* use)
+//void Language::action (const CmtSystem::cmt_string_vector& words)
   /*----------------------------------------------------------*/
 {
@@ -202,4 +204,5 @@
         }
     }
+  language.m_use = use;
 }
 
@@ -287,12 +290,15 @@
   m_native_dependencies = false;
   m_dependencies_options = "none";
+  m_dependencies_options_expanded = "";
   m_native_dependencies_set = false;
-}
-
-/*----------------------------------------------------------*/
-void Language::show ()
-  /*----------------------------------------------------------*/
-{
-  cout << "language " << m_name;
+  m_use  = 0;
+}
+
+/*----------------------------------------------------------*/
+void Language::show (PrintMode mode, ostream& out)
+//void Language::show ()
+  /*----------------------------------------------------------*/
+{
+  out << "language " << m_name;
 
   int i;
@@ -302,30 +308,48 @@
       cmt_string& suffix = suffixes[i];
       
-      cout << " -suffix=" << suffix;
-    }
-
-  if (linker != "")
-    {
-      cout << " -linker=" << linker;
+      out << " -suffix=" << suffix;
+    }
+
+  if (linker != "none")
+    //  if (linker != "")
+    {
+      switch (mode)
+	{
+	case Requirements :
+	  out << " -linker=" << CmtSystem::quote (linker, " \t");
+	  break;
+	default:
+	  out << " -linker=" << linker;
+	  break;
+	}
     }
 
   if (prototypes)
     {
-      cout << " -prototypes";
+      out << " -prototypes";
     }
 
   if (preprocessor_command != "-I")
     {
-      cout << " -preprocessor_command=" << preprocessor_command;
+      out << " -preprocessor_command=";
+      switch (mode)
+	{
+	case Requirements :
+	  out << CmtSystem::quote (preprocessor_command, " \t");
+	  break;
+	default:
+	  out << preprocessor_command;
+	  break;
+	}
     }
 
   if (fragment_name != m_name)
     {
-      cout << " -fragment=" << fragment_name;
+      out << " -fragment=" << fragment_name;
     }
 
   if (output_suffix != "")
     {
-      cout << " -output_suffix=" << output_suffix;
+      out << " -output_suffix=" << output_suffix;
     }
 
@@ -334,13 +358,22 @@
       cmt_string& suffix = extra_output_suffixes[i];
       
-      cout << " -extra_output_suffix=" << suffix;
+      out << " -extra_output_suffix=" << suffix;
     }
 
   if (m_dependencies_options != "none")
     {
-      cout << " -dependencies_options=" << m_dependencies_options;
-    }
-
-  cout << endl;
+      out << " -dependencies_options=";
+      switch (mode)
+	{
+	case Requirements :
+	  out << CmtSystem::quote (dependencies_options_expanded (), " \t");
+	  break;
+	default:
+	  out << m_dependencies_options;
+	  break;
+	}
+    }
+
+  out << endl;
 }
 
@@ -418,4 +451,5 @@
 	  m_native_dependencies = false;
 	}
+      m_dependencies_options_expanded = opts;
     }
   else
@@ -426,2 +460,10 @@
   return;
 }
+
+/*----------------------------------------------------------*/
+const cmt_string& Language::dependencies_options_expanded ()
+  /*----------------------------------------------------------*/
+{
+  setup_native_dependencies ();
+  return m_dependencies_options_expanded;
+}
Index: CMT/HEAD/source/cmt_language.h
===================================================================
--- CMT/HEAD/source/cmt_language.h	(revision 560)
+++ CMT/HEAD/source/cmt_language.h	(revision 561)
@@ -15,5 +15,6 @@
 public:
   typedef cmt_vector<Language> LanguageVector;
-  static void action (const CmtSystem::cmt_string_vector& words);
+  static void action (const CmtSystem::cmt_string_vector& words,
+		      Use* use);
   static Language& find (const cmt_string& name);
   static Language& find_with_suffix (const cmt_string& suffix);
@@ -31,5 +32,6 @@
   ~Language ();
   void clear ();
-  void show ();
+  void show (PrintMode mode = Csh, ostream& out = cout); // Csh is default for ArgParser::mode
+  //  void show ();
   void setup_fragments ();
   bool operator == (const cmt_string& name) const;
@@ -38,4 +40,5 @@
   bool native_dependencies ();
   const cmt_string& dependencies_options () const;
+  const cmt_string& dependencies_options_expanded ();
 
   cmt_string m_name;
@@ -47,4 +50,5 @@
   CmtSystem::cmt_string_vector suffixes;
   CmtSystem::cmt_string_vector extra_output_suffixes;
+  UseRef m_use;
 
   FragmentHandle application;
@@ -56,4 +60,5 @@
   bool m_native_dependencies;
   cmt_string m_dependencies_options;
+  cmt_string m_dependencies_options_expanded;
   bool m_native_dependencies_set;
 };
Index: CMT/HEAD/source/cmt_parser.cxx
===================================================================
--- CMT/HEAD/source/cmt_parser.cxx	(revision 560)
+++ CMT/HEAD/source/cmt_parser.cxx	(revision 561)
@@ -64,4 +64,5 @@
   m_cmt_root       = "";
   m_cmt_version    = "";
+  m_use_cmt        = true;
   m_current_dir     = "";
   m_current_file_path = "";
@@ -2100,9 +2101,28 @@
       return;
     }
-  if (ap.arguments.size () > 0) 
-    {
-      set_standard_macros ();
-      Generator::build_constituent_makefile (ap.arguments);
-    }
+  set_standard_macros ();
+
+  cmt_string out, name;
+  for (int i = 0; i < ap.arguments.size (); i++)
+    {
+      const cmt_string& arg = ap.arguments[i];
+      if (arg.substr (0, 5) == "-out=")
+	arg.substr (5, out);
+      else
+	name = arg;
+    }
+
+  const Constituent* constituent = Constituent::find (name);
+  if (constituent == 0)
+    {
+      CmtError::set (CmtError::constituent_not_found, name);
+      return;
+    }
+  Generator::build_constituent_makefile (*constituent, out);
+//   if (ap.arguments.size () > 0) 
+//     {
+//       set_standard_macros ();
+//       Generator::build_constituent_makefile (ap.arguments);
+//     }
 }
 
@@ -2115,16 +2135,15 @@
       return;
     }
-  if (ap.arguments.size () == 0) return;
   set_standard_macros ();
 
   CmtSystem::cmt_string_vector files (2);
-  cmt_string  outdir, name;
+  cmt_string  out, outdir, name;
   for (int i = 0; i < ap.arguments.size (); i++)
     {
-      cmt_string arg = ap.arguments[i];
+      const cmt_string arg = ap.arguments[i];
       if (arg.substr (0, 5) == "-out=")
 	{
-	  arg.erase (0, 5);
-	  CmtSystem::dirname (arg, outdir);
+	  arg.substr (5, out);
+	  CmtSystem::dirname (out, outdir);
 	}
       else
@@ -2134,12 +2153,13 @@
     }
 
-  Generator::build_constituent_makefile (ap.arguments);
+  //  Generator::build_constituent_makefile (ap.arguments);
 
   const Constituent* constituent = Constituent::find (name);
   if (constituent == 0)
     {
-      // generate error
+      CmtError::set (CmtError::constituent_not_found, name);
       return;
     }
+  Generator::build_constituent_makefile (*constituent, out);
   if (!constituent->has_target_tag) return;
   //  cerr << "constituent: " << name << endl;
@@ -2252,5 +2272,16 @@
   set_standard_macros ();
 
-  Generator::build_constituents_makefile (Me.m_current_package, ap.arguments);
+  cmt_string out;
+  for (int i = 0; i < ap.arguments.size (); i++)
+    {
+      const cmt_string& arg = ap.arguments[i];
+      if (arg.substr (0, 5) == "-out=")
+	{
+	  arg.substr (5, out);
+	}
+    }
+
+  Generator::build_constituents_makefile (Me.m_current_package, out);
+  //  Generator::build_constituents_makefile (Me.m_current_package, ap.arguments);
 }
 
@@ -2266,18 +2297,18 @@
 
   CmtSystem::cmt_string_vector files (2);
-  cmt_string outdir;
-  if (ap.arguments.size () > 0)
-    {
-      cmt_string arg = ap.arguments[0];
+  cmt_string out, outdir;
+  bool usecmt (true);
+  for (int i = 0; i < ap.arguments.size (); i++)
+    {
+      const cmt_string& arg = ap.arguments[i];
       if (arg.substr (0, 5) == "-out=")
 	{
-	  arg.erase (0, 5);
-	  CmtSystem::dirname (arg, outdir);
+	  arg.substr (5, out);
+	  CmtSystem::dirname (out, outdir);
 	}
-      else if (arg.substr (0, 8) == "-outdir=")
-	{
-	  arg.erase (0, 8);
-	  outdir = arg;
-	}
+      else if (arg == "-with_cmt")
+	usecmt = true;
+      else if (arg == "-without_cmt")
+	usecmt = false;
     }
   //  cerr << "outdir: " << outdir << endl;
@@ -2378,5 +2409,15 @@
     }
 
-  Generator::build_constituents_makefile (Me.m_current_package, ap.arguments);
+  Generator::build_constituents_makefile (Me.m_current_package, out);
+  //  Generator::build_constituents_makefile (Me.m_current_package, ap.arguments);
+
+  const Constituent::ConstituentVector& constituents =
+    Constituent::constituents ();
+  for (int n = 0; n < constituents.size (); n++)
+    {
+      const Constituent& constituent = constituents[n];
+      if (constituent.has_target_tag) continue;
+      Generator::build_constituent_infile (constituent, outdir, usecmt);
+    }
 }
 
@@ -6270,49 +6311,6 @@
   parse_arguments (ap);
   
-  if (Me.m_debug)
-    {
-      cout << "After parse_argument> pack=" << Me.m_current_package
-           << " Me.m_current_tag=" << Me.m_current_tag
-           << " cwd=" << CmtSystem::pwd () 
-	   << " mode=" << Me.m_current_access
-           << endl;
-    }
-
-  if (Me.m_configure_error != "")
-    {
-      CmtMessage::error (Me.m_configure_error);
-      //      if (!Me.m_quiet) cerr << "#CMT> Error: " << Me.m_configure_error << endl;
-      return (CmtError::execution_error);
-    }
-
-  if (CmtError::has_pending_error ())
-    {
-      int code = CmtError::get_last_error_code ();
-      CmtError::print ();
-      //      if (!Me.m_quiet) CmtError::print ();
-      clear ();
-
-      return (code);
-    }
-
-  /*
-    Now actual requirements analysis can take place.
-
-    Extra lines or files are analysed first.
-  */
-
-  if (strlen (ap.extra_file.c_str ()) > 0) SyntaxParser::parse_requirements (ap.extra_file, (Use*) 0);
-  if (strlen (ap.extra_line.c_str ()) > 0) SyntaxParser::parse_requirements_line (ap.extra_line, (Use*) 0);
-
-  //
-  //  For some of the actions, the CMT package must be automatically
-  //  included
-  //
-
-  if (Me.m_debug) cout << "parser1> current_tag=" << Me.m_current_tag << endl;
-
   if (ap.help_action == action_help)
     {
-      do_help (ap);
       int code (0);
       if (CmtError::has_pending_error ())
@@ -6321,7 +6319,62 @@
 	  CmtError::print ();
 	}
+      do_help (ap);
       return code;
-      //return (0);
-    }
+    }
+
+  if (Me.m_debug)
+    {
+      cout << "After parse_argument> pack=" << Me.m_current_package
+           << " Me.m_current_tag=" << Me.m_current_tag
+           << " cwd=" << CmtSystem::pwd () 
+	   << " mode=" << Me.m_current_access
+           << endl;
+    }
+
+  if (Me.m_configure_error != "")
+    {
+      CmtMessage::error (Me.m_configure_error);
+      //      if (!Me.m_quiet) cerr << "#CMT> Error: " << Me.m_configure_error << endl;
+      return (CmtError::execution_error);
+    }
+
+  if (CmtError::has_pending_error ())
+    {
+      int code = CmtError::get_last_error_code ();
+      CmtError::print ();
+      //      if (!Me.m_quiet) CmtError::print ();
+      clear ();
+
+      return (code);
+    }
+
+  /*
+    Now actual requirements analysis can take place.
+
+    Extra lines or files are analysed first.
+  */
+
+  //  if (strlen (ap.extra_file.c_str ()) > 0) SyntaxParser::parse_requirements (ap.extra_file, (Use*) 0);
+  if (strlen (ap.extra_line.c_str ()) > 0) SyntaxParser::parse_requirements_line (ap.extra_line, (Use*) 0);
+
+  //
+  //  For some of the actions, the CMT package must be automatically
+  //  included
+  //
+
+  if (Me.m_debug) cout << "parser1> current_tag=" << Me.m_current_tag << endl;
+
+//   if (ap.help_action == action_help)
+//     {
+//       do_help (ap);
+//       int code (0);
+//       if (CmtError::has_pending_error ())
+// 	{
+// 	  code = CmtError::get_last_error_code ();
+// 	  CmtError::print ();
+// 	}
+//       return code;
+//       //return (0);
+//     }
 
   switch (Me.m_action)
@@ -6420,5 +6473,8 @@
     case action_unlock :
     case action_version :
+      if (Me.m_use_cmt)
+	{
       use_cmt ();
+	}
       //
       // Now parse the requirements file stored in ${CMTHOME}
@@ -6646,5 +6702,8 @@
 	bool w = Me.m_warnings;
 	Me.m_warnings = false;
-	reach_current_package ();
+	if (strlen (ap.extra_file.c_str ()) == 0)
+	  reach_current_package ();
+	else
+	  use_extra_file (ap.extra_file);
 	use_user_context_requirements ();
 	Me.m_warnings = w;
@@ -7764,4 +7823,141 @@
 }
 
+//----------------------------------------------------------
+int Cmt::use_extra_file (const cmt_string& file)
+{
+  if (!CmtSystem::test_file (file))
+    {
+      CmtError::set (CmtError::path_not_found, file);
+      return 0;
+    }
+
+  // (almost) Cmt::reach_current_package ()
+  Use& use = Use::current ();
+  /*
+    Try to access the package.
+  */
+
+  if (Me.m_current_package == "cmt_standalone")
+    {
+      if ((Me.m_current_path != "") && (Me.m_current_path != CmtSystem::pwd ()))
+        {
+          if (!CmtSystem::cd (Me.m_current_path))
+            {
+              CmtError::set (CmtError::package_not_found,
+                             "ReachCurrentPackage> Cannot reach the path directory");
+              return (0);
+            }
+        }
+      /*
+      if (!CmtSystem::test_file ("requirements"))
+        {
+          return (0);
+        }
+      */
+      Me.m_current_structuring_style = without_version_directory;
+    }
+  else if (Me.m_current_package != "")
+    {
+      if (!use.move_to () && !use.move_to ("", true))
+	//      if (!use.move_to ())
+        {
+          CmtError::set (CmtError::package_not_found,
+                         "ReachCurrentPackage> Cannot reach the path directory");
+	  //          return -1;
+	  return (0);
+        }
+
+      Me.m_current_path = use.real_path;
+    }
+  else
+    {
+      //
+      // The cmt command has been given without explicit search for 
+      // a package. Thus it is expected that we are in the context of a
+      // true package.
+      //
+      //  This means that there should be a requirements file visible.
+      //
+      //  If this is not true, we'll make a try into ../cmt and then
+      // a last try into ../mgr
+      //
+
+      //...
+    }
+
+  configure_current_dir ();
+  build_prefix (Me.m_current_package, Me.m_current_prefix);
+  build_config (Me.m_current_prefix, Me.m_current_config);
+
+  /*
+    Check Tag is always set up
+  */
+
+  if (Me.m_debug) cout << "use_extra_file0> current_tag=" << Me.m_current_tag << endl;
+
+  if (Me.m_current_tag == "")
+    {
+      cmt_string env;
+
+      env = CmtSystem::getenv (Me.m_current_config);
+      if (env != "")
+        {
+          Tag* tag;
+
+          tag = Tag::add (env, PriorityConfig, "reach current package", 0);
+          tag->mark ();
+	  //Me.m_current_tag = env;
+
+          //if (!Me.m_quiet) cerr << "use_extra_file1> current_tag=" << Me.m_current_tag << endl;
+
+        }
+    }
+
+  if (Me.m_debug)
+    {
+      cout << "pwd = " << CmtSystem::pwd () << endl;
+    }
+
+  /*
+    Work on the requirements file.
+  */
+
+  SyntaxParser::parse_requirements (file, &use);
+
+  if (Me.m_debug) cout << "use_extra_file2> current_tag=" << Me.m_current_tag << endl;
+
+  /**
+   *   It would be useful to change this mechanism. Instead of
+   *  applying all global patterns at once to all use contexts, it
+   *  would be much better to apply it at the end of each
+   *  requirements file parsing, and only in the context the
+   *  appropriate Use.
+   *
+   *   This would avoid the current flaw which is that when a global
+   *  pattern specifies a "private" definition, it is actually
+   *  applied in the scope context of the Current Use and not in
+   *  each individual Use. Therefore the private is lost.
+   *
+   *   However, this induces problems since some pattern definitions
+   *  are done AFTER the use statements, which will NOT receive the
+   *  pattern aplications.
+   *
+   *   Therefore it is decided to leave this "bad" mechanism until
+   *  everybody is aware of this constraint.
+   *
+   * 
+   */
+  Pattern::apply_all_globals ();
+
+  /*
+    Select all possible tags
+  */
+
+  Tag::restore_tree ();
+
+  return (1);
+}
+
+//----------------------------------------------------------
 static cmt_string get_best_form (const CmtSystem::cmt_string_vector& pwd,
                                  const cmt_string& path)
Index: CMT/HEAD/source/cmt_symbol.cxx
===================================================================
--- CMT/HEAD/source/cmt_symbol.cxx	(revision 560)
+++ CMT/HEAD/source/cmt_symbol.cxx	(revision 561)
@@ -3061,77 +3061,4 @@
 
 //-------------------------------------------------------------
-//  Quote separators (spaces and tabs) with double quotes,
-//  double quotes with single quotes,
-//  single quotes with double quotes in text.
-//  Note: quotes preceded by backslash (i.e., \" or \') are NOT quoted
-//  (considered escaped)
-//-------------------------------------------------------------
-static cmt_string quote (const cmt_string& text,
-			 const cmt_string& separators)
-{
-  //cerr << "quote: `" << text << "'" << endl;
-  cmt_string result;
-  if (text.size () == 0) return result;
-
-  int allocated = 3 * text.size (); // if EACH character of text quoted with " or '
-  char* const buffer = (char*) malloc (allocated + 1);
-  char* b (buffer);
-
-  //  char* const beg (buffer);
-  const char* p = text.c_str ();
-  const char* const text_c (p);
-  //  const char* const beg_t (p);
-  //  cerr << "quote: p = `" << p << "'" << endl;
-
-  while (*p)
-    //  while (*p != '\0')
-    {
-      size_t l_nonsep = strcspn (p, separators.c_str ());
-      //cerr << "quote: l_nonsep = " << l_nonsep << " *p = '" << *p << "'" << endl;
-      while (l_nonsep--)
-	{
-	  if (*p == '\"' &&
-	      (p > text_c && *(p - 1) != '\\' || p == text_c))
-	    { // quote " with '
-	      *b++ = '\'';
-	      *b++ = *p++;
-	      *b++ = '\'';
-	    }
-	  else if (*p == '\'' &&
-		   (p > text_c && *(p - 1) != '\\' || p == text_c))
-	    { // quote ' with "
-	      *b++ = '\"';
-	      *b++ = *p++;
-	      *b++ = '\"';
-	    }
-	  else
-	    { // simply copy
-	      *b++ = *p++;
-	    }
-	}
-      size_t l_sep = strspn (p, separators.c_str ());
-      //cerr << "quote: l_sep = " << l_sep << " *p = '" << *p << "'" << endl;
-      if (l_sep)
-	{ // quote separators with "
-	  // place quote before all backslashes preceding separators, if any
-	  char* r = b;
-	  while (r > buffer && *(r - 1) == '\\')
-	    r--;
-	  if (r == b)
-	    *b++ = '\"';
-	  else
-	    *r = '\"', *b++ = '\\';
-	  while (l_sep--)
-	    *b++ = *p++;
-	  *b++ = '\"';
-	}
-    }
-  *b = '\0';
-  result = buffer;
-  free (buffer);
-  return result;
-}
-
-//-------------------------------------------------------------
 int SymbolValueList::print (const Symbol& symbol, 
 			    const SymbolValue& value, 
@@ -3311,5 +3238,5 @@
     }
 
-  cout << " " << quote (value.text, " \t");
+  cout << " " << CmtSystem::quote (value.text, " \t");
   //  cout << "'" << value.text << "'";
           
Index: CMT/HEAD/source/cmt_syntax.cxx
===================================================================
--- CMT/HEAD/source/cmt_syntax.cxx	(revision 560)
+++ CMT/HEAD/source/cmt_syntax.cxx	(revision 561)
@@ -494,5 +494,5 @@
 	       int line_number)
   {
-    Language::action (words);
+    Language::action (words, use);
   }
   void action (const CmtSystem::cmt_string_vector& words,
Index: CMT/HEAD/source/cmt_system.cxx
===================================================================
--- CMT/HEAD/source/cmt_system.cxx	(revision 560)
+++ CMT/HEAD/source/cmt_system.cxx	(revision 561)
@@ -2172,4 +2172,77 @@
       current_word += word_length + 1;
     }
+}
+
+//-------------------------------------------------------------
+//  Quote separators (spaces and tabs) with double quotes,
+//  double quotes with single quotes,
+//  single quotes with double quotes in text.
+//  Note: quotes preceded by backslash (i.e., \" or \') are NOT quoted
+//  (considered escaped)
+//-------------------------------------------------------------
+cmt_string CmtSystem::quote (const cmt_string& text,
+			     const cmt_string& separators)
+{
+  //cerr << "quote: `" << text << "'" << endl;
+  cmt_string result;
+  if (text.size () == 0) return result;
+
+  int allocated = 3 * text.size (); // if EACH character of text quoted with " or '
+  char* const buffer = (char*) malloc (allocated + 1);
+  char* b (buffer);
+
+  //  char* const beg (buffer);
+  const char* p = text.c_str ();
+  const char* const text_c (p);
+  //  const char* const beg_t (p);
+  //  cerr << "quote: p = `" << p << "'" << endl;
+
+  while (*p)
+    //  while (*p != '\0')
+    {
+      size_t l_nonsep = strcspn (p, separators.c_str ());
+      //cerr << "quote: l_nonsep = " << l_nonsep << " *p = '" << *p << "'" << endl;
+      while (l_nonsep--)
+	{
+	  if (*p == '\"' &&
+	      (p > text_c && *(p - 1) != '\\' || p == text_c))
+	    { // quote " with '
+	      *b++ = '\'';
+	      *b++ = *p++;
+	      *b++ = '\'';
+	    }
+	  else if (*p == '\'' &&
+		   (p > text_c && *(p - 1) != '\\' || p == text_c))
+	    { // quote ' with "
+	      *b++ = '\"';
+	      *b++ = *p++;
+	      *b++ = '\"';
+	    }
+	  else
+	    { // simply copy
+	      *b++ = *p++;
+	    }
+	}
+      size_t l_sep = strspn (p, separators.c_str ());
+      //cerr << "quote: l_sep = " << l_sep << " *p = '" << *p << "'" << endl;
+      if (l_sep)
+	{ // quote separators with "
+	  // place quote before all backslashes preceding separators, if any
+	  char* r = b;
+	  while (r > buffer && *(r - 1) == '\\')
+	    r--;
+	  if (r == b)
+	    *b++ = '\"';
+	  else
+	    *r = '\"', *b++ = '\\';
+	  while (l_sep--)
+	    *b++ = *p++;
+	  *b++ = '\"';
+	}
+    }
+  *b = '\0';
+  result = buffer;
+  free (buffer);
+  return result;
 }
 
Index: CMT/HEAD/source/cmt_system.h
===================================================================
--- CMT/HEAD/source/cmt_system.h	(revision 560)
+++ CMT/HEAD/source/cmt_system.h	(revision 561)
@@ -132,4 +132,6 @@
                      const cmt_string& separators,
                      cmt_string_vector& strings);
+  static cmt_string quote (const cmt_string& text,
+			   const cmt_string& separators);
 
   static void compress_path (const cmt_string& dir, cmt_string& new_dir);
