Index: CMT/HEAD/ChangeLog
===================================================================
--- CMT/HEAD/ChangeLog	(revision 586)
+++ CMT/HEAD/ChangeLog	(revision 588)
@@ -1,2 +1,140 @@
+2011-11-27    <rybkin@lal.in2p3.fr> 465
+
+	* source/cmt_system.cxx: In function CmtSystem::remove_file, do not use
+	custom error message
+	* source/cmt_symbol.h: In class Symbol, add const qualifier to
+	check_tag_used function	argument, to resolve_macro_value function
+	* source/cmt_symbol.cxx: idem, add same actions for
+	action_build_broadcast_config as for action_build_constituents_config,
+	action_build_constituent_config
+	* source/cmt_use.h: In class Use, introduce absolute_library_path,
+	remove_library_links functions
+	* source/cmt_use.cxx: Implement introduced functions, in install_library
+	helper function, check return value of called functions, set error (rather
+	than print error message) as appropriate, implement uninstall_library
+	helper function, refactor build_library_links function to use
+	absolute_library_path
+	* source/cmt_deps_builder.h: Make m_filter member of class
+	DepsBuilder::HeaderFilter to be owned by class and cleared accordingly
+	* source/cmt_deps_builder.cxx: In header_file_action, build_deps functions
+	check return value of read function, set error as appropriate, also set
+	error if path specified for dependencies calculation not found. In class
+	DepsBuilder, run function, pass $(app_$(CONSTITUENT)_cppflags),
+	$(lib_$(CONSTITUENT)_cppflags) to external dependencies generator specified
+	via preprocessor_command macro, if any
+	* source/cmt_generators.h: In classes DocumentGenerator, LibraryGenerator,
+	in function build, introduce argument bool& dependencies, in class
+	DocumentGenerator, introduce members Variable m_FILEEXTENSION,
+	FragmentHandle dependency_fragment, in class LibraryGenerator, declare
+	specific function fill_names_outputs. Introduce class
+	PackagesMakefileGenerator, rewrite class DependencyGenerator
+	* source/cmt_generators.cxx: In class LibraryGenerator, implement
+	fill_names_outputs, in class DocumentGenerator function build, add
+	dependency_fragment for each source file with additional template
+	FILEEXTENSION (also added for fragment) so that
+	${CONSTITUENT}_dependencies.make gets rebuilt whenever source file OR its
+	dependencies change. Implement class PackagesMakefileGenerator used to
+	build BCAST mode Makefile. In class DependencyGenerator, re-implement
+	function build (const CmtSystem::cmt_string_vector&) so that it makes use
+	of files and includes from CLI input, if any, enhance its algorithm,
+	enhance	function prepare_header_file_filters so that it makes use of input
+	file dependencies[_CONSTITUENT].in without CMT
+	* source/cmt_generator.h: In class CmtGenerator, remove prepare_use_context
+	function, m_deps_builder member. In class Generator, introduce argument
+	bool& dependencies in build_constituent_makefile function, declare
+	build_library_links_infile, build_dependencies_infile,
+	build_packages_makefile functions
+	* source/cmt_generator.cxx: In class CmtGenerator function reset, reset
+	m_bin, m_output_file_name, m_output_file, m_constituent members, in class
+	Generator, implement build_library_links_infile, build_dependencies_infile,
+	build_packages_makefile functions, in class InGenerator constructor, add
+	document dependency fragment
+	* source/cmt_constituent.h: In class Constituent, change add_for_action
+	function signature
+	* source/cmt_constituent.cxx: In class Constituent, in function parse,
+	do not treat action_value variable definition specially, in function
+	add_for_action, do not assign target_<name> tag to document corresponding
+	to action by default but only if this tag is used somewhere
+	* source/cmt_commands.cxx: In class ArgParser, in function do_build,
+	introduce broadcast_config command and its options processing, enhance
+	dependencies command options processing so that it makes use of files and
+	includes from CLI input and can have global options specified mixed with
+	its options. In class CommandHelp, in constructor, add help info for
+	broadcast_config, dependencies commands
+	* source/cmt_parser.h: In enumeration ActionType, add value
+	action_build_broadcast_config
+	* source/cmt_parser.cxx: In class Cmt, in function do_broadcast, unset
+	CMTBCAST variable in environment of command(s) being broadcast to avoid
+	looping, in function do_build_constituent_config, generate dependencies
+	infile if needed only, incorporate call to do_check_configuration into
+	function do_build_constituents_config so as not	to invoke
+	cmt check configuration command in Makefile, as part of
+	do_build_constituents_config, generate library_links infile, and
+	dependencies infile for constituents without target tag, implement function
+	do_build_broadcast_config to generate broadcast Makefile, and broadcast
+	specific macros Makefile, enhance do_build_library_links function to work
+	with generated library_links infile, make function do_check_configuration
+	set error if non-constant cmtpath_pattern found for package outside CMTPATH
+	- cannot be applied, re-implement do_remove_library_links function making
+	use of remove_library_links from class Use. In function
+	fill_for_all_constituents of class StandardMacroBuilder, print warning
+	message if package requested for import cannot be imported for constituent
+	without target tag during cmt build constituents_config, otherwise during
+	cmt build constituent_config
+	* source/cmt_cmtpath_pattern.h: In class CmtPathPattern, introduce function
+	is_constant
+	* source/cmt_cmtpath_pattern.cxx: Implement is_constant function
+	* source/cmt.h: In class Cmt, introduce function do_build_broadcast_config
+	* mgr/fragments/package: Introduce fragment for broadcast Makefile
+	generation
+	* mgr/fragments/packages_header: idem
+	* mgr/fragments/packages_trailer: idem
+	* mgr/fragments/dependency: Introduce fragment for document Makefile
+	generation
+	* mgr/fragments/dependencies: Use $(build_dependencies) command with
+	dependencies infile and include directories and source files supplied
+	via CLI
+	* mgr/fragments/constituent: In QUICK mode, rebuild constituent Makefile if
+	any requirements file changes. Make constituent uninstall targets
+	independent of constituent Makefile (so that no rebuild happens before
+	uninstall), make remove_library_links dependent on constituent uninstall
+	targets to ensure library links uninstallation order
+	* mgr/fragments/constituent_lock: idem
+	* mgr/fragments/constituents_header:  In QUICK mode, run
+	$(build_library_links) command with library_links infile, if any
+	requirements file changes, keep .DEFAULT target if PEDANTIC is undefined,
+	specify explicit (with empty command) rules for requirements files for
+	optimisation
+	* mgr/fragments/constituents_trailer: In QUICK mode, run
+	$(remove_library_links) command with library_links infile,  make uninstall
+	target (rather than clean target) dependent on remove_library_links target
+	to ensure library links uninstallation
+	* mgr/fragments/make_header: Define dependencies infile for use with
+	$(build_dependencies) command
+	* mgr/fragments/cpp: Add explicit dependency on source file to
+	${CONSTITUENT}_dependencies.make
+	* mgr/fragments/cpp_library: idem
+	* mgr/fragments/c: idem
+	* mgr/fragments/c_library: idem
+	* mgr/fragments/fortran: idem
+	* mgr/fragments/fortran_library: idem
+	* mgr/fragments/lex: idem
+	* mgr/fragments/lex_library: idem
+	* mgr/fragments/yacc: idem
+	* mgr/fragments/yacc_library: idem
+	* mgr/requirements: Declare fragments package, packages_header,
+	packages_trailer, dependency
+	* src/Makefile.core: Add .in to known suffixes
+	* src/Makefile.header: Introduce and implement BCAST mode, making use of
+	cmt build broadcast_config command. In QUICK mode, rebuild constituents or
+	broadcast Makefile and corresponding macros files if any requirements file
+	changes, specify explicit (with empty command) rules for requirements files
+	for optimisation, implement dynamic help messages on targets available for
+	BCAST mode
+	* src/setup.csh: Set MAKEFLAGS, if unset, to set number of job slots to
+	number of processors, and enable CMT QUICK mode
+	* src/setup.sh: idem. Use only shell parameter expansion to determine
+	whether	shell is intercative.
+
 2011-07-06    <rybkin@lal.in2p3.fr> 464
 
Index: CMT/HEAD/mgr/fragments/c
===================================================================
--- CMT/HEAD/mgr/fragments/c	(revision 586)
+++ CMT/HEAD/mgr/fragments/c	(revision 588)
@@ -20,4 +20,6 @@
 $(bin)${CONSTITUENT}_dependencies.make : $(${NAME}_${FILESUFFIX}_dependencies)
 
+$(bin)${CONSTITUENT}_dependencies.make : ${FULLNAME}
+
 $(bin)$(binobj)${NAME}${CONSTITUENTSUFFIX}.o : $(${NAME}_${FILESUFFIX}_dependencies)
 endif
Index: CMT/HEAD/mgr/fragments/c_library
===================================================================
--- CMT/HEAD/mgr/fragments/c_library	(revision 586)
+++ CMT/HEAD/mgr/fragments/c_library	(revision 588)
@@ -20,4 +20,6 @@
 $(bin)${CONSTITUENT}_dependencies.make : $(${NAME}_${FILESUFFIX}_dependencies)
 
+$(bin)${CONSTITUENT}_dependencies.make : ${FULLNAME}
+
 $(bin)$(binobj)${NAME}${CONSTITUENTSUFFIX}.o : $(${NAME}_${FILESUFFIX}_dependencies)
 endif
Index: CMT/HEAD/mgr/fragments/constituent
===================================================================
--- CMT/HEAD/mgr/fragments/constituent	(revision 586)
+++ CMT/HEAD/mgr/fragments/constituent	(revision 588)
@@ -44,4 +44,6 @@
 endif
 
+not_${CONSTITUENT}_dependencies = { n=0; for p in $?; do m=0; for d in $(${CONSTITUENT}_dependencies); do if [ $$p = $$d ]; then m=1; break; fi; done; if [ $$m -eq 0 ]; then n=1; break; fi; done; [ $$n -eq 1 ]; }
+
 ifdef STRUCTURED_OUTPUT
 ${CONSTITUENT}dirs :
@@ -73,7 +75,8 @@
 	  $(cmtexe) -tag=$(tags) $(${CONSTITUENT}_extratags) build constituent_config -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 \
+$(cmt_local_${CONSTITUENT}_makefile) : $(${CONSTITUENT}_dependencies) $(cmt_build_library_linksstamp) $(use_requirements)
+	@if [ ! -f $@ ] || [ ! -f $(cmt_local_tagfile_${CONSTITUENT}) ] || \
+	  [ ! -f $(cmt_final_setup_${CONSTITUENT}) ] || \
+	  $(not_${CONSTITUENT}_dependencies) ; then \
 	  test -z "$(cmtmsg)" || \
 	  echo "$(CMTMSGPREFIX)" "(constituents.make) Building ${CONSTITUENT}.make"; \
@@ -89,7 +92,8 @@
 	  $(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 \
+$(cmt_local_${CONSTITUENT}_makefile) : $(${CONSTITUENT}_dependencies) $(cmt_build_library_linksstamp) $(bin)${CONSTITUENT}.in
+	@if [ ! -f $@ ] || [ ! -f $(cmt_local_tagfile_${CONSTITUENT}) ] || \
+	  [ ! -f $(cmt_final_setup_${CONSTITUENT}) ] || \
+	  $(not_${CONSTITUENT}_dependencies) ; then \
 	  test -z "$(cmtmsg)" || \
 	  echo "$(CMTMSGPREFIX)" "(constituents.make) Building ${CONSTITUENT}.make"; \
@@ -104,5 +108,8 @@
 ${CONSTITUENT} :: $(${CONSTITUENT}_dependencies) $(cmt_local_${CONSTITUENT}_makefile) dirs ${CONSTITUENT}dirs
 	$(echo) "(constituents.make) Starting ${CONSTITUENT}"
-	@$(MAKE) -f $(cmt_local_${CONSTITUENT}_makefile) ${CONSTITUENT}
+	@if test -f $(cmt_local_${CONSTITUENT}_makefile); then \
+	  $(MAKE) -f $(cmt_local_${CONSTITUENT}_makefile) ${CONSTITUENT}; \
+	  fi
+#	@$(MAKE) -f $(cmt_local_${CONSTITUENT}_makefile) ${CONSTITUENT}
 	$(echo) "(constituents.make) ${CONSTITUENT} done"
 
@@ -126,12 +133,17 @@
 	$(echo) "(constituents.make) install ${CONSTITUENT} done"
 
-uninstall :: ${CONSTITUENT}uninstall
+uninstall : ${CONSTITUENT}uninstall
 
 $(foreach d,$(${CONSTITUENT}_dependencies),$(eval $(d)uninstall_dependencies += ${CONSTITUENT}uninstall))
 
-${CONSTITUENT}uninstall :: $(${CONSTITUENT}uninstall_dependencies) $(cmt_local_${CONSTITUENT}_makefile)
+${CONSTITUENT}uninstall : $(${CONSTITUENT}uninstall_dependencies) ##$(cmt_local_${CONSTITUENT}_makefile)
 	$(echo) "(constituents.make) Starting uninstall ${CONSTITUENT}"
-	@$(MAKE) -f $(cmt_local_${CONSTITUENT}_makefile) uninstall
+	@if test -f $(cmt_local_${CONSTITUENT}_makefile); then \
+	  $(MAKE) -f $(cmt_local_${CONSTITUENT}_makefile) uninstall; \
+	  fi
+#	@$(MAKE) -f $(cmt_local_${CONSTITUENT}_makefile) uninstall
 	$(echo) "(constituents.make) uninstall ${CONSTITUENT} done"
+
+remove_library_links :: ${CONSTITUENT}uninstall
 
 ifndef PEDANTIC
Index: CMT/HEAD/mgr/fragments/constituent_lock
===================================================================
--- CMT/HEAD/mgr/fragments/constituent_lock	(revision 586)
+++ CMT/HEAD/mgr/fragments/constituent_lock	(revision 588)
@@ -44,4 +44,6 @@
 endif
 
+not_${CONSTITUENT}_dependencies = { n=0; for p in $?; do m=0; for d in $(${CONSTITUENT}_dependencies); do if [ $$p = $$d ]; then m=1; break; fi; done; if [ $$m -eq 0 ]; then n=1; break; fi; done; [ $$n -eq 1 ]; }
+
 ifdef STRUCTURED_OUTPUT
 ${CONSTITUENT}dirs :
@@ -73,7 +75,8 @@
 	  $(cmtexe) -tag=$(tags) $(${CONSTITUENT}_extratags) build constituent_config -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 \
+$(cmt_local_${CONSTITUENT}_makefile) : $(${CONSTITUENT}_dependencies) $(cmt_build_library_linksstamp) $(use_requirements)
+	@if [ ! -f $@ ] || [ ! -f $(cmt_local_tagfile_${CONSTITUENT}) ] || \
+	  [ ! -f $(cmt_final_setup_${CONSTITUENT}) ] || \
+	  $(not_${CONSTITUENT}_dependencies) ; then \
 	  test -z "$(cmtmsg)" || \
 	  echo "$(CMTMSGPREFIX)" "(constituents.make) Building ${CONSTITUENT}.make"; \
@@ -89,7 +92,8 @@
 	  $(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 \
+$(cmt_local_${CONSTITUENT}_makefile) : $(${CONSTITUENT}_dependencies) $(cmt_build_library_linksstamp) $(bin)${CONSTITUENT}.in
+	@if [ ! -f $@ ] || [ ! -f $(cmt_local_tagfile_${CONSTITUENT}) ] || \
+	  [ ! -f $(cmt_final_setup_${CONSTITUENT}) ] || \
+	  $(not_${CONSTITUENT}_dependencies) ; then \
 	  test -z "$(cmtmsg)" || \
 	  echo "$(CMTMSGPREFIX)" "(constituents.make) Building ${CONSTITUENT}.make"; \
@@ -107,5 +111,7 @@
 	  retval=$$?; \
 	  trap '${unlock_command} ${CONSTITUENT}${lock_suffix}; exit $${retval}' 1 2 15; \
+	  if test -f $(cmt_local_${CONSTITUENT}_makefile); then \
 	  $(MAKE) -f $(cmt_local_${CONSTITUENT}_makefile) ${CONSTITUENT}; \
+	  fi; \
 	  retval=$$?; ${unlock_command} ${CONSTITUENT}${lock_suffix}; exit $${retval}
 	$(echo) "(constituents.make) ${CONSTITUENT} done"
@@ -130,12 +136,17 @@
 	$(echo) "(constituents.make) install ${CONSTITUENT} done"
 
-uninstall :: ${CONSTITUENT}uninstall
+uninstall : ${CONSTITUENT}uninstall
 
 $(foreach d,$(${CONSTITUENT}_dependencies),$(eval $(d)uninstall_dependencies += ${CONSTITUENT}uninstall))
 
-${CONSTITUENT}uninstall :: $(${CONSTITUENT}uninstall_dependencies) $(cmt_local_${CONSTITUENT}_makefile)
+${CONSTITUENT}uninstall : $(${CONSTITUENT}uninstall_dependencies) ##$(cmt_local_${CONSTITUENT}_makefile)
 	$(echo) "(constituents.make) Starting uninstall ${CONSTITUENT}"
-	@$(MAKE) -f $(cmt_local_${CONSTITUENT}_makefile) uninstall
+	@if test -f $(cmt_local_${CONSTITUENT}_makefile); then \
+	  $(MAKE) -f $(cmt_local_${CONSTITUENT}_makefile) uninstall; \
+	  fi
+#	@$(MAKE) -f $(cmt_local_${CONSTITUENT}_makefile) uninstall
 	$(echo) "(constituents.make) uninstall ${CONSTITUENT} done"
+
+remove_library_links :: ${CONSTITUENT}uninstall
 
 ifndef PEDANTIC
Index: CMT/HEAD/mgr/fragments/constituents_header
===================================================================
--- CMT/HEAD/mgr/fragments/constituents_header	(revision 586)
+++ CMT/HEAD/mgr/fragments/constituents_header	(revision 588)
@@ -26,4 +26,5 @@
 #cmt_final_setup = $(bin)$(package)setup.make
 
+cmt_build_library_linksstamp = $(bin)cmt_build_library_links.stamp
 #--------------------------------------------------------
 
@@ -73,6 +74,7 @@
 
 ifndef QUICK
-all :: build_library_links
-	$(echo) "(constituents.make) all done"
+all :: build_library_links ;
+else
+all :: $(cmt_build_library_linksstamp) ;
 endif
 
@@ -88,6 +90,6 @@
 #	  if test ! -d $(bin) ; then $(mkdir) -p $(bin) ; fi
 
-requirements :
-	@if test ! -r requirements ; then echo "No requirements file" ; fi
+#requirements :
+#	@if test ! -r requirements ; then echo "No requirements file" ; fi
 
 build_library_links : dirs
@@ -97,14 +99,21 @@
 #	$(build_library_links)
 
+$(cmt_build_library_linksstamp) : $(cmt_final_setup) $(cmt_local_tagfile) $(bin)library_links.in
+	$(echo) "(constituents.make) Rebuilding library links"; \
+	 $(build_library_links) -f=$(bin)library_links.in -without_cmt
+	$(silent) \touch $@
+
 makefiles : ;
 
+ifndef PEDANTIC
 .DEFAULT ::
+#.DEFAULT :
 	$(echo) "(constituents.make) $@: No rule for such target" >&2
-#	@echo "#CMT> Warning: $@: Using default commands" >&2; exit
+endif
 
-#	@if test "$@" = "$(cmt_lock_setup)"; then \
-	#  /bin/rm -f $(cmt_lock_setup); \
-	 # touch $(cmt_lock_setup); \
-	#fi
+${CMTROOT}/src/Makefile.core : ;
+ifdef use_requirements
+$(use_requirements) : ;
+endif
 
 #-- end of constituents_header ------
Index: CMT/HEAD/mgr/fragments/constituents_trailer
===================================================================
--- CMT/HEAD/mgr/fragments/constituents_trailer	(revision 586)
+++ CMT/HEAD/mgr/fragments/constituents_trailer	(revision 588)
@@ -1,9 +1,18 @@
 #-- start of constituents_trailer ------
 
-clean :: remove_library_links
+uninstall : remove_library_links ;
+clean ::
+	$(cleanup_echo) $(cmt_build_library_linksstamp)
+	-$(cleanup_silent) \rm -f $(cmt_build_library_linksstamp)
+#clean :: remove_library_links
 
 remove_library_links ::
+ifndef QUICK
 	$(echo) "(constituents.make) Removing library links"; \
 	  $(remove_library_links)
+else
+	$(echo) "(constituents.make) Removing library links"; \
+	  $(remove_library_links) -f=$(bin)library_links.in -without_cmt
+endif
 
 makefilesclean ::
@@ -15,9 +24,3 @@
 clean :: makefilesclean
 
-binclean :: clean
-	$(echo) "(constituents.make) Removing binary directory $(bin)"
-	@if test ! "$(bin)" = "./"; then \
-	  /bin/rm -rf $(bin); \
-	fi
-
 #-- end of constituents_trailer ------
Index: CMT/HEAD/mgr/fragments/cpp
===================================================================
--- CMT/HEAD/mgr/fragments/cpp	(revision 586)
+++ CMT/HEAD/mgr/fragments/cpp	(revision 588)
@@ -20,4 +20,6 @@
 $(bin)${CONSTITUENT}_dependencies.make : $(${NAME}_${FILESUFFIX}_dependencies)
 
+$(bin)${CONSTITUENT}_dependencies.make : ${FULLNAME}
+
 $(bin)$(binobj)${NAME}${CONSTITUENTSUFFIX}.o : $(${NAME}_${FILESUFFIX}_dependencies)
 endif
Index: CMT/HEAD/mgr/fragments/cpp_library
===================================================================
--- CMT/HEAD/mgr/fragments/cpp_library	(revision 586)
+++ CMT/HEAD/mgr/fragments/cpp_library	(revision 588)
@@ -20,4 +20,6 @@
 $(bin)${CONSTITUENT}_dependencies.make : $(${NAME}_${FILESUFFIX}_dependencies)
 
+$(bin)${CONSTITUENT}_dependencies.make : ${FULLNAME}
+
 $(bin)$(binobj)${NAME}${CONSTITUENTSUFFIX}.o : $(${NAME}_${FILESUFFIX}_dependencies)
 endif
Index: CMT/HEAD/mgr/fragments/dependencies
===================================================================
--- CMT/HEAD/mgr/fragments/dependencies	(revision 586)
+++ CMT/HEAD/mgr/fragments/dependencies	(revision 588)
@@ -1,17 +1,9 @@
-#-- start of dependency ------------------
+#-- start of dependencies ------------------
 ifneq ($(MAKECMDGOALS),${CONSTITUENT}clean)
 ifneq ($(MAKECMDGOALS),uninstall)
 
-#$(bin)${CONSTITUENT}_dependencies.make :: dirs
-
-ifndef QUICK
-$(bin)${CONSTITUENT}_dependencies.make : ${LINE} $(use_requirements) $(cmt_final_setup_${CONSTITUENT})
-else
-$(bin)${CONSTITUENT}_dependencies.make :
-endif
+$(bin)${CONSTITUENT}_dependencies.make : $(use_requirements) $(cmt_final_setup_${CONSTITUENT})
 	$(echo) "(${CONSTITUENT}.make) Rebuilding $@"; \
-	  $(build_dependencies) ${CONSTITUENT} -all_sources -out=$@ ${LINE}
-
-#$(${CONSTITUENT}_dependencies)
+	  $(build_dependencies) -out=$@ -start_all ${LINE} -end_all $(includes) $(app_${CONSTITUENT}_cppflags) $(lib_${CONSTITUENT}_cppflags) ${CONSTITUENT} $? -f=$(cmt_dependencies_in_${CONSTITUENT}) -without_cmt
 
 -include $(bin)${CONSTITUENT}_dependencies.make
@@ -19,3 +11,3 @@
 endif
 endif
-#-- end of dependency -------------------
+#-- end of dependencies -------------------
Index: CMT/HEAD/mgr/fragments/dependency
===================================================================
--- CMT/HEAD/mgr/fragments/dependency	(revision 588)
+++ CMT/HEAD/mgr/fragments/dependency	(revision 588)
@@ -0,0 +1,11 @@
+#-- start of dependency ------------------
+ifneq ($(MAKECMDGOALS),${CONSTITUENT}clean)
+ifneq ($(MAKECMDGOALS),uninstall)
+
+$(bin)${CONSTITUENT}_dependencies.make : $(${NAME}_${FILEEXTENSION}_dependencies)
+
+$(bin)${CONSTITUENT}_dependencies.make : ${FULLNAME}
+
+endif
+endif
+#-- end of dependency -------------------
Index: CMT/HEAD/mgr/fragments/fortran
===================================================================
--- CMT/HEAD/mgr/fragments/fortran	(revision 586)
+++ CMT/HEAD/mgr/fragments/fortran	(revision 588)
@@ -2,4 +2,6 @@
 
 $(bin)${CONSTITUENT}_dependencies.make : $(${NAME}_${FILESUFFIX}_dependencies)
+
+$(bin)${CONSTITUENT}_dependencies.make : ${FULLNAME}
  
 $(bin)${NAME}${CONSTITUENTSUFFIX}.o : $(${NAME}_${FILESUFFIX}_dependencies)
Index: CMT/HEAD/mgr/fragments/fortran_library
===================================================================
--- CMT/HEAD/mgr/fragments/fortran_library	(revision 586)
+++ CMT/HEAD/mgr/fragments/fortran_library	(revision 588)
@@ -2,4 +2,6 @@
 
 $(bin)${CONSTITUENT}_dependencies.make : $(${NAME}_${FILESUFFIX}_dependencies)
+
+$(bin)${CONSTITUENT}_dependencies.make : ${FULLNAME}
  
 $(bin)$(binobj)${NAME}${CONSTITUENTSUFFIX}.o : $(${NAME}_${FILESUFFIX}_dependencies)
Index: CMT/HEAD/mgr/fragments/lex
===================================================================
--- CMT/HEAD/mgr/fragments/lex	(revision 586)
+++ CMT/HEAD/mgr/fragments/lex	(revision 588)
@@ -2,4 +2,6 @@
 
 $(bin)${CONSTITUENT}_dependencies.make : $(${NAME}_${FILESUFFIX}_dependencies)
+
+$(bin)${CONSTITUENT}_dependencies.make : ${FULLNAME}
 
 $(bin)${NAME}${CONSTITUENTSUFFIX}.o : $(${NAME}_${FILESUFFIX}_dependencies)
Index: CMT/HEAD/mgr/fragments/lex_library
===================================================================
--- CMT/HEAD/mgr/fragments/lex_library	(revision 586)
+++ CMT/HEAD/mgr/fragments/lex_library	(revision 588)
@@ -2,4 +2,6 @@
 
 $(bin)${CONSTITUENT}_dependencies.make : $(${NAME}_${FILESUFFIX}_dependencies)
+
+$(bin)${CONSTITUENT}_dependencies.make : ${FULLNAME}
 
 $(bin)$(binobj)${NAME}${CONSTITUENTSUFFIX}.o : $(${NAME}_${FILESUFFIX}_dependencies)
Index: CMT/HEAD/mgr/fragments/make_header
===================================================================
--- CMT/HEAD/mgr/fragments/make_header	(revision 586)
+++ CMT/HEAD/mgr/fragments/make_header	(revision 588)
@@ -46,4 +46,5 @@
 
 cmt_final_setup_${CONSTITUENT} = $(bin)setup_${CONSTITUENT}.make
+cmt_dependencies_in_${CONSTITUENT} = $(bin)dependencies_${CONSTITUENT}.in
 #cmt_final_setup_${CONSTITUENT} = $(bin)${PACKAGE}_${CONSTITUENT}setup.make
 cmt_local_${CONSTITUENT}_makefile = $(bin)${CONSTITUENT}.make
@@ -52,4 +53,5 @@
 
 cmt_final_setup_${CONSTITUENT} = $(bin)setup.make
+cmt_dependencies_in_${CONSTITUENT} = $(bin)dependencies.in
 #cmt_final_setup_${CONSTITUENT} = $(bin)${PACKAGE}setup.make
 cmt_local_${CONSTITUENT}_makefile = $(bin)${CONSTITUENT}.make
@@ -83,4 +85,5 @@
 endif
 
+${CMTROOT}/src/Makefile.core : ;
 ifdef use_requirements
 $(use_requirements) : ;
Index: CMT/HEAD/mgr/fragments/package
===================================================================
--- CMT/HEAD/mgr/fragments/package	(revision 588)
+++ CMT/HEAD/mgr/fragments/package	(revision 588)
@@ -0,0 +1,105 @@
+
+cmt_${PACKAGE}_${ISLOCAL} = 1
+
+${PACKAGE}FullName=${PACKAGEFULLNAME}
+${PACKAGE}MgrPath=${PACKAGEMGRPATH}
+
+ifdef LOG_LOCATION
+ifdef cmt_${PACKAGE}_is_local
+${PACKAGE}OutErr = >>$(LOG_LOCATION)/$(${PACKAGE}FullName)$(LOG_SUFFIX) 2>&1
+else
+ifdef BCAST_GLOBAL
+${PACKAGE}OutErr = >>$(LOG_LOCATION)/$(${PACKAGE}FullName)$(LOG_SUFFIX) 2>&1
+endif
+endif
+endif
+
+ifndef BCAST_ONLY
+${PACKAGE} : ${DEPENDENCIES} $(${PACKAGE}MgrPath)/Makefile
+else
+${PACKAGE} : $(${PACKAGE}MgrPath)/Makefile
+endif
+ifdef cmt_${PACKAGE}_is_local
+	@echo "#--------------------------------------------------------------" \
+	  && echo "# Now trying [$(BCAST_CMD)] in $(${PACKAGE}MgrPath)" \
+	  && echo "#--------------------------------------------------------------"
+ifdef LOG_LOCATION
+	$(silent) touch $(LOG_LOCATION)/$(${PACKAGE}FullName)$(LOG_SUFFIX)
+	@{ echo "#--------------------------------------------------------------" \
+	  && echo "# Now trying [$(BCAST_CMD)] in $(${PACKAGE}MgrPath)" \
+	  && echo "#--------------------------------------------------------------"; } $(${PACKAGE}OutErr)
+endif
+ifdef NO_ALL_GROUPS
+	+$(silent) cd $(${PACKAGE}MgrPath) && $(BCAST_CMD) $(${PACKAGE}OutErr)
+else
+	+$(silent) cd $(${PACKAGE}MgrPath) && \
+	  for group in all $$($(cmtexe) show groups); do \
+	    $(Cmt_actions_handler) \
+	    $(BCAST_CMD) $$group $(${PACKAGE}OutErr); BUILD_RESULT=$$? ; \
+	    $(Package_failure_handler) \
+	  done
+endif
+else
+ifdef BCAST_GLOBAL
+	@echo "#--------------------------------------------------------------" \
+	  && echo "# Now trying [$(BCAST_CMD)] in $(${PACKAGE}MgrPath)" \
+	  && echo "#--------------------------------------------------------------"
+ifdef LOG_LOCATION
+	$(silent) touch $(LOG_LOCATION)/$(${PACKAGE}FullName)$(LOG_SUFFIX)
+	@{ echo "#--------------------------------------------------------------" \
+	  && echo "# Now trying [$(BCAST_CMD)] in $(${PACKAGE}MgrPath)" \
+	  && echo "#--------------------------------------------------------------"; } $(${PACKAGE}OutErr)
+endif
+ifdef NO_ALL_GROUPS
+	+$(silent) cd $(${PACKAGE}MgrPath) && $(BCAST_CMD) $(${PACKAGE}OutErr)
+else
+	+$(silent) cd $(${PACKAGE}MgrPath) && \
+	  for group in all $$($(cmtexe) show groups); do \
+	    $(Cmt_actions_handler) \
+	    $(BCAST_CMD) $$group $(${PACKAGE}OutErr); BUILD_RESULT=$$? ; \
+	    $(Package_failure_handler) \
+	  done
+endif
+else
+	
+endif
+endif
+
+$(${PACKAGE}MgrPath)/Makefile :
+ifdef cmt_${PACKAGE}_is_local
+	$(echo) configuring ${PACKAGE}
+	+$(silent) cd $(${PACKAGE}MgrPath) && $(cmtexe) config
+else
+ifdef BCAST_GLOBAL
+	$(echo) configuring ${PACKAGE}
+	+$(silent) cd $(${PACKAGE}MgrPath) && $(cmtexe) config
+else
+	
+endif
+endif
+
+ifndef BCAST_ONLY
+all : ${PACKAGE}
+clean : ${PACKAGE}clean
+binclean : ${PACKAGE}binclean
+uninstall : ${PACKAGE}uninstall
+endif
+
+${PACKAGE}clean ${PACKAGE}binclean ${PACKAGE}uninstall : $(${PACKAGE}MgrPath)/Makefile
+ifdef cmt_${PACKAGE}_is_local
+	@echo "#--------------------------------------------------------------" \
+	  && echo "# Now trying [$(BCAST_CMD) $(patsubst ${PACKAGE}%,%,$@)] in $(${PACKAGE}MgrPath)" \
+	  && echo "#--------------------------------------------------------------"
+	+$(silent) cd $(${PACKAGE}MgrPath) && $(BCAST_CMD) $(patsubst ${PACKAGE}%,%,$@)
+else
+ifdef BCAST_GLOBAL
+	@echo "#--------------------------------------------------------------" \
+	  && echo "# Now trying [$(BCAST_CMD) $(patsubst ${PACKAGE}%,%,$@)] in $(${PACKAGE}MgrPath)" \
+	  && echo "#--------------------------------------------------------------"
+	+$(silent) cd $(${PACKAGE}MgrPath) && $(BCAST_CMD) $(patsubst ${PACKAGE}%,%,$@)
+else
+	
+endif
+endif
+
+${PACKAGE} ${PACKAGE}clean ${PACKAGE}binclean ${PACKAGE}uninstall : FORCE
Index: CMT/HEAD/mgr/fragments/packages_header
===================================================================
--- CMT/HEAD/mgr/fragments/packages_header	(revision 588)
+++ CMT/HEAD/mgr/fragments/packages_header	(revision 588)
@@ -0,0 +1,60 @@
+#-- start of packages_header ------
+
+include ${CMTROOT}/src/Makefile.core
+
+ifndef BCAST_CMD
+BCAST_CMD = $(cmtexe) make
+endif
+
+ifdef LOG_LOCATION
+LOG_SUFFIX = .log
+endif
+
+ifndef CMTACTIONS
+Cmt_actions_handler = test "$$group" != cmt_actions || continue ;
+else
+Cmt_actions_handler =
+endif
+
+# -- Special macro to change the behavior on a failure of a package
+#    (complementary to the option '-k')
+#  Allowed values for PACKAGE_FAILURE_POLICY:
+#    stop:   do not continue (default)
+#    skip:   if a group fails, continue with the next package
+#    ignore: try all the groups even if one fails before going to the next package
+#            (may result in duplicated errors within a package)
+# Taken from https://svnweb.cern.ch/trac/gaudi/browser/Gaudi/trunk/Makefile.cmt
+Package_failure_handler = test $$BUILD_RESULT -eq 0 || exit $$BUILD_RESULT ;
+ifdef PACKAGE_FAILURE_POLICY
+ifeq ($(PACKAGE_FAILURE_POLICY),stop)
+Package_failure_handler = test $$BUILD_RESULT -eq 0 || exit $$BUILD_RESULT ;
+else
+ifeq ($(PACKAGE_FAILURE_POLICY),skip)
+Package_failure_handler = test $$BUILD_RESULT -eq 0 || break ;
+else
+ifeq ($(PACKAGE_FAILURE_POLICY),ignore)
+Package_failure_handler =
+else
+$(error Unknown PACKAGE_FAILURE_POLICY "$(PACKAGE_FAILURE_POLICY)". Allowed values: "stop" (default), "skip", "ignore")
+endif
+endif
+endif
+endif
+# --
+
+all : ;
+
+ifdef BCAST_ONLY
+all : ${PACKAGE}
+clean : ${PACKAGE}clean
+binclean : ${PACKAGE}binclean
+uninstall : ${PACKAGE}uninstall
+endif
+#--------------------------------------------------------
+
+ifndef PEDANTIC
+.DEFAULT :
+	$(echo) "(uses.make) $@: No rule for such target" >&2
+endif
+
+#-- end of packages_header ------
Index: CMT/HEAD/mgr/fragments/packages_trailer
===================================================================
--- CMT/HEAD/mgr/fragments/packages_trailer	(revision 588)
+++ CMT/HEAD/mgr/fragments/packages_trailer	(revision 588)
@@ -0,0 +1,16 @@
+#-- start of packages_trailer ------
+
+clean uninstall : ;
+
+binclean : FORCE
+ifndef BCAST_ONLY
+ifdef CMTINSTALLAREA
+	$(silent) $(RM) -r $(CMTINSTALLAREA)/$(CMTCONFIG)
+endif
+ifdef LOG_LOCATION
+	$(silent) \find $(LOG_LOCATION) -type f -name '*$(LOG_SUFFIX)' -exec $(RM) '{}' +
+endif
+endif
+
+FORCE :
+#-- end of packages_trailer ------
Index: CMT/HEAD/mgr/fragments/yacc
===================================================================
--- CMT/HEAD/mgr/fragments/yacc	(revision 586)
+++ CMT/HEAD/mgr/fragments/yacc	(revision 588)
@@ -2,4 +2,6 @@
 
 $(bin)${CONSTITUENT}_dependencies.make : $(${NAME}_${FILESUFFIX}_dependencies)
+
+$(bin)${CONSTITUENT}_dependencies.make : ${FULLNAME}
 
 $(bin)${NAME}${CONSTITUENTSUFFIX}.o : $(${NAME}_${FILESUFFIX}_dependencies)
Index: CMT/HEAD/mgr/fragments/yacc_library
===================================================================
--- CMT/HEAD/mgr/fragments/yacc_library	(revision 586)
+++ CMT/HEAD/mgr/fragments/yacc_library	(revision 588)
@@ -2,4 +2,6 @@
 
 $(bin)${CONSTITUENT}_dependencies.make : $(${NAME}_${FILESUFFIX}_dependencies)
+
+$(bin)${CONSTITUENT}_dependencies.make : ${FULLNAME}
 
 $(bin)$(binobj)${NAME}${CONSTITUENTSUFFIX}.o : $(${NAME}_${FILESUFFIX}_dependencies)
Index: CMT/HEAD/mgr/requirements
===================================================================
--- CMT/HEAD/mgr/requirements	(revision 586)
+++ CMT/HEAD/mgr/requirements	(revision 588)
@@ -588,6 +588,11 @@
 make_fragment constituents_trailer
 
+make_fragment packages_header
+make_fragment package
+make_fragment packages_trailer
+
 make_fragment dependencies
 make_fragment dependencies_and_triggers
+make_fragment dependency
 
 make_fragment readme_header
Index: CMT/HEAD/source/cmt.h
===================================================================
--- CMT/HEAD/source/cmt.h	(revision 586)
+++ CMT/HEAD/source/cmt.h	(revision 588)
@@ -111,4 +111,5 @@
   static void do_build_constituents_makefile (const ArgParser& ap);
   static void do_build_constituents_config (const ArgParser& ap);
+  static void do_build_broadcast_config (const ArgParser& ap);
   static void do_build_dependencies (const ArgParser& ap,
                                      int argc,
Index: CMT/HEAD/source/cmt_cmtpath_pattern.cxx
===================================================================
--- CMT/HEAD/source/cmt_cmtpath_pattern.cxx	(revision 586)
+++ CMT/HEAD/source/cmt_cmtpath_pattern.cxx	(revision 588)
@@ -278,2 +278,7 @@
 }
 
+bool CmtPathPattern::is_constant () const
+{
+  return ((line.find ("<path>") == cmt_string::npos) &&
+	  (line.find ("<project>") == cmt_string::npos));
+}
Index: CMT/HEAD/source/cmt_cmtpath_pattern.h
===================================================================
--- CMT/HEAD/source/cmt_cmtpath_pattern.h	(revision 586)
+++ CMT/HEAD/source/cmt_cmtpath_pattern.h	(revision 588)
@@ -35,4 +35,5 @@
   void apply () const;
   void expand (cmt_string& line, const cmt_string& path, const cmt_string& project) const;
+  bool is_constant () const;
 
   cmt_string line;
Index: CMT/HEAD/source/cmt_commands.cxx
===================================================================
--- CMT/HEAD/source/cmt_commands.cxx	(revision 586)
+++ CMT/HEAD/source/cmt_commands.cxx	(revision 588)
@@ -694,15 +694,68 @@
 	    }
 	}
+      else if (arg == "broadcast_config")
+	{
+	  cmt.m_action = action_build_broadcast_config;
+
+	  if (cmt.m_scope_filtering_mode == default_filtering_mode)
+	    {
+	      cmt.m_scope_filtering_mode = reach_private_uses;
+	    }
+
+	  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 == "dependencies")
 	{
 	  if (argc > 0)
 	    {
-	      fill_arguments ();
+	      //	      fill_arguments ();
+	      while (argc > 0)
+		{
+		  cmt_string arg(argv[0]);
+		  if (arg.substr (0, 3) == "-f=")
+		    {
+		      shift ();
+		      extra_file = arg.substr (3);
+		    }
+		  else if (arg.substr (0, 3) == "-e=")
+		    {
+		      shift ();
+		      extra_line = arg.substr (3);
+		    }
+		  else if (arg == "-with_cmt")
+		    {
+		      shift ();
+		      cmt.m_use_cmt = true;
+		    }
+		  else if (arg == "-without_cmt")
+		    {
+		      shift ();
+		      cmt.m_use_cmt = false;
+		    }
+		  else
+		    {
+		      fill_one_argument ();
+		    }
+		}  
 	      cmt.m_action = action_build_dependencies;
 	    }
 	  else
 	    {
-	      CmtMessage::error ("syntax: arguments missing");
+	      //CmtMessage::error ("syntax: arguments missing");
 	      //	      if (!cmt.m_quiet) cerr << "#CMT> syntax error : arguments missing " << endl;
+	      CmtError::set (CmtError::syntax_error, "arguments missing");
 	      help_action = action_help;
 	      cmt.m_action = action_build_dependencies;
@@ -2309,5 +2362,5 @@
 void CommandHelp::show (ActionType action)
 {
-  //cerr << "CommandHelp::show> action = " << action << endl;
+  //  cerr << "CommandHelp::show> action = " << action << endl;
 
   static HelpTexts& help_texts = get_help_texts ();
@@ -2375,5 +2428,6 @@
   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 broadcast_config [-out=<path>] : generate broadcast Makefile, and broadcast specific macros Makefile";
+  help_texts.add () =  "build dependencies [-out=<path>] [-all_sources] [-no_stamps] [-I<directory>]... [-start_all FILE... -end_all] NAME FILE... : generate dependencies for FILEs of constituent NAME";
   help_texts.add () =  "build library_links     : build symbolic links towards all imported libraries";
   help_texts.add () =  "build make_setup        : build a compiled version of setup scripts";
@@ -2477,4 +2531,5 @@
   help.add (action_build_constituents_makefile, help_texts[action_build_constituents_makefile]);
   help.add (action_build_constituents_config, help_texts[action_build_constituents_config]);
+  help.add (action_build_broadcast_config, help_texts[action_build_broadcast_config]);
   help.add (action_build_dependencies, help_texts[action_build_dependencies]);
   help.add (action_build_library_links, help_texts[action_build_library_links]);
Index: CMT/HEAD/source/cmt_constituent.cxx
===================================================================
--- CMT/HEAD/source/cmt_constituent.cxx	(revision 586)
+++ CMT/HEAD/source/cmt_constituent.cxx	(revision 588)
@@ -47,4 +47,5 @@
       if (symbol.type != Symbol::SymbolAction) continue;
 
+      /*
       if (symbol.value_lists.size () < 1) continue;
 
@@ -55,4 +56,6 @@
 	  add_for_action (symbol.name);
 	}
+      */
+      add_for_action (symbol);
     }
 
@@ -368,10 +371,10 @@
       //cerr << "Constituent " << name << " Analyzing module " << ew << endl;
 
-      if (ew.substr (0, 13) == "action_value=")
-	{
-          it.set (ew);
-	}
-      else
-	{
+//       if (ew.substr (0, 13) == "action_value=")
+// 	{
+//           it.set (ew);
+// 	}
+//       else
+// 	{
 	  CmtSystem::split (ew, " \t", ws);
 
@@ -383,5 +386,5 @@
 	      it.set (w);
 	    }
-	}
+// 	}
     }
 
@@ -417,18 +420,35 @@
 
 //----------------------------------------------------------
-Constituent* Constituent::add_for_action (const cmt_string& name)
-{
-  Constituent* constituent;
-
-  constituent = add (Document, name, "cmt_action_runner");
+Constituent* Constituent::add_for_action (const Symbol& symbol)
+//Constituent* Constituent::add_for_action (const cmt_string& name)
+{
+  Constituent* constituent (0);
+  if (symbol.value_lists.size () < 1) return constituent;
+
+  const Tag* tag = Tag::find ("target_" + symbol.name);
+  const bool target_tag_used
+    (Tag::check_tag_used (tag) || Symbol::check_tag_used (tag));
+
+  cmt_string value = symbol.build_macro_value ();
+  if ( "" == value && !target_tag_used) return constituent;
+
+  constituent = add (Document, symbol.name, "cmt_action_runner");
 
   constituent->group = Group::add ("cmt_actions");
-  constituent->has_target_tag = true;
+
+  // Do NOT assign target_<name> by default
+  // but only if this tag is used somewhere
+  if (target_tag_used)
+    constituent->has_target_tag = true;
 
   cmt_string& p1 = constituent->parameters.add ();
   p1 = "action_value=";
-  p1 += "$(";
-  p1 += name;
-  p1 += ")";
+  Symbol::expand (value);
+  // quote since split will later be applied
+  // - in parse
+  p1 += CmtSystem::quote (value, " \t");
+//   p1 += "$(";
+//   p1 += symbol.name;
+//   p1 += ")";
 
   return (constituent);
@@ -549,5 +569,6 @@
   if (!simulation)
     {
-      Generator::build_constituent_makefile (*this);
+      bool dependencies (false);
+      Generator::build_constituent_makefile (*this, dependencies);
     }
 }
Index: CMT/HEAD/source/cmt_constituent.h
===================================================================
--- CMT/HEAD/source/cmt_constituent.h	(revision 586)
+++ CMT/HEAD/source/cmt_constituent.h	(revision 588)
@@ -23,5 +23,6 @@
                            const cmt_string& name,
                            const cmt_string& generator);
-  static Constituent* add_for_action (const cmt_string& name);
+  static Constituent* add_for_action (const Symbol& action);
+  //static Constituent* add_for_action (const cmt_string& name);
   static void show (const cmt_string& name);
   static void parse_all ();
Index: CMT/HEAD/source/cmt_deps_builder.cxx
===================================================================
--- CMT/HEAD/source/cmt_deps_builder.cxx	(revision 586)
+++ CMT/HEAD/source/cmt_deps_builder.cxx	(revision 588)
@@ -11,4 +11,5 @@
 #include "cmt_symbol.h"
 #include "cmt_log.h"
+#include "cmt_error.h"
 
 //
@@ -92,4 +93,5 @@
         {
           cmt_string stamp_file;
+	  log << "|header_file_action> header " << header_file_path << " against stamp " << stamp_file << log_endl;
           if (header_filters[i].use_stamp (header_file_path, stamp_file))
             {
@@ -113,5 +115,9 @@
 ///////////////////////////////////////////////////////////////////////////////////////////////////////
   cmt_string text;
-  text.read (header_file_path);
+  if (!text.read (header_file_path))
+    {
+      CmtError::set (CmtError::file_access_error, header_file_path);
+      return;
+    }
   char* ptr = &text[0];
   cmt_string new_dir;
@@ -725,5 +731,9 @@
     {
       cmt_string text;
-      text.read (full_name);
+      if (!text.read (full_name))
+	{
+	  CmtError::set (CmtError::file_access_error, full_name);
+	  return -2;
+	}
       char* ptr = &text[0];
       cmt_string new_dir;
@@ -746,4 +756,5 @@
     {
       log << "CMT> build_deps3" << log_endl;
+      CmtError::set (CmtError::path_not_found, name);
     }
   return path_index;
@@ -811,4 +822,14 @@
 
 //--------------------------------------------------------------------------
+DepsBuilder::DepsBuilder ()
+{ }
+
+//--------------------------------------------------------------------------
+DepsBuilder::~DepsBuilder ()
+{
+  clear ();
+}
+
+//--------------------------------------------------------------------------
 void DepsBuilder::clear ()
 {
@@ -820,4 +841,6 @@
     }
   m_header_filters.clear ();
+  m_deps.clear ();
+  m_all_deps.clear ();
 }
 
@@ -829,15 +852,17 @@
       return;
     }
+
+  cmt_string p = path;
   if (path[path.size () - 1] == CmtSystem::file_separator ())
     {
-      cmt_string p = path;
-      p.erase (path.size () - 1);
-      m_include_paths.push_back (p);
-    }
-  else
-    {
-      m_include_paths.push_back (path);
-    }
-
+      p = path.substr(0, path.size () - 1);
+    }
+  for (int k = m_include_paths.size () - 1; k >= 0; k--)
+    if (m_include_paths[k] == p)
+      {
+	return;
+      }
+  
+  m_include_paths.push_back (p);
   m_substitutions.push_back (substitution);
 }
@@ -919,9 +944,11 @@
 
 //--------------------------------------------------------------------------
-CmtSystem::cmt_string_vector& DepsBuilder::run (const cmt_string& file_name)
+CmtSystem::cmt_string_vector& DepsBuilder::run (const cmt_string& file_name,
+						const cmt_string& constituent_name)
 {
   Log;
 
   log << "Starting deps builder on " << file_name << log_endl;
+  CmtMessage::info ("calculating dependencies for " + file_name);
 
   m_deps.clear ();
@@ -974,7 +1001,23 @@
       // missing)
       //
-      preprocessor += " ";
       macro = Symbol::find ("includes");
-      preprocessor += macro->resolve_macro_value ();
+      if (0 != macro)
+	{
+	  preprocessor += " ";
+	  preprocessor += macro->resolve_macro_value ();
+	}
+      macro = Symbol::find ("app_" + constituent_name + "_cppflags");
+      if (0 != macro)
+	{
+	  preprocessor += " ";
+	  preprocessor += macro->resolve_macro_value ();
+	}
+      macro = Symbol::find ("lib_" + constituent_name + "_cppflags");
+      if (0 != macro)
+	{
+	  preprocessor += " ";
+	  preprocessor += macro->resolve_macro_value ();
+	}
+      
       preprocessor += " ";
       preprocessor += file_name;
@@ -982,5 +1025,10 @@
       cmt_string output;
       
-      CmtSystem::execute (preprocessor, output);
+      int status = CmtSystem::execute (preprocessor, output);
+      if (0 != status)
+	{
+	  CmtError::set (CmtError::execution_failed, preprocessor, status);
+	  return m_deps;
+	}
 
       //
@@ -1041,5 +1089,5 @@
 
 //--------------------------------------------------------------------------
-void DepsBuilder::add_header_filter (const Use* use, const cmt_regexp* filter, const cmt_string& stamp)
+void DepsBuilder::add_header_filter (const Use* use, cmt_regexp* filter, const cmt_string& stamp)
 {
   add_header_filter (HeaderFilter (use, filter, stamp));
Index: CMT/HEAD/source/cmt_deps_builder.h
===================================================================
--- CMT/HEAD/source/cmt_deps_builder.h	(revision 586)
+++ CMT/HEAD/source/cmt_deps_builder.h	(revision 588)
@@ -23,5 +23,5 @@
       : m_use (0), m_filter (0) { }
 
-    HeaderFilter (const Use* use, const cmt_regexp* filter, const cmt_string& stamp)
+    HeaderFilter (const Use* use, cmt_regexp* filter, const cmt_string& stamp)
       : m_use (use), m_filter (filter), m_stamp (stamp) { }
 
@@ -38,5 +38,9 @@
       {
         m_use = 0;
-        if (m_filter) delete m_filter;
+        if (m_filter) 
+	  {
+	    m_filter->clear ();
+	    delete m_filter;
+	  }
         m_filter = 0;
         m_stamp = cmt_string (); 
@@ -46,5 +50,5 @@
 
     const Use* m_use;
-    const cmt_regexp* m_filter;
+    cmt_regexp* m_filter;
     cmt_string m_stamp;
   };
@@ -55,20 +59,20 @@
   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 Use* use, cmt_regexp* filter, const cmt_string& stamp);
   void add_header_filter (const HeaderFilter& hf);
-  CmtSystem::cmt_string_vector& run (const cmt_string& file_name);
+  CmtSystem::cmt_string_vector& run (const cmt_string& file_name,
+				     const cmt_string& constituent_name);
 
-  DepsBuilder ()
-    { }
+  DepsBuilder ();
+  ~DepsBuilder ();
 
 private:
 
-  DepsBuilder (const DepsBuilder&)
-    { }
+  DepsBuilder (const DepsBuilder&);
+  DepsBuilder& operator = (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;
   CmtSystem::cmt_string_vector m_all_deps;
Index: CMT/HEAD/source/cmt_generator.cxx
===================================================================
--- CMT/HEAD/source/cmt_generator.cxx	(revision 586)
+++ CMT/HEAD/source/cmt_generator.cxx	(revision 588)
@@ -19,4 +19,6 @@
 #include "cmt_log.h"
 #include "cmt_error.h"
+
+#include "cmt_install_area.h"
 
 //------------------------------------------------------------------------
@@ -143,4 +145,8 @@
 
   m_source_files.clear ();
+  m_bin = "";
+  m_output_file_name = "";
+  m_output_file = 0;
+  m_constituent = 0;
 
   Language::setup_all_fragments ();
@@ -350,5 +356,5 @@
       if (Cmt::get_debug ())
         {
-          cout << "CmtGenerator::fill_names_ outputs>" << endl;
+          cout << "CmtGenerator::fill_names_outputs>" << endl;
 	  cout << "name=" << name << " LINE=" << m_LINE << endl;
 	  cout << "output=" << output << " OBJS=" << m_OBJS << endl;
@@ -399,4 +405,5 @@
 }
 
+/*
 //--------------------------------------------------
 void CmtGenerator::prepare_use_context ()
@@ -476,5 +483,5 @@
     }
 }
-
+*/
 //--------------------------------------------------
 void CmtGenerator::filter_path (cmt_string& text)
@@ -700,4 +707,5 @@
 static MakeSetupGenerator MakeSetupContext;
 static ConstituentsMakefileGenerator ConstituentsMakefileContext;
+static PackagesMakefileGenerator PackagesMakefileContext;
 static DependencyGenerator DependencyContext;
 
@@ -813,5 +821,417 @@
 
 //--------------------------------------------------
+int Generator::build_library_links_infile (const cmt_string& outdir)
+{
+#ifndef WIN32
+  cmt_string file ("library_links.in");
+  if (outdir != "")
+    {
+      if (outdir [outdir.size () - 1] != CmtSystem::file_separator ())
+	file = outdir + CmtSystem::file_separator () + file;
+      else
+	file = outdir + file;
+    }
+
+  bool wrote (false);
+  ostringstream ls;
+
+  Use::UsePtrVector& Uses = Use::get_ordered_uses ();
+  Use& current_use = Use::current ();
+  Use::UsePtrVector uses (Uses);
+  uses.push_back (&Use::current ());
+
+  cmt_string shlibsuffix;
+  {
+    Symbol* macro = Symbol::find ("shlibsuffix");
+    if (macro == 0)
+      {
+	CmtError::set(CmtError::configuration_error, "shlibsuffix undefined");
+	return -1;
+      }
+    shlibsuffix = macro->build_macro_value ();
+    Symbol::expand (shlibsuffix);
+  }
+
+  for (int i = 0; i < uses.size (); i++)
+    {
+      Use* use = uses[i];
+
+      if (use == 0) continue;
+      if (use->discarded) continue;
+      if (use->m_hidden) continue;
+
+      if (use->get_package_name () == "CMT") continue;
+      if (!use->located ()) continue;
+      //use->remove_library_links (cmtinstallarea, tag, shlibsuffix, symunlinkcmd);
+      cmt_string s (use->get_package_name ());
+      s += "_libraries";
+      const Symbol* libraries_macro = Symbol::find (s);
+      if (libraries_macro == 0) continue;
+      cmt_string libraries = libraries_macro->build_macro_value ();
+      Symbol::expand (libraries);
+      static CmtSystem::cmt_string_vector values;
+      
+      CmtSystem::split (libraries, " \t", values);
+      
+      for (int j = 0; j < values.size (); j++)
+	{
+	  const cmt_string& library = values[j];
+	  
+	  static cmt_string libname;
+	  static cmt_string name;
+	  
+	  // Is it a simple name or a complete path?
+	  
+	  libname = library;
+	  Symbol::expand (libname);
+	  if (0 == libname.size ()) continue;
+	  
+	  CmtSystem::cmt_string_vector paths;
+	  use->absolute_library_path (libname,
+				      shlibsuffix, 
+				      paths);
+	  for (int k = 0; k < paths.size (); k++)
+	    {
+	      cmt_string path (paths[k]);
+	      Symbol::expand (path);
+	      if (0 == path.size ()) continue;
+	      if (wrote) ls << " ";
+	      else wrote = true;
+	      ls << CmtSystem::quote (path, " \t");
+	    }
+	}
+    }
+  ostringstream os;
+  if (wrote)
+    {
+      os << "macro ";
+      os << current_use.get_package_name () + "_libraries ";
+      os << CmtSystem::quote (ls.str ().c_str (), " \t");
+      os << "\n";
+
+      os << "macro shlibsuffix ";
+      os << CmtSystem::quote (shlibsuffix, " \t");
+      os << "\n";
+
+      cmt_string symlinkcmd;
+      {
+	Symbol* macro = Symbol::find ("library_install_command");
+	if (macro != 0)
+	  {
+	    symlinkcmd = macro->build_macro_value ();
+	    Symbol::expand (symlinkcmd);
+	  }
+      }
+      os << "macro library_install_command ";
+      os << CmtSystem::quote (symlinkcmd, " \t");
+      os << "\n";
+
+      cmt_string symunlinkcmd;
+      {
+	Symbol* macro = Symbol::find ("symunlink");
+	if (macro != 0)
+	  {
+	    symunlinkcmd = macro->build_macro_value ();
+	    Symbol::expand (symunlinkcmd);
+	  }
+      }
+      os << "macro symunlink ";
+      os << CmtSystem::quote (symunlinkcmd, " \t");
+      os << "\n";
+
+      if (current_use.get_strategy ("InstallArea"))
+	{
+	  os << "build_strategy with_installarea\n";
+
+	  const CmtInstallAreaMgr& ia_mgr = CmtInstallAreaMgr::instance ();
+	  
+	  cmt_string cmtinstallarea = ia_mgr.get_installarea ();
+	  {
+	    Symbol* symbol = Symbol::find ("CMTINSTALLAREA");
+	    if (symbol != 0)
+	      {
+		cmtinstallarea = symbol->build_macro_value ();
+		Symbol::expand (cmtinstallarea);
+	      }
+	  }
+	  os << "macro CMTINSTALLAREA ";
+	  os << CmtSystem::quote (cmtinstallarea, " \t");
+	  os << "\n";
+
+	  cmt_string tag;
+	  {
+	    Symbol* macro = Symbol::find ("tag");
+	    if (macro != 0)
+	      {
+		tag = macro->build_macro_value ();
+		Symbol::expand (tag);
+	      }
+	  }
+	  os << "macro tag ";
+	  os << CmtSystem::quote (tag, " \t");
+	  os << "\n";
+	}
+      //      cerr << os.str ();
+    }
+
+  // Write input requirements 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;
+	}
+    }
+
+#endif
+  return 0;
+}
+
+//--------------------------------------------------
+int Generator::build_dependencies_infile (const Constituent* pconstituent,
+					  const cmt_string& outdir,
+					  bool usecmt)
+{
+  cmt_string file ("dependencies");
+  if (0 != pconstituent)
+    file += "_" + pconstituent->name;
+  file += ".in";
+
+  if (outdir != "")
+    {
+      if (outdir [outdir.size () - 1] != CmtSystem::file_separator ())
+	file = outdir + CmtSystem::file_separator () + file;
+      else
+	file = outdir + file;
+    }
+
+  ostringstream os;
+  
+  cmt_string preprocessor;
+  Symbol* macro = Symbol::find ("preprocessor_command");
+  if (macro != 0)
+    {
+      preprocessor = macro->resolve_macro_value ();
+    }
+
+  if (preprocessor == "")
+    {
+      const Use* current_use = &Use::current ();
+      Use::UsePtrVector uses (Use::get_ordered_uses ());
+      uses.push_back (&Use::current ());
+      
+      if (current_use->include_path == "none")
+	os << "include_path none\n";
+
+      for (int i = uses.size () - 1; i >= 0; i--)
+	{
+	  const 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;
+	  
+	  const Symbol* filter_macro = Symbol::find (package_name + "_header_file_filter");
+	  if (filter_macro == 0) continue;
+	  
+	  const 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);
+	      switch (use->style)
+		{
+		case cmt_style:
+		  stamp += CmtSystem::file_separator ();
+		  stamp += "cmt";
+		  break;
+		case mgr_style:
+		  stamp += CmtSystem::file_separator ();
+		  stamp += "mgr";
+		  break;
+		}
+	      stamp += CmtSystem::file_separator ();
+	      stamp += "cmt_header_file.stamp";
+	    }
+	  if (!CmtSystem::test_file (stamp)) continue;
+
+	  os << "macro " + package_name + "_header_file_filter ";
+	  os << CmtSystem::quote (filter_macro->resolve_macro_value (), " \t");
+	  os << "\n";
+	  os << "macro " + package_name + "_header_file_stamp ";
+	  os << CmtSystem::quote (stamp, " \t");
+	  os << "\n";
+	}
+    }
+  else
+    {
+      os << "macro preprocessor_command ";
+      os << CmtSystem::quote (preprocessor, " \t");
+      os << "\n";
+      macro = Symbol::find ("includes");
+      if (0 != macro)
+	{
+	  os << "macro includes ";
+	  os << CmtSystem::quote (macro->resolve_macro_value (), " \t");
+	  os << "\n";
+	}
+      if (0 == pconstituent)
+	{
+	  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;
+	      if (constituent.type == Document) continue;
+	      cmt_string prefix;
+	      switch (constituent.type)
+		{
+		case Application:
+		  prefix = "app_";
+		  break;
+		case Library:
+		  prefix = "lib_";
+		  break;
+		}
+	      cmt_string macro_name (prefix + constituent.name + "_cppflags");
+	      macro = Symbol::find (macro_name);
+	      if (0 != macro)
+		{
+		  os << "macro_append " + macro_name + " ";
+		  os << CmtSystem::quote (macro->resolve_macro_value (), " \t");
+		  os << "\n";
+		}
+	    }
+	}
+      else if (pconstituent->type != Document)
+	{
+	  const Constituent& constituent = *pconstituent;
+	  cmt_string prefix;
+	  switch (constituent.type)
+	    {
+	    case Application:
+	      prefix = "app_";
+	      break;
+	    case Library:
+	      prefix = "lib_";
+	      break;
+	    }
+	  cmt_string macro_name (prefix + constituent.name + "_cppflags");
+	  macro = Symbol::find (macro_name);
+	  if (0 != macro)
+	    {
+	      os << "macro_append " + macro_name + " ";
+	      os << CmtSystem::quote (macro->resolve_macro_value (), " \t");
+	      os << "\n";
+	    }
+	}
+    }
+
+  // Write input requirements file
+
+  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;
+	}
+    }
+
+  return 0;
+}
+
+//--------------------------------------------------
 int Generator::build_constituent_makefile (const Constituent& constituent,
+					   bool& dependencies,
 					   const cmt_string& file)
 {
@@ -824,8 +1244,8 @@
       //break;
     case Library:
-      LibraryContext.build (package, constituent, file);
+      LibraryContext.build (package, constituent, dependencies, file);
       break;
     case Document:
-      DocumentContext.build (package, constituent, file);
+      DocumentContext.build (package, constituent, dependencies, file);
       break;
     }
@@ -860,5 +1280,9 @@
 
   const Constituent* constituent = Constituent::find (name);
-  if (constituent != 0) build_constituent_makefile (*constituent, file);
+  if (constituent != 0)
+    {
+      bool dependencies (false);
+      build_constituent_makefile (*constituent, dependencies, file);
+    }
 }
 
@@ -867,4 +1291,12 @@
 {
   DefaultMakefileContext.build ();
+}
+
+//--------------------------------------------------
+void Generator::build_packages_makefile (const cmt_string& package,
+					 const cmt_string& file)
+{
+  PackagesMakefileContext.build (package, file);
+  //  UsesMakefileContext.build (package, file);
 }
 
@@ -1213,4 +1645,5 @@
   CmtSystem::cmt_string_vector document;
   document.push_back ("document_header");
+  document.push_back ("dependency");
   m_document.set_names (document);
   m_document.set_uses (usecmt);
Index: CMT/HEAD/source/cmt_generator.h
===================================================================
--- CMT/HEAD/source/cmt_generator.h	(revision 586)
+++ CMT/HEAD/source/cmt_generator.h	(revision 588)
@@ -12,5 +12,4 @@
 #include "cmt_language.h"
 #include "cmt_awk.h"
-#include "cmt_deps_builder.h"
 
 class Packager : public FAwk
@@ -59,5 +58,5 @@
   void fill_outputs ();
 
-  void prepare_use_context ();
+  //  void prepare_use_context ();
 
   void set_full_name (cmt_string& full_name, cmt_string& file);
@@ -96,6 +95,4 @@
   cmt_string m_output_file_name;
   FILE* m_output_file;
-
-  DepsBuilder m_deps_builder;
 
   Constituent* m_constituent;
@@ -215,4 +212,5 @@
     // Build the makefile fragment for one constituent
   static int build_constituent_makefile (const Constituent& constituent,
+					 bool& dependencies,
 					 const cmt_string& file = "");
   static void build_constituent_makefile (const CmtSystem::cmt_string_vector& arguments);
@@ -221,5 +219,15 @@
 				       bool usecmt = true);
 
+  static int build_library_links_infile (const cmt_string& outdir = "");
+
+  static int build_dependencies_infile (const Constituent* constituent,
+					const cmt_string& outdir = "",
+					bool usecmt = true);
+
   static void build_default_makefile ();
+
+    // Build the packages (N)Make file
+  static void build_packages_makefile (const cmt_string& package,
+				       const cmt_string& file = "");
 
     // Build the dependencies for one module
Index: CMT/HEAD/source/cmt_generators.cxx
===================================================================
--- CMT/HEAD/source/cmt_generators.cxx	(revision 586)
+++ CMT/HEAD/source/cmt_generators.cxx	(revision 588)
@@ -12,4 +12,5 @@
 #include "cmt_error.h"
 #include <assert.h>
+#include "cmt_project.h"
 
 //--------------------------------------------------
@@ -200,5 +201,5 @@
   if (Cmt::get_debug ())
     {
-      cout << "CmtGenerator::analyze_file> constituent=" << 
+      cout << "LibraryGenerator::analyze_file> constituent=" << 
 	constituent.name <<
 	" obj=" << obj << endl;
@@ -408,6 +409,60 @@
 
 //--------------------------------------------------
+void LibraryGenerator::fill_names_outputs ()
+{
+  bool l_first = true;
+  bool o_first = true;
+
+  m_LINE = "";
+  m_OBJS = "";
+
+  for (int i = 0; i < m_source_files.size (); i++)
+    {
+      const SourceFile& file = m_source_files[i];
+      const cmt_string name = file.name ();
+      const cmt_string output = file.output ();
+      Language& language = file.language ();
+
+      if (output != "")
+        {
+          if (o_first)
+            {
+              o_first = false;
+            }
+          else
+            {
+              m_OBJS += " ";
+            }
+          m_OBJS += output;
+
+	  if (language == Language::null () || !language.native_dependencies ())
+	    {
+	      if (l_first)
+		{
+		  l_first = false;
+		}
+	      else
+		{
+		  m_LINE += " ";
+		}
+	      m_LINE += name;
+	    }
+	}
+
+      if (Cmt::get_debug ())
+        {
+          cout << "LibraryGenerator::fill_names_outputs>" << endl;
+	  cout << "name=" << name << " LINE=" << m_LINE << endl;
+	  cout << "output=" << output << " OBJS=" << m_OBJS << endl;
+        }
+    }
+
+  filter_path (m_LINE.value);
+}
+
+//--------------------------------------------------
 void LibraryGenerator::build (const cmt_string& package,
 			      const Constituent& constituent,
+			      bool& dependencies,
 			      const cmt_string& file_name)
 {
@@ -735,4 +790,5 @@
 	}
     }
+  dependencies = need_dependencies;
 
   if (constituent.build_triggers)
@@ -893,5 +949,8 @@
 DocumentGenerator::DocumentGenerator ()
 {
+  m_FILEEXTENSION.set ("FILEEXTENSION");
+
   document_header_fragment.set ("document_header");
+  dependency_fragment.set ("dependency");
 }
 
@@ -900,5 +959,8 @@
 {
   AnyDocumentGenerator::reset ();
+  m_FILEEXTENSION = "";
+
   document_header_fragment.reset ();
+  dependency_fragment.reset ();
 }
 
@@ -906,4 +968,5 @@
 void DocumentGenerator::build (const cmt_string& package,
 			       const Constituent& constituent,
+			       bool& dependencies,
 			       const cmt_string& file_name)
 {
@@ -1062,4 +1125,5 @@
     }
 
+  dependencies = fragment.need_dependencies ();
   if (fragment.need_dependencies ())
     {
@@ -1123,6 +1187,9 @@
       if (m_FILEPATH.value != "") m_FILEPATH.value += CmtSystem::file_separator ();
       filter_path (m_FILEPATH.value);
-      CmtSystem::basename (file_name, m_FILENAME.value);
-      CmtSystem::get_dot_suffix (m_FILENAME.value, m_FILESUFFIX.value);
+      m_FILENAME.value = m_NAME.value + suffix;
+      //CmtSystem::basename (file_name, m_FILENAME.value);
+      m_FILESUFFIX.value = suffix;
+      //CmtSystem::get_dot_suffix (m_FILENAME.value, m_FILESUFFIX.value);
+      CmtSystem::get_suffix (m_FILENAME.value, m_FILEEXTENSION .value);
       /*
       if (!CmtSystem::test_file (file_name) && !CmtSystem::test_directory (file_name))
@@ -1133,5 +1200,21 @@
       filter_path (m_FULLNAME.value);
 
-      fragment.copy (m_output_file, constituent.variables, 8,
+      if (fragment.need_dependencies ())
+	{
+	  // ensure that ${CONSTITUENT}_dependencies.make gets rebuilt
+	  // whenever source file OR its dependencies change
+	  dependency_fragment.copy (m_output_file, constituent.variables, 9,
+				    &m_FILEPATH,
+				    &m_SUFFIX,
+				    &m_CONSTITUENT,
+				    &m_CONSTITUENTSUFFIX,
+				    &m_FILENAME,
+				    &m_NAME,
+				    &m_FULLNAME,
+				    &m_FILESUFFIX,
+				    &m_FILEEXTENSION);
+	}
+      
+      fragment.copy (m_output_file, constituent.variables, 9,
                      &m_FILEPATH,
                      &m_SUFFIX,
@@ -1141,5 +1224,6 @@
                      &m_NAME,
                      &m_FULLNAME,
-                     &m_FILESUFFIX);
+                     &m_FILESUFFIX,
+		     &m_FILEEXTENSION);
     }
 
@@ -1201,4 +1285,5 @@
 }
 
+//--------------------------------------------------
 ReadmeGenerator::ReadmeGenerator ()
 {
@@ -2702,6 +2787,194 @@
 }
 
-
-
+//--------------------------------------------------
+
+PackagesMakefileGenerator::PackagesMakefileGenerator ()
+{
+  m_DEPENDENCIES.set ("DEPENDENCIES");
+  m_PACKAGEMGRPATH.set ("PACKAGEMGRPATH");
+  m_PACKAGEFULLNAME.set ("PACKAGEFULLNAME");
+  m_ISLOCAL.set ("ISLOCAL");
+
+  packages_header_fragment.set ("packages_header");
+  packages_trailer_fragment.set ("packages_trailer");
+  package_fragment.set ("package");
+}
+
+void PackagesMakefileGenerator::reset ()
+{
+  CmtGenerator::reset ();
+  m_DEPENDENCIES = "";
+  m_PACKAGEMGRPATH = "";
+  m_PACKAGEFULLNAME = "";
+  m_ISLOCAL = "";
+
+  packages_header_fragment.reset ();
+  packages_trailer_fragment.reset ();
+  package_fragment.reset ();
+}
+
+//--------------------------------------------------
+void PackagesMakefileGenerator::build (const cmt_string& package,
+				       const cmt_string& file)
+{
+  reset ();
+
+  cmt_string file_name (file);
+  if (file_name == "")
+    {
+      file_name = "packages.";
+
+      if (Cmt::build_nmake ())
+	{
+	  file_name += "nmake";
+	}
+      else
+	{
+	  file_name += "make";
+	}
+    }
+
+  cmt_string save_file_name = file_name;
+  save_file_name += "cmtsave";
+
+  if (CmtSystem::test_file (file_name))
+    {
+      rename (file_name, save_file_name);
+    }
+
+  cmt_string new_file_name = file_name;
+  new_file_name += "new";
+
+  m_output_file = fopen (new_file_name, "wb");
+  if (m_output_file != NULL)
+    {
+      m_PACKAGE = package;
+
+      packages_header_fragment.copy (m_output_file, 1, &m_PACKAGE);
+
+      Project* cur = Project::get_current ();
+      Use::UsePtrVector uses (Use::get_ordered_uses ());
+      uses.push_back (&Use::current ());
+      cmt_string temp;
+      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;
+	  if (use->get_package ()->is_cmt ()) continue;
+
+	  if (use->get_project () == cur)
+	    m_ISLOCAL = "is_local";
+	  else
+	    m_ISLOCAL = "is_not_local";
+
+	  temp = use->get_full_path ();
+	  switch (use->style)
+	    {
+	    case cmt_style:
+	      temp += CmtSystem::file_separator ();
+	      temp += "cmt";
+	      break;
+	    case mgr_style:
+	      temp += CmtSystem::file_separator ();
+	      temp += "mgr";
+	      break;
+	    }
+#ifdef WIN32
+	  temp += " ";
+#endif
+	  m_PACKAGEMGRPATH = temp;
+	  //	  fprintf (m_output_file, "%s\n", temp.c_str());
+
+	  temp = "";
+	  if (Symbol* s = Symbol::find (use->get_package_name () + "_offset"))
+	    {
+	      cmt_string o = s->build_macro_value ();
+	      if (o != "")
+		{
+		  temp += o;
+		  temp += CmtSystem::file_separator ();
+		}
+	    }
+	  else
+	    {
+	      CmtMessage::warning
+		(CmtError::get_error_name (CmtError::symbol_not_found)
+		 + ": macro " + use->get_package_name () + "_offset");
+	    }
+	  temp += use->get_package_name ();
+	  temp.replace_all (CmtSystem::file_separator (), "_");
+#ifdef WIN32
+	  temp += " ";
+#endif
+	  m_PACKAGEFULLNAME = temp;
+	  //	  fprintf (m_output_file, "%s\n", temp.c_str());
+
+	  m_PACKAGE = use->get_package_name ();
+
+	  Use::UsePtrVector subuses;
+	  for (int i = 0; i < use->sub_uses.size (); i++)
+	    {
+	      if (use->sub_uses[i]->m_index >= 0 && !use->sub_uses[i]->discarded)
+		{
+		  if (use->sub_uses[i]->m_hidden) continue;
+		  subuses.push_back (use->sub_uses[i]);
+		}
+	      else
+		{
+		  Use* au (Use::find_valid (use->sub_uses[i]->get_package_name ()));
+		  if (au)
+		    {
+		      subuses.push_back (au);
+		    }
+		}
+	    }
+	  m_DEPENDENCIES = "";
+	  for (int i = 0; i < subuses.size (); i++)
+	    {
+	      if (i != 0)
+		{
+		  m_DEPENDENCIES += " " + subuses[i]->get_package_name ();
+		}
+	      else
+		{
+		  m_DEPENDENCIES += subuses[i]->get_package_name ();
+		}
+	    }
+
+	  package_fragment.copy (m_output_file, 5, &m_PACKAGE, &m_DEPENDENCIES,
+			     &m_PACKAGEMGRPATH, &m_PACKAGEFULLNAME, &m_ISLOCAL);
+	}
+
+      if (Symbol* s = Symbol::find ("CMTINSTALLAREA"))
+	{
+	  cmt_string o = s->build_macro_value ();
+	  Symbol::expand (o);
+	  if (o != "")
+	    {
+	      temp  = "CMTINSTALLAREA=";
+	      temp += o;
+#ifdef WIN32
+	      temp += " ";
+#endif
+	      fprintf (m_output_file, "%s\n", temp.c_str());
+	    }
+	}
+
+      packages_trailer_fragment.copy (m_output_file, 0);
+
+      CmtSystem::close_ostream (m_output_file, new_file_name);
+      //  fclose (m_output_file);
+
+      commit (new_file_name);
+    }
+  else
+    {
+      CmtError::set (CmtError::file_access_error, new_file_name);
+    }
+}
+
+//--------------------------------------------------
 
 /**
@@ -2794,75 +3067,234 @@
 };
 
+//--------------------------------------------------
+void DependencyGenerator::reset ()
+{
+  CmtGenerator::reset ();
+  m_deps_builder.clear ();
+  m_stamps = true;
+  m_name = "";
+}
+
+//--------------------------------------------------
+void DependencyGenerator::prepare_includes ()
+{
+  cmt_string path;
+  cmt_string substitution;
+
+  Use* use = &Use::current ();
+
+  //  m_deps_builder.clear ();
+
+  if (use->include_path != "none")
+    {
+      if (use->include_path == "")
+	{
+	  m_deps_builder.add (incdir, "$(src)");
+	}
+      else
+	{
+	  substitution = use->include_path;
+	  
+	  path = substitution;
+	  Symbol::expand (path);
+	  
+	  CmtSystem::reduce_file_separators (path);
+
+          m_deps_builder.add (path, substitution);
+	}
+    }
+
+  m_deps_builder.add_includes (*use);
+
+  Use::UsePtrVector& uses = Use::get_ordered_uses ();
+
+  if (uses.size () > 0)
+    {
+      int number;
+
+      for (number = 0; number < uses.size (); number++)
+        {
+          use = uses[number];
+          if (use->discarded) continue;
+
+          if (use->real_path != "")
+            {
+	      if (use->include_path != "none")
+		{
+		  if (use->include_path == "")
+		    {
+		      use->get_full_path (path);
+                      path += CmtSystem::file_separator ();
+		      path += "src";
+
+		      substitution = "$(";
+		      substitution += use->prefix;
+		      substitution += "ROOT)";
+		      substitution += CmtSystem::file_separator ();
+		      substitution += "src";
+		      substitution += CmtSystem::file_separator ();
+		    }
+		  else
+		    {
+		      substitution = use->include_path;
+
+		      path = substitution;
+		      Symbol::expand (path);
+
+                      CmtSystem::reduce_file_separators (path);
+		    }
+
+		  m_deps_builder.add (path, substitution);
+		}
+
+              m_deps_builder.add_includes (*use);
+            }
+        }
+    }
+}
+
+//--------------------------------------------------
+void DependencyGenerator::prepare_header_file_filters ()
+{
+  const Use* current_use = &Use::current ();
+  Use::UsePtrVector uses (Use::get_ordered_uses ());
+  uses.push_back (&Use::current ());
+  bool current_only (true);
+  for (int i = uses.size () - 1; i >= 0; i--)
+    {
+      const Use* use = uses[i];
+      //cerr << "prepare_header_file_filters(0)> " << use->get_package_name () << "[" << use->get_index () << "]\n";
+      if (use->discarded) continue;
+      if (use->m_hidden) continue;
+      if (!use->located ()) continue;
+
+      if (current_only && use != current_use)
+	current_only = false;
+
+      cmt_string package_name = use->get_package_name ();
+      if (package_name == "CMT") continue;
+
+      const Symbol* filter_macro = Symbol::find (package_name + "_header_file_filter");
+      if (filter_macro == 0) continue;
+
+      const 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);
+	  switch (use->style)
+	    {
+	    case cmt_style:
+	      stamp += CmtSystem::file_separator ();
+	      stamp += "cmt";
+	      break;
+	    case mgr_style:
+	      stamp += CmtSystem::file_separator ();
+	      stamp += "mgr";
+	      break;
+	    }
+          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;
+
+      //cerr << "0: adding filter: " << use->get_package_name () << "[" << use->get_index () << "]\n";
+      cmt_regexp* filter = new cmt_regexp (filter_macro->resolve_macro_value ());
+      assert (filter != 0);
+
+      m_deps_builder.add_header_filter (use, filter, stamp);
+    }
+
+  if (current_only)
+    { // we are most likely reading dependencies[_CONSTITUENT].in without CMT
+      for (int number = 0; number < Symbol::symbol_number (); number++)
+	{
+	  const Symbol& symbol = Symbol::symbol (number);
+	  if (symbol.type != Symbol::SymbolMacro) continue;
+	  int r = symbol.name.find_last_of ("_header_file_filter");
+	  if (r == cmt_string::npos ||
+	      (r + 19) != symbol.name.size () ||
+	      r == 0) continue;
+
+	  cmt_string package_name = symbol.name.substr(0, r);
+	  const Use* use = Use::find (package_name);
+	  if (use == current_use) continue;
+	  if (0 != use && use->discarded) continue;
+	  if (0 != use && use->m_hidden) continue;
+	  if (0 != use && !use->located ()) continue;
+	  
+	  //Symbol* filter_macro = Symbol::find (package_name + "_header_file_filter");
+	  //if (filter_macro == 0) continue;
+	  
+	  const Symbol* stamp_macro = Symbol::find (package_name + "_header_file_stamp");
+	  cmt_string stamp;
+	  if (stamp_macro != 0)
+	    {
+	      stamp = stamp_macro->resolve_macro_value ();
+	    }
+	  else if (0 != use)
+	    {
+	      use->get_full_path (stamp);
+	      switch (use->style)
+		{
+		case cmt_style:
+		  stamp += CmtSystem::file_separator ();
+		  stamp += "cmt";
+		  break;
+		case mgr_style:
+		  stamp += CmtSystem::file_separator ();
+		  stamp += "mgr";
+		  break;
+		}
+	      stamp += CmtSystem::file_separator ();
+	      stamp += "cmt_header_file.stamp";
+	    }
+	  if (!CmtSystem::test_file (stamp)) continue;
+	  
+	  //cerr << "1: adding filter: " << package_name << "\n";
+	  cmt_regexp* filter = new cmt_regexp (symbol.resolve_macro_value ());
+	  assert (filter != 0);
+	  
+	  m_deps_builder.add_header_filter (use, filter, stamp);
+	}
+    }
+}
+
+//--------------------------------------------------
 void DependencyGenerator::build (const CmtSystem::cmt_string_vector& arguments)
 {
   reset ();
-  prepare_use_context ();
-
-  prepare_header_file_filters ();
-
-  const cmt_string& name = arguments[0];
-
-  m_constituent = Constituent::find (name);
-  if (m_constituent == 0)
-    {
-      // Error : wrong constituent name...
-      return;
-    }
-
-  const Constituent& constituent = *m_constituent;
-
-  cmt_string file_name;
-  cmt_string full_name;
-  cmt_string compressed_name;
-  //  cmt_string suffix;
-  cmt_string dependencies;
 
   //
-  // Scan the sources.
+  // Parse arguments first
   //
-
-  //
-  //  We have to rebuild the dependencies for :
-  //
-  //   o all sources if the parameter -all_sources has been received
-  //   o otherwise,
-  //      + all source names provided in the argument list (if any)
-  //      + all source names missing from the existing dependency file (if any)
-  //
-
-  const CmtSystem::cmt_string_vector& sources = constituent.modules;
-  const cmt_vector<cmt_regexp>& excludes = constituent.exclude_exprs;
-  const cmt_vector<cmt_regexp>& selects = constituent.select_exprs;
-
-  m_stamps = true;
+  CmtSystem::cmt_string_vector cli_input, all;
   bool all_sources = false;
-
-  int source_number = arguments.size ();
-  int i;
-
-  //cerr << "source_number=" << source_number << endl;
-
-  for (i = source_number-1; i >= 0; i--)
-    {
-      file_name = arguments[i];
-
-      //cerr << "file_name=" << file_name << endl;
-
-      // Get rid of files that may come from the makefile fragment
-      if (file_name.find ("requirements") != cmt_string::npos) source_number--;
-      else if (file_name.substr (0, 5) == "-out=" ||
-	       file_name.substr (0, 5) == "-out:" ||
-	       file_name.substr (0, 5) == "/out:" ||
-	       file_name.substr (0, 5) == "/out=")
-        {
-          source_number--;
+  bool config_files (false);
+  bool start_all (false);
+
+  for (int i = 0; i < arguments.size (); i++)
+    {
+      cmt_string file_name = arguments[i];
+
+      //cerr << "i: " << i << " file_name=" << file_name << endl;
+
+      if (file_name.substr (0, 5) == "-out=" ||
+	  file_name.substr (0, 5) == "-out:" ||
+	  file_name.substr (0, 5) == "/out:" ||
+	  file_name.substr (0, 5) == "/out=")
+        {
 	  file_name.erase (0, 5);
 	  m_output_file_name = file_name;
         }
-      else if (file_name.find (".make") != cmt_string::npos) source_number--;
       else if (file_name == "-all_sources" ||
 	       file_name == "/all_sources") 
         {
-          source_number = sources.size ();
           all_sources = true;
         }
@@ -2870,8 +3302,110 @@
 	       file_name == "/no_stamps") 
         {
-          source_number--;
 	  m_stamps = false;
         }
-    }
+      else if (file_name.substr (0, 2) == "-I" ||
+	       file_name.substr (0, 2) == "/I")
+	{
+	  file_name.erase (0, 2);
+	  //cerr << "include: " << file_name << endl;
+	  m_deps_builder.add (file_name, file_name);
+        }
+      else if (file_name  == "-start_all" ||
+	       file_name  == "/start_all")
+	{
+	  if (start_all)
+	    {
+	      CmtError::set(CmtError::syntax_error,
+			    "Unexpected option " + file_name);
+	      return;
+	    }
+	  start_all = true;
+        }
+      else if (file_name == "-end_all" ||
+	       file_name == "/end_all")
+	{
+	  if (!start_all)
+	    {
+	      CmtMessage::warning
+		(CmtError::get_error_name (CmtError::syntax_error)
+		 + ": Unexpected option " + file_name);
+	    }
+	  start_all = false;
+        }
+      else if (file_name.substr (0, 1) == "-"
+#ifdef WIN32
+	       || file_name.substr (0, 1) == "/"
+#endif
+	       )
+	{
+	  if (CmtMessage::active (Verbose))
+	    CmtMessage::warning
+	      (CmtError::get_error_name (CmtError::warning)
+	       + ": Unknown option " + file_name);
+        }
+      else if (file_name.substr (file_name.size () - 12) == "requirements" ||
+	       file_name.substr (file_name.size () - 5) == ".make" ||
+	       file_name.substr (file_name.size () - 3) == ".mk" ||
+	       file_name.substr (file_name.size () - 6) == ".nmake" ||
+	       file_name.substr (file_name.size () - 3) == ".in" ||
+	       file_name.substr (file_name.size () - 6) == ".stamp")
+	{
+	  // Configuration changed,
+	  // want to rebuild dependencies from scratch
+	  if (!config_files) config_files = true;
+          if (!all_sources) all_sources = true;
+	}
+      else if (start_all)
+	{
+	  all.push_back (file_name);
+	}
+      else if (m_name.size () != 0)
+	{
+	  cli_input.push_back (file_name);
+	}
+      else
+	{
+	  if (file_name.size () != 0)
+	    m_name = file_name;
+	}
+    }
+  
+  if (start_all)
+    CmtMessage::warning
+      (CmtError::get_error_name (CmtError::syntax_error)
+       + ": Missing option -end_all");
+
+  //cerr << "m_name: " << m_name << endl;
+  if (m_name.size () == 0)
+    {
+      CmtError::set(CmtError::syntax_error,
+		    "Name missing as first argument");
+      return;
+    }
+
+  //cerr << "config_files: " << config_files << endl;
+
+  m_constituent = Constituent::find (m_name);
+
+  if (!config_files && 0 == cli_input.size () &&
+      0 == all.size () && 0 == m_constituent)
+    {
+      CmtError::set(CmtError::syntax_error,
+		    m_name + ": Files arguments missing");
+      return;
+    }
+  /*
+  cerr << "cli_input:";
+  for (int i = 0; i < cli_input.size (); i++)
+    cerr << " " << cli_input[i];
+  cerr << "\n";
+
+  cerr << "all:";
+  for (int i = 0; i < all.size (); i++)
+    cerr << " " << all[i];
+  cerr << "\n";
+  */
+  prepare_includes ();
+  prepare_header_file_filters ();
 
   //
@@ -2922,5 +3456,5 @@
     {
       m_output_file_name = m_bin;
-      m_output_file_name += name;
+      m_output_file_name += m_name;
       m_output_file_name += "_";
       m_output_file_name += "dependencies.";
@@ -2935,92 +3469,182 @@
     }
 
-  if (all_sources)
-    {
-      for (i = 0; i < sources.size (); i++)
-        {
-          file_name = sources[i];
-          
-          set_full_name (full_name, file_name);
-          if (full_name == "") continue;
-
-          CmtSystem::compress_path (full_name, compressed_name);
-          full_name = compressed_name;
-          
-          static CmtSystem::cmt_string_vector files;
-
-          get_all_files (full_name, excludes, selects, files);
-
-          for (int j = 0; j < files.size (); j++)
-            {
-              const cmt_string& name = files[j];
-              
-              if (name != "") 
-                {
-                  const cmt_string& line = build (name);
-                  
-                  add_line_to_text (line, dependencies);
-                }
-            }
-        }
-    }
-  else
-    {
-      //
-      // New read the existing dependency file if any and filter it to
-      // extract the source names
-      //
-      static DependencyFilter filter;
-      dependencies.read (m_output_file_name);
-      filter.run (dependencies);
-      
-      for (i = 1; i < source_number; i++)
-        {
-          file_name = arguments[i];
-
-          set_full_name (full_name, file_name);
-          if (full_name == "") continue;
-
-          CmtSystem::compress_path (full_name, compressed_name);
-          full_name = compressed_name;
-          
-          const cmt_string& line = build (full_name);
-                  
-          add_line_to_text (line, dependencies);
-
-          filter.add_source (full_name);
-
-        }
-
-      // Now : are there still any missing source file in dependencies??
-
-      for (i = 0; i < sources.size (); i++)
-        {
-          file_name = sources[i];
-          
-          set_full_name (full_name, file_name);
-          if (full_name == "") continue;
-          
-          CmtSystem::compress_path (full_name, compressed_name);
-          full_name = compressed_name;
-          
-          static CmtSystem::cmt_string_vector files;
-          
-          get_all_files (full_name, excludes, selects, files);
-
-          for (int j = 0; j < files.size (); j++)
-            {
-              const cmt_string& name = files[j];
-              if (name != "") 
-                {
-                  if (!filter.has_source (name))
-                    {
-                      const cmt_string& line = build (name);
-                  
-                      add_line_to_text (line, dependencies);
-                    }
-                }
-            }
-        }
-    }
+  //-------------------------------------------------------------------------------
+  //
+  // For Makefile, we need to select, from cli_input, source files only,
+  // there may be dependencies of source files (typically, header files) as well
+  //
+  cmt_string dependencies;
+  if (!all_sources)
+    {
+      // want to validate cli_input against
+      //   either
+      // o all cli sources
+      //   or
+      // o m_constituent sources
+      set_source_files (all);
+      if (0 == validate (cli_input))
+	{
+	  // cli_input contains source files ONLY
+	  // calculate dependencies for them ONLY
+	  if (CmtSystem::test_file (m_output_file_name))
+	    {
+	      if (!dependencies.read (m_output_file_name))
+		{
+		  CmtError::set (CmtError::file_access_error, m_output_file_name);
+		  return;
+		}
+	    }
+	  fill_dependencies (dependencies, cli_input);
+	}
+      else
+	{
+	  all_sources = true;
+	  // calculate dependencies for 
+	  // all cli sources
+	  // or
+	  // m_constituent sources
+	  fill_dependencies (dependencies);
+	}
+      /*
+      if (0 != all.size ())
+	{
+	  // o all cli sources
+	  int n_invalid = 0;
+	  for (int i = 0; i < cli_input.size (); i++)
+	    {
+	      bool valid = false;
+	      for (int j = 0; j < all.size (); j++)
+		if (cli_input[i] == all[j])
+		  {
+		    valid = true;
+		    break;
+		  }
+	      if (!valid)
+		{
+		  n_invalid += 1;
+		  break;
+		}
+	    }
+	  if (0 == n_invalid)
+	    {
+	      // cli_input contains source files ONLY
+	      // calculate dependencies for them ONLY
+	      if (CmtSystem::test_file (m_output_file_name))
+		{
+		  if (!dependencies.read (m_output_file_name))
+		    {
+		      CmtError::set (CmtError::file_access_error, m_output_file_name);
+		      return;
+		    }
+		}
+	      fill_dependencies (dependencies, cli_input);
+	    }
+	  else
+	    {
+	      all_sources = true;
+	      // calculate dependencies for all (all cli sources)
+	      fill_dependencies (dependencies, all);
+	    }
+	}
+      else // 0 == all.size ()
+	{
+	  //	  set_source_files ();
+	  if (int n = set_source_files ())
+	    //	  if (0 != m_source_files.size ())
+	    {
+	      // o m_constituent sources
+	      int n_invalid = 0;
+	      for (int i = 0; i < cli_input.size (); i++)
+		{
+		  bool valid = false;
+		  for (int j = 0; j < n; j++)
+		    if (cli_input[i] == m_source_files[j].name ())
+		      {
+			valid = true;
+			break;
+		      }
+		  if (!valid)
+		    {
+		      n_invalid += 1;
+		      break;
+		    }
+		}
+	      if (0 == n_invalid)
+		{
+		  // cli_input contains source files ONLY
+		  // calculate dependencies for them ONLY
+		  if (CmtSystem::test_file (m_output_file_name))
+		    {
+		      if (!dependencies.read (m_output_file_name))
+			{
+			  CmtError::set (CmtError::file_access_error, m_output_file_name);
+			  return;
+			}
+		    }
+		  fill_dependencies (dependencies, cli_input);
+		}
+	      else
+		{
+		  all_sources = true;
+		  // calculate dependencies for m_source_files
+		  // (m_constituent sources)
+		  fill_dependencies (dependencies);
+		}
+	    }
+	  else // 0 == m_source_files.size ())
+	    {
+	      // no source files to validate against
+	      fill_dependencies (dependencies, cli_input);
+	    }
+	}
+      */
+    }
+  else // all_sources = true
+    {
+      if (int n = set_source_files (all))
+	{
+	  // calculate dependencies for m_source_files 
+	  //   either
+	  // o all cli sources
+	  //   or
+	  // o m_constituent sources
+	  //   if any existing
+	  fill_dependencies (dependencies);
+	}
+      else
+	{
+	  // calculate dependencies for all we have
+	  fill_dependencies (dependencies, cli_input);
+	}
+      /*
+      if (0 != all.size ())
+	{
+	  // calculate dependencies for all (all cli sources)
+	  fill_dependencies (dependencies, all);
+	}
+      else
+	{
+	  if (int n = set_source_files ())
+	    {
+	      // calculate dependencies for m_source_files (m_constituent sources)
+	      fill_dependencies (dependencies);
+	    }
+	  else
+	    {
+	      // calculate dependencies for all we have
+	      fill_dependencies (dependencies, cli_input);
+	    }
+	}
+      */
+    }
+
+  if (CmtError::has_pending_error ())
+    {
+      if (CmtError::get_last_error_code () == CmtError::path_not_found ||
+	  CmtError::get_last_error_code () == CmtError::file_access_error ||
+	  CmtError::get_last_error_code () == CmtError::execution_failed)
+	return;
+    }
+  //-------------------------------------------------------------------------------
 
   FILE* f = fopen (m_output_file_name.c_str (), "wb");
@@ -3030,10 +3654,8 @@
       dependencies.write (f);
       CmtSystem::close_ostream (f, m_output_file_name);
-      //          fclose (f);
     }
   else
     {
       CmtError::set (CmtError::file_access_error, m_output_file_name);
-      //      CmtMessage::error ("Cannot open " + m_output_file_name + " for write");
     }
 
@@ -3043,12 +3665,12 @@
 //--------------------------------------------------
 //  o text contains lines with a pattern like :
-//      key = xxxxx
-//
+//      key = value
 //  o line follows the same pattern
 //
-//   This function appends <line> to <text> only if the key found in
-//  <line> is not found in <text>
+//  This function
+//    o if the key found in <line> is found in <text>, removes the first line in <text> with the key, if any
+//    o appends <line> to <text>
 //--------------------------------------------------
-void DependencyGenerator::add_line_to_text (const cmt_string& line, cmt_string& text)
+void DependencyGenerator::add_line_to_text (const cmt_string& line, cmt_string& text) const
 {
   static const cmt_string empty;
@@ -3091,9 +3713,10 @@
 }
 
+//--------------------------------------------------
 cmt_string DependencyGenerator::build (const cmt_string& file_name)
 {
   Log;
 
-  const Constituent& constituent = *m_constituent;
+  //  const Constituent& constituent = *m_constituent;
 
   static cmt_string full_name;
@@ -3105,8 +3728,10 @@
   line = "";
 
+  /*
   if (!CmtSystem::absolute_path (file_name))
     {
       full_name = srcdir;
     }
+  */
 
   full_name += file_name;
@@ -3116,7 +3741,14 @@
   CmtSystem::get_suffix (full_name, suffix);
 
-  if (name == "requirements") return (line);
-
-  const CmtSystem::cmt_string_vector& deps = m_deps_builder.run (full_name);
+  //  if (name == "requirements") return (line);
+
+  const CmtSystem::cmt_string_vector& deps = m_deps_builder.run (full_name, m_name);
+  if (CmtError::has_pending_error ())
+    {
+      return line;
+    }
+  //	  CmtError::set (CmtError::execution_failed, preprocessor, status);
+  //      CmtError::set (CmtError::file_access_error, header_file_path);
+  //      CmtError::set (CmtError::path_not_found, name);
 
   line  = name;
@@ -3157,5 +3789,6 @@
   if (m_stamps)
     {
-      cmt_string stamp_output_base = constituent.name;
+      cmt_string stamp_output_base = m_name;
+      //      cmt_string stamp_output_base = constituent.name;
       stamp_output_base += "_deps";
 
@@ -3165,6 +3798,8 @@
       if (!CmtSystem::mkdir (stamp_output))
 	{
-	  CmtMessage::error ("Cannot create the binary output directory for this constituent " + stamp_output);
-	  //	  cerr << "Cannot create the binary output directory for this constituent" << endl;
+	  CmtError::set (CmtError::file_access_error, 
+			 + "Cannot create directory " + stamp_output
+			 + " for " + m_name);
+	  return line;
 	}
 
@@ -3185,10 +3820,20 @@
       if (CmtSystem::test_file (stamp_output))
 	{
-	  old_stamp.read (stamp_output);
-	}
-
-      if (line != old_stamp)
-	{
-	  line.write (stamp_output);
+	  if (!old_stamp.read (stamp_output))
+	    {
+	      CmtError::set (CmtError::file_access_error, stamp_output);
+	      return line;
+	    }
+	  //	  old_stamp.read (stamp_output);
+	}
+
+      if (line != old_stamp.substr(0, old_stamp.size () - 1))
+	{
+	  if (!(line + "\n").write (stamp_output))
+	    {
+	      CmtError::set (CmtError::file_access_error, stamp_output);
+	      return line;
+	    }
+	  //	  (line + "\n").write (stamp_output);
 	}
     }
@@ -3198,45 +3843,161 @@
 
 //--------------------------------------------------
-void DependencyGenerator::prepare_header_file_filters ()
-{
-//   Use::UsePtrVector& uses = Use::get_ordered_uses ();
-  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);
-    }
-}
+int DependencyGenerator::fill_dependencies (cmt_string& dependencies)
+{
+  CmtSystem::cmt_string_vector sources;
+  for (int i = 0; i < m_source_files.size (); i++)
+    {
+      const SourceFile& file = m_source_files[i];
+      sources.push_back (file.name ());
+    }
+  return fill_dependencies (dependencies, sources);
+}
+
+//--------------------------------------------------
+int DependencyGenerator::fill_dependencies (cmt_string& dependencies,
+					    const CmtSystem::cmt_string_vector& sources)
+{
+  int retval (0);
+  cmt_string file_name;
+  cmt_string compressed_name;
+
+  for (int i = 0; i < sources.size (); i++)
+    {
+      file_name = sources[i];
+      //set_full_name (full_name, file_name);
+      CmtSystem::reduce_file_separators (file_name);
+      if (file_name == "") continue;
+      CmtSystem::compress_path (file_name, compressed_name);
+      file_name = compressed_name;
+      //cerr << "file_name: " << file_name << endl;     
+      if (file_name == "") continue;
+
+      const cmt_string& line = build (file_name);
+      if (CmtError::has_pending_error ())
+	{
+	  //	  if (CmtError::get_last_error_code () == CmtError::file_access_error)
+	  return -1;
+	}
+      
+      //cerr << "line: " << line << endl;     
+      add_line_to_text (line, dependencies);
+      //cerr << "dependencies: " << dependencies << endl;     
+    }
+
+  return retval;
+}
+
+//--------------------------------------------------
+int DependencyGenerator::set_source_files (const CmtSystem::cmt_string_vector& files)
+{
+  m_source_files.clear ();
+
+  for (int j = 0; j < files.size (); j++)
+    {
+      const cmt_string& name = files[j];
+      if (name == "") continue;
+
+      bool included = false;
+      for (int k = m_source_files.size () - 1; k >= 0; k--)
+	if (m_source_files[k].name () == name)
+	  {
+	    included = true;
+	    break;
+	  }
+      if (included) continue;
+      
+      SourceFile& source = m_source_files.add ();
+      source.set (name, Language::null (), "");
+    }
+      
+  if (m_source_files.size ()) return m_source_files.size ();
+  else return set_source_files ();
+}
+
+//--------------------------------------------------
+int DependencyGenerator::set_source_files ()
+{
+  if (0 == m_constituent && 0 != m_name.size ())
+    m_constituent = Constituent::find (m_name);
+  if (0 == m_constituent) return 0;
+
+  m_source_files.clear ();
+
+  const CmtSystem::cmt_string_vector& sources = m_constituent->modules;
+  const cmt_vector<cmt_regexp>& excludes = m_constituent->exclude_exprs;
+  const cmt_vector<cmt_regexp>& selects = m_constituent->select_exprs;
+
+  cmt_string file_name, full_name;
+  cmt_string compressed_name;
+  cmt_string visited, token;
+
+  for (int i = 0; i < sources.size (); i++)
+    {
+      file_name = sources[i];
+      set_full_name (full_name, file_name);
+      if (full_name == "") continue;
+      
+      CmtSystem::compress_path (full_name, compressed_name);
+      full_name = compressed_name;
+      
+      static CmtSystem::cmt_string_vector files;
+      
+      get_all_files (full_name, excludes, selects, files);
+      
+      for (int j = 0; j < files.size (); j++)
+	{
+	  const cmt_string& name = files[j];
+              
+	  if (name == "") continue;
+	  
+	  cmt_string suffix;
+	  CmtSystem::get_suffix (name, suffix);
+	  Language& language = Language::find_with_suffix (suffix);
+
+	  if ((m_constituent->type == Application || m_constituent->type == Library)
+	      && language != Language::null () && language.native_dependencies ())
+	    continue;
+
+	  bool included = false;
+	  for (int k = m_source_files.size () - 1; k >= 0; k--)
+	    if (m_source_files[k].name () == name)
+	      {
+		included = true;
+		break;
+	      }
+	  if (included) continue;
+	  
+	  SourceFile& source = m_source_files.add ();
+	  source.set (name, language, "");
+	}
+    }
+  return m_source_files.size ();
+}
+
+//--------------------------------------------------
+/**
+ *  Returns 0, if each file in files is found in m_source_files,
+ *  otherwise returns 1
+ */
+//--------------------------------------------------
+int DependencyGenerator::validate (const CmtSystem::cmt_string_vector& files) const
+{
+  int n_invalid = 0;
+  for (int i = 0; i < files.size (); i++)
+    {
+      bool valid = false;
+      for (int j = 0; j < m_source_files.size (); j++)
+	if (files[i] == m_source_files[j].name ())
+	  {
+	    valid = true;
+	    break;
+	  }
+      if (!valid)
+	{
+	  n_invalid += 1;
+	  break;
+	}
+    }
+
+  return n_invalid;
+}
Index: CMT/HEAD/source/cmt_generators.h
===================================================================
--- CMT/HEAD/source/cmt_generators.h	(revision 586)
+++ CMT/HEAD/source/cmt_generators.h	(revision 588)
@@ -11,4 +11,5 @@
 #include "cmt_fragment.h"
 #include "cmt_generator.h"
+#include "cmt_deps_builder.h"
 
 class AnyDocumentGenerator : public CmtGenerator
@@ -36,5 +37,7 @@
   void build (const cmt_string& package,
               const Constituent& constituent,
+	      bool& dependencies,
 	      const cmt_string& file = "");
+  // returned bool& value indicates whether dependencies_fragment added to makefile
 
 private:
@@ -44,5 +47,8 @@
 		     const cmt_string& output_suffix);
 
+  Variable m_FILEEXTENSION;
+
   FragmentHandle document_header_fragment;
+  FragmentHandle dependency_fragment;
 };
 
@@ -53,5 +59,7 @@
   void build (const cmt_string& package,
               const Constituent& constituent,
+	      bool& dependencies,
 	      const cmt_string& file = "");
+  // returned bool& value indicates whether dependencies_fragment added to makefile
 
 protected:
@@ -63,4 +71,5 @@
   void prepare_proto_file (const cmt_string& file);
   void module_file_action (SourceFile& file, const Constituent& constituent);
+  void fill_names_outputs ();
 
   FragmentHandle library_header_fragment;
@@ -214,14 +223,47 @@
 };
 
+class PackagesMakefileGenerator : public CmtGenerator
+{
+public:
+  PackagesMakefileGenerator ();
+  void build (const cmt_string& package,
+	      const cmt_string& file);
+  //	      const CmtSystem::cmt_string_vector& arguments);
+
+private:
+  void reset ();
+
+  Variable m_DEPENDENCIES;
+  Variable m_PACKAGEMGRPATH;
+  Variable m_PACKAGEFULLNAME;
+  Variable m_ISLOCAL;
+
+  FragmentHandle packages_header_fragment;
+  FragmentHandle packages_trailer_fragment;
+  FragmentHandle package_fragment;
+};
+
 class DependencyGenerator : public CmtGenerator
 {
 public:
   void build (const CmtSystem::cmt_string_vector& arguments);
+  void prepare_includes ();
   void prepare_header_file_filters ();
- 
-private:
-  void add_line_to_text (const cmt_string& line, cmt_string& text);
+  void reset ();
+
+protected:
+  int set_source_files ();
+  int set_source_files (const CmtSystem::cmt_string_vector& files);
+  int validate (const CmtSystem::cmt_string_vector& files) const;
+
+private:
+  void add_line_to_text (const cmt_string& line, cmt_string& text) const;
   cmt_string build (const cmt_string& file_name);
+  int fill_dependencies (cmt_string& dependencies,
+			 const CmtSystem::cmt_string_vector& source);
+  int fill_dependencies (cmt_string& dependencies);
+  DepsBuilder m_deps_builder;
   bool m_stamps;
+  cmt_string m_name;
 };
 
Index: CMT/HEAD/source/cmt_parser.cxx
===================================================================
--- CMT/HEAD/source/cmt_parser.cxx	(revision 586)
+++ CMT/HEAD/source/cmt_parser.cxx	(revision 588)
@@ -1888,4 +1888,6 @@
   Cmt::reset_all_sets_done ();
   Symbol::all_set ();
+  if (CmtSystem::testenv ("CMTBCAST"))
+    CmtSystem::putenv ("CMTBCAST", "");
 
   for (i = 0; i < uses.size (); i++)
@@ -2125,5 +2127,6 @@
       return;
     }
-  Generator::build_constituent_makefile (*constituent, out);
+  bool dependencies (false);
+  Generator::build_constituent_makefile (*constituent, dependencies, out);
 //   if (ap.arguments.size () > 0) 
 //     {
@@ -2167,6 +2170,10 @@
       return;
     }
-  Generator::build_constituent_makefile (*constituent, out);
-  if (!constituent->has_target_tag) return;
+  if (!constituent->has_target_tag)
+    {
+      bool dependencies (false);
+      Generator::build_constituent_makefile (*constituent, dependencies, out);
+      return;
+    }
   //  cerr << "constituent: " << name << endl;
 
@@ -2266,4 +2273,12 @@
 	}
     }
+
+  int retval (0);
+
+  bool dependencies (false);
+  Generator::build_constituent_makefile (*constituent, dependencies, out);
+
+  if (dependencies)
+    retval = Generator::build_dependencies_infile (constituent, outdir/*, usecmt*/);
 }
 
@@ -2300,4 +2315,8 @@
       return;
     }
+  do_check_configuration (ap);
+  if (CmtError::get_last_error_code () == CmtError::configuration_error)
+    return;
+
   set_standard_macros ();
 
@@ -2415,15 +2434,104 @@
     }
 
+  int retval (0);
+
   Generator::build_constituents_makefile (Me.m_current_package, out);
   //  Generator::build_constituents_makefile (Me.m_current_package, ap.arguments);
 
+  retval = Generator::build_library_links_infile (outdir);
+  if (0 != retval) return;
+
   const Constituent::ConstituentVector& constituents =
     Constituent::constituents ();
+  bool deps (false);
   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);
-    }
+
+      retval = Generator::build_constituent_infile (constituent, outdir, usecmt);
+      if (0 != retval) return;
+
+      if (!deps)
+	if (constituent.type == Application ||
+	    constituent.type == Library ||
+	    (constituent.type == Document &&
+	     FragmentHandle (constituent.generator).need_dependencies ()))
+	  {
+	    deps = true;
+	  }
+    }
+
+  if (deps)
+    retval = Generator::build_dependencies_infile (0, outdir, usecmt);
+}
+
+//----------------------------------------------------------
+void Cmt::do_build_broadcast_config (const ArgParser& ap)
+{
+  if (CmtLock::check () == CmtLock::locked_by_another_user)
+    {
+      CmtError::set (CmtError::conflicting_lock, "build_broadcast_config>");
+      return;
+    }
+  set_standard_macros ();
+
+  cmt_string out, outdir, name ("broadcast");
+  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);
+	  CmtSystem::dirname (out, outdir);
+	  CmtSystem::name (out, name);
+	}
+    }
+
+  cmt_string tag;
+  {
+    Symbol* macro = Symbol::find ("tag");
+    if (macro != 0)
+      {
+	tag = macro->build_macro_value ();
+	Symbol::expand (tag);
+      }
+  }
+  cmt_string file (tag + "_" + name);
+  //  cmt_string file (tag + "_uses");
+  if (Cmt::build_nmake ())
+    file += ".nmake";
+  else
+    file += ".make";
+  if (outdir != "")
+    {
+      if (outdir [outdir.size () - 1] != CmtSystem::file_separator ())
+	outdir += CmtSystem::file_separator ();
+      file = outdir + file;
+    }
+
+  ofstream t (file);
+  if (!t)
+    {
+      CmtError::set (CmtError::file_access_error, file);
+      return;
+    }
+  t.exceptions (ios::failbit | ios::badbit);
+  try
+    {
+//       Symbol* symbol = Symbol::find ("use_requirements");
+//       if (symbol != 0)
+// 	symbol->show_macro (Make, t);
+      const cmt_string pattern = "^use_requirements$|.*_root$";
+      print_macros (Make, pattern, t);
+      t.close (); // ios_base::failbit
+    }
+  catch (const ios::failure& e)
+    {
+      CmtSystem::close_ostream (NULL, file + ": " + cmt_string (e.what ()));
+    }
+
+  Generator::build_packages_makefile (Me.m_current_package, out);
+  //  Generator::build_uses_makefile (Me.m_current_package, out);
 }
 
@@ -2468,5 +2576,19 @@
   {
     Symbol* macro = Symbol::find ("shlibsuffix");
-    if (macro == 0) return;
+    if (macro == 0)
+      {
+	if (strlen (ap.extra_file.c_str ()) == 0)
+	  {
+	    CmtError::set(CmtError::configuration_error, "shlibsuffix undefined");
+	  }
+	else
+	  { // we are most likely reading empty library_links.in without CMT
+	    if (CmtMessage::active (Verbose))
+	      CmtMessage::warning
+		(CmtError::get_error_name (CmtError::configuration_error)
+		 + ": shlibsuffix undefined");
+	  }
+	return;
+      }
     shlibsuffix = macro->build_macro_value ();
     Symbol::expand (shlibsuffix);
@@ -2716,14 +2838,29 @@
       if (action_setup != get_action () &&
 	  none_style != use.style &&
-	  0 == Project::find_in_cmt_paths (use.real_path).size ())
+	  0 == Project::get_current ())
+	  //	  0 == Project::find_in_cmt_paths (use.real_path).size ())
 	{
-	  if (0 == CmtSystem::getenv ("CMTPEDANTIC").size () &&
-	      0 == CmtSystem::getenv ("PEDANTIC").size ())
-	    CmtMessage::warning
-	      (CmtError::get_error_name (CmtError::configuration_error)
-	       + ": Current use outside CMTPATH: " + use.get_info ());
-	  else
-	    CmtError::set(CmtError::configuration_error,
-			  "Current use outside CMTPATH: " + use.get_info ());
+	  bool use_cmtpath_pattern (false);
+	  static CmtPathPattern::CmtPathPatternVector& CmtPathPatterns = CmtPathPattern::patterns ();
+	  for (int i = 0; i < CmtPathPatterns.size (); i++)
+	    {
+	      CmtPathPattern& p = CmtPathPatterns[i];
+	      if (p.use->get_package ()->is_cmt () || p.is_constant ()) continue;
+	      use_cmtpath_pattern = true;
+	      break;
+	    }
+	  if (use_cmtpath_pattern)
+	    // non-constant cmtpath_pattern found that
+	    // cannot be applied for package outside CMTPATH
+	    {
+	      if (0 == CmtSystem::getenv ("CMTPEDANTIC").size () &&
+		  0 == CmtSystem::getenv ("PEDANTIC").size ())
+		CmtMessage::warning
+		  (CmtError::get_error_name (CmtError::configuration_error)
+		   + ": Package outside CMTPATH: " + use.get_info ());
+	      else
+		CmtError::set(CmtError::configuration_error,
+			      "Package outside CMTPATH: " + use.get_info ());
+	    }
 	}
     }
@@ -2737,5 +2874,6 @@
   static CmtSystem::cmt_string_vector tags;
 
-  CmtSystem::split (Me.m_extra_tags, " \t,", tags);
+  if (action_build_constituents_config != get_action ())
+    CmtSystem::split (Me.m_extra_tags, " \t,", tags);
 
   for (int i = 0; i < tags.size (); i++)
@@ -3848,10 +3986,26 @@
   uses.push_back (&Use::current ());
   int i;
+  cmt_string cmtinstallarea = "";
+  cmt_string tag = "";
   cmt_string shlibsuffix;
-  cmt_string symunlink;
+  cmt_string symunlinkcmd;
 
   {
     Symbol* macro = Symbol::find ("shlibsuffix");
-    if (macro == 0) return;
+    if (macro == 0)
+      {
+	if (strlen (ap.extra_file.c_str ()) == 0)
+	  {
+	    CmtError::set(CmtError::configuration_error, "shlibsuffix undefined");
+	  }
+	else
+	  { // we are most likely reading empty library_links.in without CMT
+	    if (CmtMessage::active (Verbose))
+	      CmtMessage::warning
+		(CmtError::get_error_name (CmtError::configuration_error)
+		 + ": shlibsuffix undefined");
+	  }
+	return;
+      }
     shlibsuffix = macro->build_macro_value ();
     Symbol::expand (shlibsuffix);
@@ -3860,19 +4014,51 @@
   {
     Symbol* macro = Symbol::find ("symunlink");
-    if (macro == 0) return;
-    symunlink = macro->build_macro_value ();
-    Symbol::expand (symunlink);
+    if (macro != 0)
+      {
+	symunlinkcmd = macro->build_macro_value ();
+	Symbol::expand (symunlinkcmd);
+      }
   }
 
-//   for (i = 0; i < Uses.size (); i++)
-//     {
-//       Use* use = Uses[i];
+  if (current_use.get_strategy ("InstallArea"))
+    {
+      const CmtInstallAreaMgr& ia_mgr = CmtInstallAreaMgr::instance ();
+      
+      cmt_string s1 = ia_mgr.get_installarea ();
+
+      {
+        Symbol* symbol = Symbol::find ("CMTINSTALLAREA");
+        if (symbol != 0)
+          {
+            s1 = symbol->build_macro_value ();
+	    Symbol::expand (s1);
+          }
+      }
+
+      cmtinstallarea = s1;
+                  
+      cmt_string s2;
+
+      {
+        Symbol* macro = Symbol::find ("tag");
+        if (macro != 0)
+          {
+            s2 = macro->build_macro_value ();
+	    Symbol::expand (s2);
+          }
+      }
+
+      tag = s2;
+    }
+
   for (i = 0; i < uses.size (); i++)
     {
       Use* use = uses[i];
 
+      if (use == 0) continue;
       if (use->discarded) continue;
       if (use->m_hidden) continue;
 
+      if (use->get_package_name () == "CMT") continue;
       if (!use->located ())
         {
@@ -3880,148 +4066,8 @@
 			       + " " + use->version + " " + use->path
 			       + " not found");
-	      /*
-          if (!Me.m_quiet)
-            {
-              cerr << "#CMT> package " << use->get_package_name () <<
-		" " << use->version << " " << use->path << 
-		" not found" <<
-		endl;
-            }
-	      */
-        }
-      else
-        {
-          if (use->get_package_name () == "CMT") continue;
-//           if (use->get_package_name () == current_use.get_package_name ()) continue;
-
-          cmt_string s;
-
-          s = use->get_package_name ();
-          s += "_libraries";
-
-          Symbol* libraries_macro = Symbol::find (s);
-
-          if (libraries_macro == 0) continue;
-
-          cmt_string libraries = libraries_macro->build_macro_value ();
-	  Symbol::expand (libraries);
-
-          static CmtSystem::cmt_string_vector values;
-
-          CmtSystem::split (libraries, " \t", values);
-
-          for (int j = 0; j < values.size (); j++)
-            {
-              const cmt_string& library = values[j];
-
-              static cmt_string libname;
-              static cmt_string name;
-
-              // Is it a simple name or a complete path?
-
-              libname = library;
-              Symbol::expand (libname);
-
-              if (CmtSystem::absolute_path (libname))
-                {
-                  /**
-                   *   We assume here that "library" contains a complete path.
-                   *   (including the complete syntax libxxx.so)
-                   */
-
-                  cmt_string suffix;
-                  CmtSystem::basename (library, name);
-                }
-              else
-                {
-                  /**
-                   *   Here we expect that only the base name of the library
-                   *   is given : ie it should not contain the "lib" prefix, 
-                   *   nor the suffix .so, nor any path prefix.
-                   *    This of course should generally correspond to a constituent name.
-                   */
-
-                  name = "lib";
-                  name += libname;
-                  name += ".";
-                  name += shlibsuffix;
-                }
-
-              Symbol::expand (libname);
-
-              if (current_use.get_strategy ("InstallArea"))
-                {
-                  const CmtInstallAreaMgr& ia_mgr = CmtInstallAreaMgr::instance ();
-
-                  cmt_string s1 = ia_mgr.get_installarea ();
-
-                  {
-                    Symbol* symbol = Symbol::find ("CMTINSTALLAREA");
-                    if (symbol != 0)
-                      {
-                        s1 = symbol->build_macro_value ();
-			Symbol::expand (s1);
-                      }
-                  }
-                  
-                  cmt_string s2;
-
-                  {
-                    Symbol* macro = Symbol::find ("tag");
-                    if (macro != 0)
-                      {
-                        s2 = macro->build_macro_value ();
-			Symbol::expand (s2);
-                      }
-                  }
-
-		  // Now deleting the reference file
-
-                  s = symunlink;
-                  s += " ";
-                  s += s1;
-                  s += CmtSystem::file_separator ();
-                  s += s2;
-                  s += CmtSystem::file_separator ();
-                  s += "lib";
-                  s += CmtSystem::file_separator ();
-                  s += name;
-                  s += ".cmtref";
-                  s += " ";
-                  s += s1;
-                  s += CmtSystem::file_separator ();
-                  s += s2;
-                  s += CmtSystem::file_separator ();
-                  s += "lib";
-                  s += CmtSystem::file_separator ();
-                  s += name;
-                }
-              else
-                {
-                  s = symunlink;
-                  s += " ../$(";
-                  s += current_use.get_package_name ();
-                  s += "_tag)/";
-                  s += name;
-                }
-
-              Symbol::expand (s);
-
-              if (!Me.m_quiet) cerr << s << endl;
-
-              int status = CmtSystem::execute (s);
-
-              if (status != 0)
-                {
-		  //                  if (status != 2) CmtError::set (CmtError::execution_error, s);
-                  CmtError::set (CmtError::execution_error, s);
-
-                  CmtMessage::warning ("Cannot remove the symbolic link " + s);
-		  //                  cerr << "#CMT> Cannot remove the symbolic link " << s << endl;
-
-                  break;
-                }
-            }
-        }
+	  continue;
+        }
+
+      use->remove_library_links (cmtinstallarea, tag, shlibsuffix, symunlinkcmd);
     }
 }
@@ -6417,4 +6463,5 @@
     case action_build_constituents_makefile :
     case action_build_constituents_config :
+    case action_build_broadcast_config :
     case action_build_dependencies :
     case action_build_library_links :
@@ -6535,4 +6582,5 @@
     case action_build_constituents_makefile :
     case action_build_constituents_config :
+    case action_build_broadcast_config :
     case action_build_dependencies :
     case action_build_library_links :
@@ -6642,4 +6690,5 @@
     case action_build_constituents_makefile :
     case action_build_constituents_config :
+    case action_build_broadcast_config :
     case action_build_dependencies :
     case action_build_library_links :
@@ -6789,4 +6838,5 @@
         case action_build_constituents_makefile :
         case action_build_constituents_config :
+	case action_build_broadcast_config :
         case action_build_dependencies :
         case action_build_library_links :
@@ -6911,4 +6961,7 @@
 	case action_build_constituents_config :
 	  do_build_constituents_config (ap);
+	  break;
+	case action_build_broadcast_config :
+	  do_build_broadcast_config (ap);
 	  break;
 	case action_build_dependencies :
@@ -9042,9 +9095,17 @@
 	    else
 	      {
-		if (Me.m_action == action_build_constituents_makefile ||
-		    Me.m_action == action_build_constituents_config)
-		  CmtMessage::warning ("package " + import +
-				       " cannot be imported (requested for " +
-				       constituent.name +")");
+		if ((!constituent.has_target_tag &&
+		     Me.m_action == action_build_constituents_config)
+		    ||
+		    (constituent.has_target_tag &&
+		     Me.m_action == action_build_constituent_config))
+		  CmtMessage::warning
+		    (CmtError::get_error_name (CmtError::configuration_error)
+		     + ": package " + import
+		     + " cannot be imported (requested for "
+		     + (constituent.type == Application ?
+			"application " : "library ")
+		     + constituent.name +")");
+		
 		if (Cmt::get_debug ())
 		  {
@@ -9052,4 +9113,6 @@
 			 << ("package " + import +
 			     " cannot be imported (requested for " +
+			     (constituent.type == Application ?
+			      "application " : "library ") +
 			     constituent.name +")")  << endl;
 		  }
Index: CMT/HEAD/source/cmt_parser.h
===================================================================
--- CMT/HEAD/source/cmt_parser.h	(revision 586)
+++ CMT/HEAD/source/cmt_parser.h	(revision 588)
@@ -228,4 +228,5 @@
   action_build_constituents_makefile,
   action_build_constituents_config,
+  action_build_broadcast_config,
   action_build_dependencies,
   action_build_library_links,
Index: CMT/HEAD/source/cmt_symbol.cxx
===================================================================
--- CMT/HEAD/source/cmt_symbol.cxx	(revision 586)
+++ CMT/HEAD/source/cmt_symbol.cxx	(revision 588)
@@ -1907,5 +1907,5 @@
 
   */
-cmt_string Symbol::resolve_macro_value (const cmt_string& tag_name)
+cmt_string Symbol::resolve_macro_value (const cmt_string& tag_name) const
 {
   cmt_string temp = builder->build (*this, tag_name);
@@ -1933,4 +1933,5 @@
       (action != action_build_constituents_config) &&
       (action != action_build_constituent_config) &&
+      (action != action_build_broadcast_config) &&
       (action != action_show_macros) &&
       (action != action_show_actions) &&
@@ -1952,4 +1953,5 @@
           (action == action_build_constituents_config) ||
           (action == action_build_constituent_config) ||
+          (action == action_build_broadcast_config) ||
           (action == action_load) ||
           (!Cmt::get_quiet ()))
@@ -1973,5 +1975,6 @@
       else if (action == action_build_tag_makefile ||
 	       action == action_build_constituents_config ||
-	       action == action_build_constituent_config)
+	       action == action_build_constituent_config ||
+	       action == action_build_broadcast_config)
         {
             /* 
@@ -1997,4 +2000,5 @@
           (action == action_build_constituents_config) ||
           (action == action_build_constituent_config) ||
+          (action == action_build_broadcast_config) ||
           (action == action_load) ||
           (!Cmt::get_quiet ()))
@@ -3287,5 +3291,5 @@
 
 //-------------------------------------------------------------
-bool Symbol::check_tag_used (Tag* tag)
+bool Symbol::check_tag_used (const Tag* tag)
 {
   if (tag == 0) return (false);
Index: CMT/HEAD/source/cmt_symbol.h
===================================================================
--- CMT/HEAD/source/cmt_symbol.h	(revision 586)
+++ CMT/HEAD/source/cmt_symbol.h	(revision 588)
@@ -102,5 +102,5 @@
   static void filter_path_value (const cmt_string& name, cmt_string& text);
 
-  static bool check_tag_used (Tag* tag);
+  static bool check_tag_used (const Tag* tag);
 
   static cmt_string get_env_value (const cmt_string& name);
@@ -122,5 +122,5 @@
   int print_macro (PrintMode mode, ostream& out = cout) const;
   cmt_string clean_macro_value () const;
-  cmt_string resolve_macro_value (const cmt_string& tag_name = "");
+  cmt_string resolve_macro_value (const cmt_string& tag_name = "") const;
   void show_macro (PrintMode mode, ostream& out = cout);
   //  void show_macro (PrintMode mode);
Index: CMT/HEAD/source/cmt_system.cxx
===================================================================
--- CMT/HEAD/source/cmt_system.cxx	(revision 586)
+++ CMT/HEAD/source/cmt_system.cxx	(revision 588)
@@ -674,5 +674,5 @@
   if (::unlink (name) != 0)
     {
-      CmtMessage::error ("Cannot remove file " + name);
+      //      CmtMessage::error ("Cannot remove file " + name);
       //      cerr << "#CMT> Cannot remove file " << name << endl;
       return (false);
Index: CMT/HEAD/source/cmt_use.cxx
===================================================================
--- CMT/HEAD/source/cmt_use.cxx	(revision 586)
+++ CMT/HEAD/source/cmt_use.cxx	(revision 588)
@@ -1624,4 +1624,5 @@
   // On deplace tous les pointeurs d'une case en arriere
   //
+  //cerr << "move-0> " << use->get_package_name () << "[" << use->m_index << "]" << endl;
   for (use_index++; use_index < size; use_index++)
     {
@@ -1629,4 +1630,5 @@
       u->m_index--;
 
+      //cerr << "move-1> " << u->get_package_name () << "[" << u->m_index << "]" << endl;
       uses[use_index - 1] = uses[use_index];
     }
@@ -1638,4 +1640,5 @@
   use->m_index = size - 1;
   uses[size - 1] = use;
+  //cerr << "move-2> " << use->get_package_name () << "[" << use->m_index << "]" << endl;
 }
 
@@ -3815,7 +3818,11 @@
 
       if (CmtMessage::active (Info))
-	cerr << "   Creating the reference file " << ref_file << endl;
+	cerr << "   Creating reference file " << ref_file << endl;
 	  //      if (!Cmt::get_quiet ()) cerr << "   Creating the reference file " << ref_file << endl;
-      text.write (ref_file);
+      if (!text.write (ref_file))
+	{
+	  CmtError::set (CmtError::file_access_error, ref_file);
+	  return false;
+	}
     }
   else
@@ -3844,5 +3851,8 @@
   if (same_dirs (source, dest))
     {
-      return (false);
+      cmt_string lname;
+      CmtSystem::basename (libname, lname);
+      if (lname == name)
+	return true;
     }
 
@@ -3855,5 +3865,6 @@
       if (!CmtSystem::create_symlink (libname, s))
 	{
-	  CmtMessage::error ("Cannot create a symbolic link to " + libname);
+	  CmtError::set (CmtError::file_access_error, "Cannot create symbolic link to " + libname);
+	  //CmtMessage::error ("Cannot create a symbolic link to " + libname);
 	  //	  cerr << "#CMT> Cannot create a symbolic link to " << libname << endl;
 	  return (false);
@@ -3867,10 +3878,9 @@
       cmd += " ";
       cmd += s;
-      
       int status = CmtSystem::execute (cmd);
-      
       if (status != 0)
 	{
-	  CmtMessage::error ("Cannot create a symbolic link to " + libname);
+	  CmtError::set (CmtError::execution_error, "Cannot create symbolic link to " + libname);
+	  //CmtMessage::error ("Cannot create a symbolic link to " + libname);
 	  //	  cerr << "#CMT> Cannot create a symbolic link to " << libname << endl;
 	  return (false);
@@ -3881,8 +3891,188 @@
 }
 
-
+//----------------------------------------------------------
+static bool uninstall_library (const cmt_string& source_library_name, 
+			       const cmt_string& dest_library_name, 
+			       const cmt_string& cmtinstallarea, 
+			       const cmt_string& tag, 
+			       const cmt_string& symunlinkcmd)
+{
+  cmt_string libname = source_library_name;
+  cmt_string name = dest_library_name;
+  cmt_string s;
+  Use& current_use = Use::current ();
+
+  Symbol::expand (name);
+  Symbol::expand (libname);
+
+  if (cmtinstallarea != "")
+    {
+      s = cmtinstallarea;
+      s += CmtSystem::file_separator ();
+      s += tag;
+      s += CmtSystem::file_separator ();
+      s += "lib";
+      s += CmtSystem::file_separator ();
+      s += name;
+      
+      // Now removing the reference file
+
+      cmt_string r = s;
+      r += ".cmtref";
+
+      if (CmtMessage::active (Info))
+	cerr << "   Removing reference file " << r << endl;
+      if (symunlinkcmd == "")
+	{
+	  if (!CmtSystem::remove_file (r) && CmtSystem::test_file(r))
+	    {
+	      CmtError::set (CmtError::file_access_error, r);
+	      return false;
+	    }
+	}
+      else
+	{
+	  cmt_string cmd (symunlinkcmd);
+	  cmd += " ";
+	  cmd += r;
+	  int status = CmtSystem::execute (cmd);
+	  if (status != 0)
+	    {
+	      //                  if (status != 2) CmtError::set (CmtError::execution_error, s);
+	      CmtError::set (CmtError::execution_error, cmd);
+	    }
+	}
+    }
+  else
+    {
+      if (current_use.style != none_style)
+	{
+	  s = "../$(";
+	  s += current_use.get_package_name ();
+	  s += "_tag)/";
+	}
+      else
+	{
+	  s = "./";
+	}
+      s += name;
+    }
+
+  Symbol::expand (s);
+
+  cmt_string source;
+  cmt_string dest;
+
+  CmtSystem::dirname (libname, source);
+  CmtSystem::dirname (s, dest);
+
+  if (same_dirs (source, dest))
+    {
+      cmt_string lname;
+      CmtSystem::basename (libname, lname);
+      if (lname == name)
+	return true;
+    }
+
+  //if (!Cmt::get_quiet ()) 
+  if (CmtMessage::active (Info))
+    cerr << "   Removing symlink " << s << " to " << libname << endl;
+
+  if (symunlinkcmd == "")
+    {
+      if (!CmtSystem::remove_file (s) && CmtSystem::test_file(s))
+	{
+	  CmtError::set (CmtError::file_access_error, "Cannot remove symbolic link to " + libname);
+	  return (false);
+	}
+    }
+  else
+    {
+      cmt_string cmd = symunlinkcmd;
+      cmd += " ";
+      cmd += s;
+      int status = CmtSystem::execute (cmd);
+      if (status != 0)
+	{
+	  CmtError::set (CmtError::execution_error, "Cannot remove symbolic link to " + libname);
+	  //CmtMessage::error ("Cannot create a symbolic link to " + libname);
+	  //	  cerr << "#CMT> Cannot create a symbolic link to " << libname << endl;
+	  return (false);
+	}
+    }
+  
+  return (true);
+}
+
+//----------------------------------------------------------
 /**
-   Centralize the construction of library links for this Use.
-*/
+ *  This function construct absolute library path
+ *  for libraries specified via <package>_libraries macros
+ *  to be used by build[remove]_library_links functions,
+ *  and class Generator build_library_links_infile function, in particular.
+ */
+void Use::absolute_library_path (const cmt_string& libname,
+				 const cmt_string& shlibsuffix, 
+				 CmtSystem::cmt_string_vector& paths) const
+{
+  if (CmtSystem::absolute_path (libname))
+    {
+      paths.push_back (libname);
+      return;
+    }
+
+  /**
+   *   Here we expect that only the base name of the library
+   *   is given : ie it should not contain the "lib" prefix, 
+   *   nor the suffix .so, nor any path prefix.
+   *   This of course should generally correspond to a constituent name.
+   */
+  cmt_string libpath;
+  if (style != none_style)
+    {
+      libpath = "${";
+      libpath += prefix;
+      libpath += "ROOT}/${";
+      libpath += get_package_name ();
+      libpath += "_tag}/";
+    }
+  else
+    {
+      libpath = "${";
+      libpath += prefix;
+      libpath += "ROOT}/";
+    }
+  libpath += "$(library_prefix)";
+  libpath += libname;
+  libpath += "$(library_suffix)";
+  libpath += ".";
+  libpath += shlibsuffix;
+  paths.push_back (libpath);
+
+#ifdef __APPLE__
+  if (style != none_style)
+    {
+      libpath = "${";
+      libpath += prefix;
+      libpath += "ROOT}/${";
+      libpath += get_package_name ();
+      libpath += "_tag}/";
+    }
+  else
+    {
+      libpath = "${";
+      libpath += prefix;
+      libpath += "ROOT}/";
+    }
+  libpath += libname;
+  libpath += ".bundle";
+  paths.push_back (libpath);
+#endif
+}
+
+//----------------------------------------------------------
+/**
+ *   Centralize the construction of library links for this Use.
+ */
 void Use::build_library_links (const cmt_string& cmtinstallarea, 
 			       const cmt_string& tag, 
@@ -3933,89 +4123,79 @@
       libname = library;
       Symbol::expand (libname);
-
-      bool is_absolute = false;
-
-      is_absolute = CmtSystem::absolute_path (libname);
-
-      if (is_absolute)
-	{
-	  /**
-	   *   We assume here that "library" contains a complete path.
-	   *   (including the complete syntax libxxx.so)
-	   */
-
-	  cmt_string suffix;
-	  CmtSystem::basename (library, name);
-	}
-      else
-	{
-	  /**
-	   *   Here we expect that only the base name of the library
-	   *   is given : ie it should not contain the "lib" prefix, 
-	   *   nor the suffix .so, nor any path prefix.
-	   *    This of course should generally correspond to a constituent name.
-	   */
-	  
-	  if (style != none_style)
-	    {
-	  libname = "${";
-	  libname += prefix;
-	  libname += "ROOT}/${";
-	  libname += get_package_name ();
-	  libname += "_tag}/";
-	    }
-	  else
-	    {
-	  libname = "${";
-	  libname += prefix;
-	  libname += "ROOT}/";
-	    }
-	  libname += "$(library_prefix)";
-	  libname += library;
-	  libname += "$(library_suffix)";
-	  libname += ".";
-	  libname += shlibsuffix;
-
-	  name = "$(library_prefix)";
-	  name += library;
-	  name += "$(library_suffix)";
-	  name += ".";
-	  name += shlibsuffix;
-	}
-
-      if (!install_library (libname, name, cmtinstallarea, tag, symlinkcmd))
-	{
-	  continue;
-	}
-
-#ifdef __APPLE__
-      if (!is_absolute)
-	{
-	  if (style != none_style)
-	    {
-	  libname = "${";
-	  libname += prefix;
-	  libname += "ROOT}/${";
-	  libname += get_package_name ();
-	  libname += "_tag}/";
-	    }
-	  else
-	    {
-	  libname = "${";
-	  libname += prefix;
-	  libname += "ROOT}/";
-	    }
-	  libname += library;
-	  libname += ".bundle";
-
-	  name = library;
-	  name += ".bundle";
-	  
-	  if (!install_library (libname, name, cmtinstallarea, tag, symlinkcmd))
-	    {
-	      continue;
-	    }
-	}
-#endif
+      if (0 == libname.size ()) continue;
+
+      CmtSystem::cmt_string_vector paths;
+      absolute_library_path (libname,
+			     shlibsuffix, 
+			     paths);
+
+      for (int k = 0; k < paths.size (); k++)
+	{
+	  CmtSystem::basename (paths[k], name);
+	  if (!install_library (paths[k], name, cmtinstallarea, tag, symlinkcmd))
+	    {
+	      CmtError::print ();
+	    }
+	}
+    }
+}
+//----------------------------------------------------------
+/**
+ *   Centralize the removal of library links for this Use.
+ */
+void Use::remove_library_links (const cmt_string& cmtinstallarea, 
+				const cmt_string& tag, 
+				const cmt_string& shlibsuffix, 
+				const cmt_string& symunlinkcmd) const
+{
+  if (!located ())
+    {
+      CmtMessage::warning ("package " + get_package_name ()
+			   + " " + version + " " + path
+			   + " not found");
+      return;
+    }
+
+  cmt_string s;
+
+  s = get_package_name ();
+  s += "_libraries";
+
+  Symbol* libraries_macro = Symbol::find (s);
+
+  if (libraries_macro == 0) return;
+
+  cmt_string libraries = libraries_macro->build_macro_value ();
+  Symbol::expand (libraries);
+  static CmtSystem::cmt_string_vector values;
+
+  CmtSystem::split (libraries, " \t", values);
+
+  for (int j = 0; j < values.size (); j++)
+    {
+      const cmt_string& library = values[j];
+
+      static cmt_string libname;
+      static cmt_string name;
+
+      // Is it a simple name or a complete path?
+
+      libname = library;
+      Symbol::expand (libname);
+      if (0 == libname.size ()) continue;
+
+      CmtSystem::cmt_string_vector paths;
+      absolute_library_path (libname,
+			     shlibsuffix, 
+			     paths);
+      
+      for (int k = 0; k < paths.size (); k++)
+	{
+	  CmtSystem::basename (paths[k], name);
+	  if (!uninstall_library (paths[k], name, cmtinstallarea, tag, symunlinkcmd))
+	    {
+	      CmtError::print ();
+	    }
+	}
     }
 }
Index: CMT/HEAD/source/cmt_use.h
===================================================================
--- CMT/HEAD/source/cmt_use.h	(revision 586)
+++ CMT/HEAD/source/cmt_use.h	(revision 588)
@@ -118,5 +118,9 @@
 			    const cmt_string& shlibsuffix, 
 			    const cmt_string& symlinkcmd) const;
-
+  void remove_library_links (const cmt_string& cmtinstallarea, 
+			     const cmt_string& tag, 
+			     const cmt_string& shlibsuffix, 
+			     const cmt_string& symunlinkcmd) const;
+  
   bool get_all_clients (const cmt_string& to_name);
 
@@ -152,4 +156,7 @@
   bool is_head_version (const cmt_string& version);
   void clear ();
+  void absolute_library_path (const cmt_string& libname,
+			      const cmt_string& shlibsuffix, 
+			      CmtSystem::cmt_string_vector& paths) const;
 // Public attributes
 public:
Index: CMT/HEAD/src/Makefile.core
===================================================================
--- CMT/HEAD/src/Makefile.core	(revision 586)
+++ CMT/HEAD/src/Makefile.core	(revision 588)
@@ -135,3 +135,3 @@
 # add to the list of valid suffixes
 # so that nonterminal match-anything rules will not be considered
-.SUFFIXES: .make .stamp .cxx
+.SUFFIXES: .make .in .stamp .cxx
Index: CMT/HEAD/src/Makefile.header
===================================================================
--- CMT/HEAD/src/Makefile.header	(revision 586)
+++ CMT/HEAD/src/Makefile.header	(revision 588)
@@ -19,81 +19,89 @@
 
 cmt_local_tagfile = $(bin)$(tag).make
+cmt_broadcast_tagfile = $(bin)$(tag)_broadcast.make
 
 cmt_constituents_makefile = $(bin)constituents.make
-
-cmt_local_setup = $(bin)setup$$$$.make
-#cmt_local_setup = $(bin)$(package)setup$$$$.make
-#cmt_final_setup = $(bin)${PACKAGE}setup.make
+cmt_broadcast_makefile = $(bin)broadcast.make
+
 cmt_final_setup = $(bin)setup.make
-#cmt_final_setup = $(bin)$(package)setup.make
-
-#
-#  Generic entry points for all targets
-#
-#ifndef QUICK
-#all :: check_config ;
-#else
-#all :: no_check_config ;
-#endif
-#all :: $(cmt_constituents_makefile)
-#	@$(MAKE) --no-print-directory -f $(cmt_constituents_makefile) $@
-default :: all ;
+
+cmt_check_configurationstamp = $(bin)cmt_check_configuration.stamp
+
+ifdef CMTBCAST
+QUICK = 1
+endif
+
+ifdef QUICK
+ifndef CMTBCAST
+
+ifneq ($(MAKECMDGOALS),binclean)
+ifneq ($(MAKECMDGOALS),help)
+cmt_included = 1
+-include $(cmt_local_tagfile)
+endif
+endif
+
+else
+
+ifneq ($(MAKECMDGOALS),help)
+cmt_included = 1
+-include $(cmt_broadcast_tagfile)
+endif
+
+endif
+endif
+
+all ::
+ifndef CMTBCAST
+ifndef cmt_included
+	@$(MAKE) $(cmt_constituents_makefile)
+endif
+	$(MAKE) --no-print-directory -f $(cmt_constituents_makefile) $@
+else
+ifndef cmt_included
+	@$(MAKE) $(cmt_broadcast_makefile)
+endif
+	@$(MAKE) --no-print-directory -f $(cmt_broadcast_makefile) CMTBCAST= $@
+endif
+
+.DEFAULT :
+ifndef CMTBCAST
+ifndef cmt_included
+	@$(MAKE) $(cmt_constituents_makefile)
+endif
+	@$(MAKE) --no-print-directory -f $(cmt_constituents_makefile) $@
+else
+ifndef cmt_included
+	@$(MAKE) $(cmt_broadcast_makefile)
+endif
+	@$(MAKE) --no-print-directory -f $(cmt_broadcast_makefile) CMTBCAST= $@
+endif
 
 check_config ::
-	@$(cmtexe) check configuration; retval=$$?; \
-	if test $${retval} -ne 0; then \
-	  test -z "$(cmtmsg)" || \
-	  echo "$(CMTMSGPREFIX)" "(Makefile.header) Configuration error(s). Please correct" >&2; \
-	fi; exit $${retval}
-
-#	@$(cmtexe) check configuration; retval=$$?; \
-#	if test $${retval} = 0; then \
-#	  $(MAKE) --no-print-directory target="all" common_target; \
-#	else \
-#	  test -z "$(cmtmsg)" || \
-#	  echo "$(CMTMSGPREFIX)" "(Makefile.header) Configuration error(s). Please correct" >&2; \
-#	fi
-
-#no_check_config ::
-#	@$(MAKE) --no-print-directory target="all" common_target
-
-binclean ::
-	if test ! "$(bin)" = "./"; then \
-	  if test -d $(bin) ; then \
-	    test -z "$(cmtmsg)" || \
-	    echo "$(CMTMSGPREFIX)" "(Makefile.header) Removing binary directory $(bin)"; \
-	    \rm -rf $(bin) ; \
-	  fi ; \
-	fi
-
-#clean uninstall :: check_config
-#	@$(MAKE) --no-print-directory -f $(cmt_constituents_makefile) $@
-#	@$(cmtexe) check configuration
-#	@$(MAKE) --no-print-directory target="$@" common_target
-
-.DEFAULT ::
-	@$(MAKE) $(cmt_constituents_makefile)
-	@$(MAKE) --no-print-directory -f $(cmt_constituents_makefile) $@
-
-#	@$(cmtexe) check configuration
-#	@$(MAKE) --no-print-directory target="$@" common_target
-#	@$(MAKE) --no-print-directory target="config $@" common_target
-
-#
-#  Capture all possible targets
-#
-#common_target : $(cmt_constituents_makefile)
-#	@$(MAKE) --no-print-directory -f $(cmt_constituents_makefile) $(target)
-
-#$(cmt_constituents_makefile) : $(cmt_local_tagfile)
+	+@$(cmtexe) check configuration; retval=$$?; \
+	  if test $${retval} -ne 0; then \
+	    test -z "$(cmtmsg)" || \
+	    echo "$(CMTMSGPREFIX)" "(Makefile.header) Configuration error(s). Please correct" >&2; \
+	  fi; exit $${retval}
+
+$(cmt_check_configurationstamp) : $(use_requirements)
+	+@$(cmtexe) check configuration; retval=$$?; \
+	  if test $${retval} -ne 0; then \
+	    test -z "$(cmtmsg)" || \
+	    echo "$(CMTMSGPREFIX)" "(Makefile.header) Configuration error(s). Please correct" >&2; \
+	  fi; exit $${retval}
+	+$(silent) if test ! -d $(@D) ; then $(mkdir) -p $(@D); fi && \touch $@
+#	echo "$(CMTMSGPREFIX)" "(Makefile.header) Configuration error(s). Please correct" >&2; exit 17
 
 ifndef QUICK
-$(cmt_constituents_makefile) : check_config
-else
-$(cmt_constituents_makefile) :
-endif
-	$(echo) "(Makefile.header) Rebuilding $@"; \
+$(cmt_constituents_makefile) ::
+#$(cmt_constituents_makefile) : check_config
+else
+$(cmt_local_tagfile) $(cmt_constituents_makefile) : $(use_requirements)
+#$(cmt_local_tagfile) $(cmt_constituents_makefile) : $(cmt_check_configurationstamp)
+endif
+	+$(echo) "(Makefile.header) Rebuilding $@"; \
 	  if test ! -d $(@D) ; then $(mkdir) -p $(@D); fi; \
-	  $(cmtexe) -tag=$(tags) build constituents_config -out=$@; \
+	  $(cmtexe) -tag=$(tags) build constituents_config -out=$(cmt_constituents_makefile); \
 	  retval=$$?; \
 	  if test $${retval} -ne 0; then \
@@ -105,20 +113,20 @@
 
 ifndef QUICK
-$(cmt_local_tagfile) ::
-else
-$(cmt_local_tagfile) :
-endif
-	$(echo) "(Makefile.header) Rebuilding $@"; \
-	  if test -f $@; then rm -f $@; fi; \
-	  if test ! -d $(@D); then $(mkdir) -p $(@D); fi; \
-	  $(cmtexe) -tag=$(tags) build tag_makefile >$@
-	$(echo) "(Makefile.header) Rebuilding $(cmt_final_setup)"; \
-	  test ! -f $(cmt_local_setup) || \rm -f $(cmt_local_setup); \
-	  trap '\rm -f $(cmt_local_setup)' 0 1 2 15; \
-	  $(cmtexe) -tag=$(tags) show setup >$(cmt_local_setup) && \
-	  if [ -f $(cmt_final_setup) ] && \
-	    \cmp -s $(cmt_final_setup) $(cmt_local_setup); then \
-	    \rm $(cmt_local_setup); else \
-	    \mv -f $(cmt_local_setup) $(cmt_final_setup); fi
+$(cmt_broadcast_makefile) ::
+#$(cmt_broadcast_makefile) : check_config
+else
+$(cmt_broadcast_tagfile) $(cmt_broadcast_makefile) : $(use_requirements)
+#$(cmt_broadcast_makefile) : $(cmt_check_configurationstamp)
+endif
+	+$(echo) "(Makefile.header) Rebuilding $@"; \
+	  if test ! -d $(@D) ; then $(mkdir) -p $(@D); fi; \
+	  $(cmtexe) -tag=$(tags) build broadcast_config -out=$(cmt_broadcast_makefile); \
+	  retval=$$?; \
+	  if test $${retval} -ne 0; then \
+	    test -z "$(cmtmsg)" || \
+	    echo "$(CMTMSGPREFIX)" "(Makefile.header) Cannot generate $@" >&2; \
+	    \rm -f $@; \
+	  fi; \
+	  exit $${retval}
 
 #
@@ -134,8 +142,18 @@
 everywhere :: $(everywhere)
 
+ifndef CMTBCAST
+binclean ::
+	if _bin=`cd $(bin) 2>/dev/null&&pwd -P`&&_cur=`pwd -P`&&[ -n "$${_bin}" ]&&[ "$${_cur#$${_bin}}" = "$${_cur}" ] ; then \
+	    test -z "$(cmtmsg)" || \
+	    echo "$(CMTMSGPREFIX)" "(Makefile.header) Removing binary directory $(bin)"; \
+	    \rm -rf $(bin) ; \
+	fi
+endif
+
 #
 #   Display all targets
 #
 help ::
+ifndef CMTBCAST
 	@echo '--------------------------------------------------------------------------'
 	@echo 'You may select one of the following make targets :'
@@ -160,8 +178,82 @@
 	@echo '              run all applications defined with the -check option'
 	@echo ' '
-
-
-# explicit rule not to remake
+	@echo 'To switch to BCAST mode, set CMTBCAST to non-empty string.'
+else
+	@echo 'Targets for BCAST mode:'
+	@echo
+	@echo 'help        : this help'
+ifndef BCAST_ONLY
+ifndef BCAST_GLOBAL
+	@echo 'all         : (re)build all used packages in current project (this is default target)'
+else
+	@echo 'all         : (re)build all used packages in all projects (this is default target)'
+endif
+else
+	@echo 'all         : (re)build current package (this is default target)'
+endif
+	@echo 'clean       : remove everything that can be rebuilt'
+	@echo 'binclean    : fast erase of binary directories (and installation area)'
+	@echo 'uninstall   : remove everything installed in the installation area'
+	@echo
+ifndef BCAST_GLOBAL
+	@uses=`$(cmtexe) -private show macros '_project$$|package$$' -tag=$(tags)| \
+	  awk -F = '{if ($$1 ~ /_project$$/) {uses[substr($$1,1,length($$1)-8)]=$$2}else if ($$1 == "package") {cur = $$2;gsub("'\''","",cur)}}END{for (u in uses){if (uses[u]==uses[cur]) print u}}'`; \
+	  for u in $${uses}; do \
+	    echo "$${u} : (re)build package $${u} ($(_groups))"; \
+	    echo "$${u}clean : remove everything that can be rebuilt in package $${u}"; \
+	    echo "$${u}binclean : fast erase of binary directory in package $${u}"; \
+	    echo "$${u}uninstall : remove everything installed in the installation area from package $${u}"; \
+	  done
+else
+	@uses=`$(cmtexe) -private show macros '_root$$' -tag=$(tags)| \
+	  awk -F = '{u=substr($$1,1,length($$1)-5);if (u != "CMT" && u != "CMTHOME" && u != "CMTUSERCONTEXT") print u}'`; \
+	  for u in $${uses}; do \
+	    echo "$${u} : (re)build package $${u} ($(_groups))"; \
+	    echo "$${u}clean : remove everything that can be rebuilt in package $${u}"; \
+	    echo "$${u}binclean : fast erase of binary directory in package $${u}"; \
+	    echo "$${u}uninstall : remove everything installed in the installation area from package $${u}"; \
+	  done
+endif
+	@echo
+ifndef BCAST_ONLY
+	@echo '   ... with dependencies packages (may be ignored by setting BCAST_ONLY).'
+else
+	@echo '   ... without dependencies packages (may be included by unsetting BCAST_ONLY).'
+endif
+	@echo
+ifndef BCAST_GLOBAL
+	@echo 'To (re)build packages in all projects, set BCAST_GLOBAL.'
+else
+	@echo 'To (re)build packages in current project, unset BCAST_GLOBAL.'
+endif
+ifndef NO_ALL_GROUPS
+	@echo 'To (re)build default group only, set NO_ALL_GROUPS.'
+ifndef CMTACTIONS
+	@echo 'To also (re)build cmt_actions group, set CMTACTIONS.'
+endif
+else
+	@echo 'To (re)build all groups, unset NO_ALL_GROUPS.'
+endif
+	@echo
+	@echo 'To switch to PACKAGE mode, unset CMTBCAST.'
+endif
+
+ifndef NO_ALL_GROUPS
+ifndef CMTACTIONS
+_groups = all groups except cmt_actions
+else
+_groups = all groups
+endif
+else
+_groups = default group
+endif
+
+# explicit rule to avoid implicit rule search
+# and not to remake
 ${CMTROOT}/src/Makefile.header : ;
+${CMTROOT}/src/Makefile.core : ;
+ifdef use_requirements
+$(use_requirements) : ;
+endif
 
 # for multiple command line goals,
Index: CMT/HEAD/src/setup.csh
===================================================================
--- CMT/HEAD/src/setup.csh	(revision 586)
+++ CMT/HEAD/src/setup.csh	(revision 588)
@@ -54,2 +54,12 @@
 
 alias jcmt '(java cmt_parser)'
+
+# Set MAKEFLAGS, if unset (similar to NPROC with Plan 9 mk utility)
+if ( $?MAKEFLAGS == 0 ) then
+  setenv MAKEFLAGS -j`getconf _NPROCESSORS_ONLN` || unsetenv MAKEFLAGS
+  if ( $?MAKEFLAGS == 1 ) then
+    setenv MAKEFLAGS "${MAKEFLAGS} QUICK=1"
+  else
+    setenv MAKEFLAGS "QUICK=1"
+  endif
+endif
Index: CMT/HEAD/src/setup.sh
===================================================================
--- CMT/HEAD/src/setup.sh	(revision 586)
+++ CMT/HEAD/src/setup.sh	(revision 588)
@@ -11,5 +11,5 @@
 fi
 
-if [ `expr $- : '.*i'` -ne 0 ]; then
+if [ -n "$-" ] && [ "${-#*i}" != "$-" ]; then
 if [ -n "${ZSH_NAME-}" ]; then
   . ${CMTROOT}/src/setup.zsh
@@ -47,2 +47,13 @@
 
 alias jcmt='(java cmt_parser)'; export jcmt
+
+# Set MAKEFLAGS, if unset (similar to NPROC with Plan 9 mk utility)
+if [ -z ${MAKEFLAGS+CMT} ]; then
+  MAKEFLAGS=-j`getconf _NPROCESSORS_ONLN 2>/dev/null` && export MAKEFLAGS || unset MAKEFLAGS
+  if [ -n "${MAKEFLAGS:-}" ]; then
+    MAKEFLAGS="${MAKEFLAGS} QUICK=1"
+  else
+    MAKEFLAGS="QUICK=1"
+  fi
+  export MAKEFLAGS
+fi
