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

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

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

!if defined (cmt_${CONSTITUENT}_has_target_tag)

cmt_local_tagfile_${CONSTITUENT} = $(bin)$(${PACKAGE}_tag)_${CONSTITUENT}.nmake
cmt_final_setup_${CONSTITUENT} = $(bin)setup_${CONSTITUENT}.nmake
cmt_local_${CONSTITUENT}_makefile = $(bin)${CONSTITUENT}.nmake

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

!else

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

!endif

!if defined (cmt_${CONSTITUENT}_has_target_tag)

!if "$(QUICK)" == "" || !exist ($(cmt_local_${CONSTITUENT}_makefile)) || !exist ($(cmt_local_tagfile_${CONSTITUENT})) || !exist ($(cmt_final_setup_${CONSTITUENT}))
$(cmt_local_${CONSTITUENT}_makefile) :: $(${CONSTITUENT}_dependencies) dirs
	$(echo) (constituents.nmake) Building ${CONSTITUENT}.nmake
	@set include=$(include)
	@set lib=$(lib)
	@$(cmtexe) -tag=$(tags) $(${CONSTITUENT}_extratags) build -nmake constituent_config -out=$@ ${CONSTITUENT}
!else
$(cmt_local_${CONSTITUENT}_makefile) : $(${CONSTITUENT}_dependencies) $(use_requirements)
	@set include=$(include)
	@set lib=$(lib)
	@if not "$?"=="$(${CONSTITUENT}_dependencies)" ((if not "$(cmtmsg)"=="" @echo "$(CMTMSGPREFIX)" "(constituents.nmake) Rebuilding ${CONSTITUENT}.nmake") & $(cmtexe) -tag=$(tags) $(${CONSTITUENT}_extratags) build -nmake constituent_config -out=$@ ${CONSTITUENT}) else (if not "$(cmtmsg)"=="" @echo "$(CMTMSGPREFIX)" "(constituents.nmake) ${CONSTITUENT}.nmake up-to-date")
!endif

!else

!if "$(QUICK)" == "" || !exist ($(cmt_local_${CONSTITUENT}_makefile)) || !exist ($(cmt_local_tagfile_${CONSTITUENT})) || !exist ($(cmt_final_setup_${CONSTITUENT}))
$(cmt_local_${CONSTITUENT}_makefile) :: $(${CONSTITUENT}_dependencies) dirs
	$(echo) (constituents.nmake) Building ${CONSTITUENT}.nmake
	@set include=$(include)
	@set lib=$(lib)
	@$(cmtexe) -f=$(bin)${CONSTITUENT}.in -tag=$(tags) $(${CONSTITUENT}_extratags) build -nmake constituent_makefile -without_cmt -out=$@ ${CONSTITUENT}
!else
$(cmt_local_${CONSTITUENT}_makefile) : $(${CONSTITUENT}_dependencies) $(use_requirements) $(bin)${CONSTITUENT}.in
	@set include=$(include)
	@set lib=$(lib)
	@if not "$?"=="$(${CONSTITUENT}_dependencies)" ((if not "$(cmtmsg)"=="" @echo "$(CMTMSGPREFIX)" "(constituents.nmake) Rebuilding ${CONSTITUENT}.nmake") & $(cmtexe) -f=$(bin)${CONSTITUENT}.in -tag=$(tags) $(${CONSTITUENT}_extratags) build -nmake constituent_makefile -without_cmt -out=$@ ${CONSTITUENT}) else (if not "$(cmtmsg)"=="" @echo "$(CMTMSGPREFIX)" "(constituents.nmake) ${CONSTITUENT}.nmake up-to-date")
!endif

!endif


!if defined (cmt_${CONSTITUENT}_has_dependencies)

${CONSTITUENT}dependencies : $(${CONSTITUENT}_dependencies) $(cmt_local_${CONSTITUENT}_makefile) dirs
	@set include=$(include)
	@set lib=$(lib)
	@$(MAKE) /nologo /f $(cmt_local_${CONSTITUENT}_makefile) /$(MAKEFLAGS) bin=$(bin) build_strategy=keep_makefiles dependencies tag=$(tag)

${CONSTITUENT} :: ${CONSTITUENT}dependencies
!else
${CONSTITUENT} :: $(${CONSTITUENT}_dependencies) $(cmt_local_${CONSTITUENT}_makefile) dirs
!endif
	$(echo) (constituents.nmake) Starting ${CONSTITUENT}
	@set include=$(include)
	@set lib=$(lib)
	@$(MAKE) /nologo /f $(cmt_local_${CONSTITUENT}_makefile) /$(MAKEFLAGS) bin=$(bin) build_strategy=keep_makefiles ${CONSTITUENT} tag=$(tag)
	$(echo) (constituents.nmake) ${CONSTITUENT} done

clean :: ${CONSTITUENT}clean ;

${CONSTITUENT}clean :: $(${CONSTITUENT}clean_dependencies) ##$(cmt_local_${CONSTITUENT}_makefile)
	$(echo) (constituents.nmake) Starting $@
	@set include=$(include)
	@set lib=$(lib)
	@-if exist $(cmt_local_${CONSTITUENT}_makefile) $(MAKE) /nologo /f $(cmt_local_${CONSTITUENT}_makefile) /$(MAKEFLAGS) bin=$(bin) build_strategy=keep_makefiles $@ tag=$(tag)
	$(echo) (constituents.nmake) $@ done
#	@$(MAKE) /nologo /f $(cmt_local_${CONSTITUENT}_makefile) /$(MAKEFLAGS) bin=$(bin) build_strategy=keep_makefiles ${CONSTITUENT}clean tag=$(tag)

install :: ${CONSTITUENT}install ;

${CONSTITUENT}install :: $(${CONSTITUENT}_dependencies) $(cmt_local_${CONSTITUENT}_makefile)
	$(echo) (constituents.nmake) Starting $@
	@set include=$(include)
	@set lib=$(lib)
	@$(MAKE) /nologo /f $(cmt_local_${CONSTITUENT}_makefile) /$(MAKEFLAGS) bin=$(bin) build_strategy=keep_makefiles install tag=$(tag)
	$(echo) (constituents.nmake) $@ done

uninstall :: ${CONSTITUENT}uninstall ;

${CONSTITUENT}uninstall :: $(${CONSTITUENT}uninstall_dependencies)
	$(echo) (constituents.nmake) Starting $@
	@set include=$(include)
	@set lib=$(lib)
	@-if exist $(cmt_local_${CONSTITUENT}_makefile) $(MAKE) /nologo /f $(cmt_local_${CONSTITUENT}_makefile) /$(MAKEFLAGS) bin=$(bin) build_strategy=keep_makefiles uninstall tag=$(tag)
#	@if not exist $(cmt_local_${CONSTITUENT}_makefile) $(cmtexe) -tag=$(tags) $(${CONSTITUENT}_extratags) build -nmake constituent_config -out=$(cmt_local_${CONSTITUENT}_makefile) ${CONSTITUENT}
#	@if not exist $(cmt_local_${CONSTITUENT}_makefile) $(cmtexe) -tag=$(tags) $(${CONSTITUENT}_extratags) build -nmake constituent_makefile -out=$(cmt_local_${CONSTITUENT}_makefile) ${CONSTITUENT}
#	@-$(MAKE) /nologo /f $(cmt_local_${CONSTITUENT}_makefile) /$(MAKEFLAGS) bin=$(bin) build_strategy=keep_makefiles uninstall tag=$(tag)
	$(echo) (constituents.nmake) $@ done

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