#-- start of constituent ------

cmt_${CONSTITUENT}_${HASTARGETTAG} = 1

#--------------------------------------------------------

ifdef cmt_${CONSTITUENT}_has_target_tag

#cmt_local_tagfile_${CONSTITUENT} = $(${PACKAGE}_tag)_${CONSTITUENT}.make
cmt_local_tagfile_${CONSTITUENT} = $(bin)$(${PACKAGE}_tag)_${CONSTITUENT}.make
cmt_local_setup_${CONSTITUENT} = $(bin)setup_${CONSTITUENT}$$$$.make
cmt_final_setup_${CONSTITUENT} = $(bin)setup_${CONSTITUENT}.make
#cmt_final_setup_${CONSTITUENT} = $(bin)${PACKAGE}_${CONSTITUENT}setup.make
cmt_local_${CONSTITUENT}_makefile = $(bin)${CONSTITUENT}.make

${CONSTITUENT}_extratags = -tag_add=target_${CONSTITUENT}

#$(cmt_local_tagfile_${CONSTITUENT}) : $(cmt_lock_setup)
ifndef QUICK
$(cmt_local_tagfile_${CONSTITUENT}) ::
else
$(cmt_local_tagfile_${CONSTITUENT}) :
endif
	$(echo) "(constituents.make) Rebuilding $@"; \
	  if test -f $(cmt_local_tagfile_${CONSTITUENT}); then /bin/rm -f $(cmt_local_tagfile_${CONSTITUENT}); fi ; \
	  $(cmtexe) -tag=$(tags) $(${CONSTITUENT}_extratags) build tag_makefile >>$(cmt_local_tagfile_${CONSTITUENT})
	$(echo) "(constituents.make) Rebuilding $(cmt_final_setup_${CONSTITUENT})"; \
	  test ! -f $(cmt_local_setup_${CONSTITUENT}) || \rm -f $(cmt_local_setup_${CONSTITUENT}); \
	  trap '\rm -f $(cmt_local_setup_${CONSTITUENT})' 0 1 2 15; \
	  $(cmtexe) -tag=$(tags) $(${CONSTITUENT}_extratags) show setup >$(cmt_local_setup_${CONSTITUENT}) && \
	  if [ -f $(cmt_final_setup_${CONSTITUENT}) ] && \
	    \cmp -s $(cmt_final_setup_${CONSTITUENT}) $(cmt_local_setup_${CONSTITUENT}); then \
	    \rm $(cmt_local_setup_${CONSTITUENT}); else \
	    \mv -f $(cmt_local_setup_${CONSTITUENT}) $(cmt_final_setup_${CONSTITUENT}); fi

else

#cmt_local_tagfile_${CONSTITUENT} = $(${PACKAGE}_tag).make
cmt_local_tagfile_${CONSTITUENT} = $(bin)$(${PACKAGE}_tag).make
cmt_final_setup_${CONSTITUENT} = $(bin)setup.make
#cmt_final_setup_${CONSTITUENT} = $(bin)${PACKAGE}setup.make
cmt_local_${CONSTITUENT}_makefile = $(bin)${CONSTITUENT}.make

endif

ifdef STRUCTURED_OUTPUT
${CONSTITUENT}dirs :
	@if test ! -d $(bin)${CONSTITUENT}; then $(mkdir) -p $(bin)${CONSTITUENT}; fi
	$(echo) "STRUCTURED_OUTPUT="$(bin)${CONSTITUENT}
else
${CONSTITUENT}dirs : ;
endif

#ifndef QUICK
#ifdef STRUCTURED_OUTPUT
# ${CONSTITUENT}dirs ::
#	@if test ! -d $(bin)${CONSTITUENT}; then $(mkdir) -p $(bin)${CONSTITUENT}; fi
#	$(echo) "STRUCTURED_OUTPUT="$(bin)${CONSTITUENT}
#
#$(cmt_local_${CONSTITUENT}_makefile) :: $(${CONSTITUENT}_dependencies) $(cmt_local_tagfile_${CONSTITUENT}) build_library_links dirs ${CONSTITUENT}dirs
#else
#$(cmt_local_${CONSTITUENT}_makefile) :: $(${CONSTITUENT}_dependencies) $(cmt_local_tagfile_${CONSTITUENT}) build_library_links dirs
#endif
#else
#$(cmt_local_${CONSTITUENT}_makefile) :: $(cmt_local_tagfile_${CONSTITUENT})
#endif

makefiles : $(cmt_local_${CONSTITUENT}_makefile)

ifndef QUICK
$(cmt_local_${CONSTITUENT}_makefile) : $(${CONSTITUENT}_dependencies) build_library_links
#$(cmt_local_${CONSTITUENT}_makefile) : $(${CONSTITUENT}_dependencies) $(cmt_local_tagfile_${CONSTITUENT}) build_library_links
	$(echo) "(constituents.make) Building ${CONSTITUENT}.make"; \
	  $(cmtexe) -tag=$(tags) $(${CONSTITUENT}_extratags) build constituent_config -out=$(cmt_local_${CONSTITUENT}_makefile) ${CONSTITUENT}
else
$(cmt_local_${CONSTITUENT}_makefile) : $(${CONSTITUENT}_dependencies)
#$(cmt_local_${CONSTITUENT}_makefile) : $(cmt_local_tagfile_${CONSTITUENT})
	if [ ! -f $@ ]; then \
	  test -z "$(cmtmsg)" || \
	  echo "$(CMTMSGPREFIX)" "(constituents.make) Building ${CONSTITUENT}.make"; \
	  $(cmtexe) -tag=$(tags) $(${CONSTITUENT}_extratags) build constituent_config -out=$(cmt_local_${CONSTITUENT}_makefile) ${CONSTITUENT}; \
	  fi
endif

#	  $(cmtexe) -tag=$(tags) $(${CONSTITUENT}_extratags) build constituent_makefile -out=$(cmt_local_${CONSTITUENT}_makefile) ${CONSTITUENT}

${CONSTITUENT} :: $(${CONSTITUENT}_dependencies) $(cmt_local_${CONSTITUENT}_makefile) dirs ${CONSTITUENT}dirs
	$(echo) "(constituents.make) Starting ${CONSTITUENT}"
	@$(MAKE) -f $(cmt_local_${CONSTITUENT}_makefile) ${CONSTITUENT}
	$(echo) "(constituents.make) ${CONSTITUENT} done"

clean :: ${CONSTITUENT}clean

${CONSTITUENT}clean :: $(${CONSTITUENT}clean_dependencies) ##$(cmt_local_${CONSTITUENT}_makefile)
	$(echo) "(constituents.make) Starting ${CONSTITUENT}clean"
	@-if test -f $(cmt_local_${CONSTITUENT}_makefile); then \
	  $(MAKE) -f $(cmt_local_${CONSTITUENT}_makefile) ${CONSTITUENT}clean; \
	fi
	$(echo) "(constituents.make) ${CONSTITUENT}clean done"
#	@-$(MAKE) -f $(cmt_local_${CONSTITUENT}_makefile) ${CONSTITUENT}clean

##	  /bin/rm -f $(cmt_local_${CONSTITUENT}_makefile) $(bin)${CONSTITUENT}_dependencies.make

install :: ${CONSTITUENT}install

${CONSTITUENT}install :: $(${CONSTITUENT}_dependencies) $(cmt_local_${CONSTITUENT}_makefile)
	$(echo) "(constituents.make) Starting install ${CONSTITUENT}"
	@-$(MAKE) -f $(cmt_local_${CONSTITUENT}_makefile) install
	$(echo) "(constituents.make) install ${CONSTITUENT} done"

uninstall :: ${CONSTITUENT}uninstall

$(foreach d,$(${CONSTITUENT}_dependencies),$(eval $(d)uninstall_dependencies += ${CONSTITUENT}uninstall))

${CONSTITUENT}uninstall :: $(${CONSTITUENT}uninstall_dependencies) $(cmt_local_${CONSTITUENT}_makefile)
	$(echo) "(constituents.make) Starting uninstall ${CONSTITUENT}"
	@$(MAKE) -f $(cmt_local_${CONSTITUENT}_makefile) uninstall
	$(echo) "(constituents.make) uninstall ${CONSTITUENT} done"

ifndef PEDANTIC
.DEFAULT::
	$(echo) "(constituents.make) Starting $@ ${CONSTITUENT}"
	$(echo) Using default action for $@
	$(echo) "(constituents.make) $@ ${CONSTITUENT} done"
endif

#-- end of constituent ------
